Managing roles

Creating a new role

 

[C#]

 

 

// Create new RoleInfo

RoleInfo role = new RoleInfo();

 

// Set RoleInfo properties except RoleID

role.RoleName = "DocumentEditor";

role.DisplayName = "Document editor";

role.Description = "some description...";

role.SiteID = CMS.CMSHelper.CMSContext.CurrentSite.SiteID;

 

// check if the role name is unique in the given site

if (!CMS.SiteProvider.RoleInfoProvider.RoleExists(role.RoleName, CMS.CMSHelper.CMSContext.CurrentSite.SiteName))

{

   // Insert new RoleInfo for current site

   CMS.SiteProvider.RoleInfoProvider.SetRoleInfo(role);

}

else

{

   // Role with the same name already exists in specified site

}

 

 

 

Selecting and updating a role

 

[C#]

 

 

// Get role of specified name from current site

RoleInfo role = CMS.SiteProvider.RoleInfoProvider.GetRoleInfo("ArticleEditor", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);

 

if (role != null)

{

   // Make some changes

   role.Description = "Changed description.";

   // Update the role

   CMS.SiteProvider.RoleInfoProvider.SetRoleInfo(role);

}

 

 

 

Deleting a role

 

[C#]

 

 

// Delete the role

CMS.SiteProvider.RoleInfoProvider.DeleteRole("ArticleEditor", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);