Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Webparts: How to restrict the webparts for a specific role? View modes: 
User avatar
Member
Member
guillaume.marquilly-tv5monde - 4/25/2012 10:30:26 PM
   
Webparts: How to restrict the webparts for a specific role?

Hello,

I want to restrict the numbers of webpart according to a specific role.

Administrators will be allowed to add all webparts but a content manager will only see a selection of webparts in the add webpart menu

Thank you!

Best regards,

Guillaume

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/26/2012 2:40:40 AM
   
RE:Webparts: How to restrict the webparts for a specific role?
Hello,

Regrettably this kind of functionality is not implemented in Kentico CMS, so it would take a lot of customization from your side. I can offer you a compromise between a bit of customization and user's experience:

You can create a new web part category and place (or copy/clone) there web parts, which can be used only by your specific role, so only web parts from this category will be visible, when someone from that role will try to add a new one and you can specify it in following files (please edit them carefully and make a backup first):

\CMSModules\PortalEngine\Controls\WebParts\WebPartFlatSelector.ascx.cs, line 86:
if (categoryId > 0)
{
if (CMSContext.CurrentUser.IsInRole("CMSEditor", "CorporateSite")) {
mSelectedCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(399); // where 399 is CategoryID from CMS_WebPartCategory
}
else {

mSelectedCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(categoryId);
}
}

\CMSModules\PortalEngine\Controls\WebParts\WebPartTree.ascx.cs, line 304:
if (CMSContext.CurrentUser.IsInRole("CMSEditor", "CorporateSite"))
{
// Hide all web parts except one category
where = SqlHelperClass.AddWhereCondition(where, "ParentID = 399");
}

\CMSModules\PortalEngine\Controls\WebParts\WebPartTree.ascx.cs, line 345:
// Add last recently used
if (ShowRecentlyUsed && !CMSContext.CurrentUser.IsInRole("CMSEditor", "CorporateSite"))
{
treeElem.AddDefaultItem(GetString("webparts.recentlyused"), "recentlyused", ResolveUrl(GetImageUrl("Objects/CMS_WebPartCategory/recentlyused.png")));
}


Where CMSEditor is a role name of your specific role and CorporateSite is a site name.

Best regards,
Jan Hermann

User avatar
Member
Member
guillaume.marquilly-tv5monde - 4/26/2012 5:27:52 AM
   
RE:Webparts: How to restrict the webparts for a specific role?

Good idea with the category filter.

I will try that !

Thank you

User avatar
Member
Member
guillaume.marquilly-tv5monde - 4/29/2012 10:35:40 PM
   
RE:Webparts: How to restrict the webparts for a specific role?
So i did some tests and everything work like a charm.

I suppose that its the same workaround for the Widgets?

Best regards,

Guillaume

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/30/2012 1:56:24 AM
   
RE:Webparts: How to restrict the webparts for a specific role?
Hello,

Actually no, there is a UI interface for widgets and you can set it in Site Manager -> Developmanet -> Widgets -> <a widget> -> Security and here you can choose Allowed for -> Authorized roles and select them in the table below.

Best regards,
Jan Hermann