Apply Permissions to Custom UI Links / Actions in SharePoint Menus and Settings Pages - SharePoint Development & Administration + InfoPath

Monday, October 24, 2011

Apply Permissions to Custom UI Links / Actions in SharePoint Menus and Settings Pages

This post explains how to incorporate permissions into custom links and actions added to the UI on menus, toolbars and default layout pages such as the Site Settings page in SharePoint 2010.  



 
Examples included in the post are:
  • Restricting custom links on list settings pages to only site collection administrators
  • Adding custom actions to the Document Library dropdown menu (ECB - Edit Control Block) that are displayed only to users with edit permissions on the document.
  • Displaying a link on the Site Actions menu only to users with access to manage  permissions for the current site.
  • Displaying a custom link on the List Actions menu for users with access to manage the list.
  • Display a link on the Site Settings page of a site to users with access to add and customise pages on the site, as well as apply themes and stylesheets to the site (Site Designers).


The attributes used to control custom links are included in the CustomAction element when configuring the link or action.  The RequireSiteAdministrator attribute accepts a boolean value that specifies if a user needs to be a Site Collection Administrator to see the link.  The Rights attribute accepts one or more base permissions in a comma separated list, which a user must have for the link to be displayed.  If multiple permissions are specified in the Role attribute, the user must have all of the permissions listed to see the link.


Customising the User Interface by adding links and actions based on user permissions can enhance usability of the site for some, but without cluttering or adding links to irrelevant resources for other users.  For example, displaying links to specific help content or branding guidelines to site designers may help maintain consistency and elements/themes required to maintain a acceptable look and feel when modifying themes and styles used across sites in a SharePoint environment.


For help with creating a feature that includes the customised links and actions for the User Interface in SharePoint, please see my post: Add Custom Links to the SharePoint 2010 UI as a Feature with or without using Visual Studio.


Examples:
Restricting custom links on list settings pages to only Site Collection Administrators.  
This is done using the RequireSiteAdministrator attribute, which should be set to TRUE.  If you want to display a link to only Administrators of the current web, you should use the “Rights” attribute with the “ManageWeb” permission.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
 Id="Microsoft.SharePoint.SiteSettings.OnlineHelp"
 GroupId="SiteAdministration"
 Location="Microsoft.SharePoint.SiteSettings"
 Sequence="1000"
 Title="Online Help with SharePoint 2010 (Site Admin)"
 RequireSiteAdministrator="TRUE"
 >
    <UrlAction Url="http://www.master-sharepoint.com/"/>
 </CustomAction>
</Elements>

This will add a new link to the “Site Administration” group on the site settings page.




Adding custom actions to the Document Library dropdown menu (ECB - Edit Control Block) that are displayed only to users with edit permissions on the document.
This is achieved using the “Rights” attribute with “EditListItems” as the value (SPBasePermissions.EditListItems).  The RegistrationType is set to “List”, and the RegistrationId set to “101” which corresponds to a Document Library in SharePoint.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
 Id="EditControlBlock.Library.OnlineHelp"
 RegistrationType="List"
 RegistrationId="101"
 Location="EditControlBlock"
 Sequence="1000"
 Title="Online Help with SharePoint 2010"
 Rights="EditListItems"
 >
    <UrlAction Url="http://www.master-sharepoint.com/"/>
 </CustomAction>
</Elements>

This will add a new link to the List Item dropdown menu (ECB) for files in Document Libraries.







Displaying a link on the Site Actions menu only to users with access to manage  permissions for the current site.
Adding a link visible only to users who can manage permission is done using the “Rights” attribute with “ManagePermisisons” as the value (SPBasePermissions.ManagePermissions).

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
 Id="Microsoft.SharePoint.StandardMenu.SiteActions.OnlineHelp"
 GroupId="SiteActions"
 Location="Microsoft.SharePoint.StandardMenu"
 Sequence="1000"
 Title="Online Help with SharePoint 2010"
 Rights="ManagePermissions"
 >
    <UrlAction Url="http://www.master-sharepoint.com/"/>
 </CustomAction>
</Elements>

This will add a new link to the bottom of the “Site Actions” menu for users who can manage permission on the site.





Displaying a custom link on the List Actions menu for users with access to manage the list (“Links” list).
This is achieved by setting the “Rights” attribute to “ManageLists”, the RegistrationType attribute to “List” and “RegistrationId” to “103” to specify the “Links” list type.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
 Id="Microsoft.SharePoint.StandardMenu.ActionsMenu.OnlineHelp"
 GroupId="ActionsMenu"
 RegistrationType="List"
 RegistrationId="103"
 Location="Microsoft.SharePoint.StandardMenu"
 Sequence="1000"
 Title="List Actions: Online Help with SharePoint 2010"
 Rights="ManageLists"
 >
    <UrlAction Url="http://www.master-sharepoint.com/"/>
 </CustomAction>
</Elements>

This will add a new link to a “Custom Actions” tab for a “Links” list.



Display a link on the Site Settings page of a site to users with access to add and customise pages on the site, as well as apply themes and stylesheets to the site (Site Designers).
This is achieved by including multiple comma separated SPBasePermisisons for the “Rights” attribute, where the user must have each of the permissions listed to be able to see the link.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
 Id="Microsoft.SharePoint.SiteSettings.OnlineHelp2"
 GroupId="Customization"
 Location="Microsoft.SharePoint.SiteSettings"
 Sequence="1001"
 Title="Online Help with SharePoint 2010 (Site Designer)"
 Rights="AddAndCustomizePages, ApplyThemeAndBorder, ApplyStyleSheets"
 >
    <UrlAction Url="http://www.master-sharepoint.com/"/>
 </CustomAction>
</Elements>

This will add a link to the Site Settings page under the “Look and Feel” group.



Additional Resources:







      Share this article:
      Stumble This Delicious
      Delicious
      submit to reddit
      Facebook
      MySpace
      MySpace

      No comments:

      Post a Comment