Web part restriction according to roles

   —   

This article gives you instructions on how to add functionality to restrict web parts to be listed for your editors.

You can specify what web part to offer to your editors according to roles they belong to. All you need to do is apply hotfix 7.0.45 or later and follow the steps below:

1)  Download this package (or this one for v8, v10, v11, v12), import it (please don’t forget to check the Import files property in third step)


2)    v7 - Edit the \CMSModules\PortalEngine\Controls\WebParts\WebPartSelector.ascx.cs file and add following code to the line 178 (hotfixing or upgrading may overwrite this):

where = SqlHelperClass.AddWhereCondition(flatElem.UniFlatSelector.WhereCondition, WebPartPermissionMethods.GetRestrictedWebParts());

v8+ - Edit the \CMSModules\PortalEngine\Controls\WebParts\WebPartSelector.ascx.cs file and add following code to the line 211 (hotfixing or upgrading may overwrite this):
where = SqlHelper.AddWhereCondition(flatElem.UniFlatSelector.WhereCondition, WebPartPermissionMethods.GetRestrictedWebParts(false));

3)    v7 - Edit the \CMSModules\Content\Controls\WebPartToolbar.ascx.cs file and add following code to the line 517 (hotfixing or upgrading may overwrite this):
repItems.WhereCondition = SqlHelperClass.AddWhereCondition(repItems.WhereCondition, WebPartPermissionMethods.GetRestrictedWebParts());

v8+ - Edit the \CMSModules\Content\Controls\WebPartToolbar.ascx.cs file and add following code to the line 486 (hotfixing or upgrading may overwrite this):
repItems.WhereCondition = SqlHelper.AddWhereCondition(repItems.WhereCondition, WebPartPermissionMethods.GetRestrictedWebParts(true));

4)    v7 - Add a new UI element to the Site Manager -> Development -> Modules -> Site Manager -> User interface -> Site Manager -> Administration section with following properties:

  • Display name: Web part permission
  • Caption: Web part permission
  • Target URL: ~/CMSModules/WebPartPermission/Default.aspx



v8+ - New Web part permissions UI element is present under the Development section

Now you can restrict any web part for any role in the Site Manager -> Administration -> Web part permission section.

-jh-

 


Applies to: Kentico CMS 7.0.45 and above.

 

Share this article on   LinkedIn