Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > API- adding ROLES to a GROUP View modes: 
User avatar
Member
Member
eagleag - 1/3/2011 1:18:30 AM
   
API- adding ROLES to a GROUP
HI I would like to add some custom functionality to->

file: CMSModules\Groups\Tools\Group_New.aspx.cs
function: void groupEditElem_OnSaved

I want to add a group ROLE that CAN MANAGE GROUP.

looked throw API (GroupRolePermissionInfoProvider.AddRoleToGroup) and other files like:Role_New.apsx.

What is the easiest way to do this?
After adding ROLE to group need to update SECURITY matrix and give edit/create/delete permissions only to new group admin role.

THANKS :)


User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/3/2011 5:23:07 AM
   
RE:API- adding ROLES to a GROUP
Hi,

you could add following method and call it from groupEditElem_OnSaved event in file CMSModules\Groups\Tools\Group_New.aspx.cs:


protected void addRoleToGroup()
{
RoleInfo role = new RoleInfo();

// Set RoleInfo properties except RoleID
role.RoleName = "CMSDeskAdmin";
role.DisplayName = "CMSDeskAdmin";
role.Description = "some description...";
role.SiteID = CMS.CMSHelper.CMSContext.CurrentSite.SiteID;
role.RoleGroupID = this.groupEditElem.GroupID;
role.RoleIsGroupAdministrator = true;

// 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
role = CMS.SiteProvider.RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMS.CMSHelper.CMSContext.CurrentSiteName);

//checks if role is not null and if it is not related to another group
if ((role != null) && (role.RoleGroupID ==0))
{
// Make some changes
role.RoleGroupID = this.groupEditElem.GroupID;
role.RoleIsGroupAdministrator = true;
// Update the role
CMS.SiteProvider.RoleInfoProvider.SetRoleInfo(role);
}
}
}


This way role is added to appropriate group after the group is created.

Best regards,
Ivana Tomanickova