Wednesday, April 6, 2011

Hide / Remove Web Parts in SharePoint 2010 based on security permissions !!

I came across a requirement where a client was looking to hide web parts for use in SharePoint. Before reading any further I’ve only carried out some light testing on this to see if its suitable but seems a viable solution and happy to get feedback on this.
The ideal solution would be to have a similar user interface to that that hides site templates and page layouts however this isn't available for web parts.
So the solution is really simple, for those web parts you don't want to display you can do one of two things:
1. Delete the web part from the gallery
2.Sever security permissions for that web part for those you don't want to use the web part.
I prefer the option 2 as this allows to easily reinstate the web part should things change in the future.
So exploring option 2 navigate to site settings at the root of the site collection and select web parts from galleries.
image
Click edit next to the web part you wish to hide.
Web parts gallery – sever inheritance add users who you may want to add these web parts.
image
As shown above click ‘manage permissions’. From here as you would with any item in SharePoint edit the permissions to allow only those who you wish to use this web part.
image
Simply stop inheriting from the parent and remove these users who you don't wish to have access. For the purposes of my quick test I removed all users so you will have to do some more testing as to allowing specific users.
For a quick test I removed the advancedsearchbox web part and logged in as standard site admin (not site collection admin) and the web part was removed from the list available as shown below when editing a page.
image
To add the web part back into the list simply reapply inheritance to the specific web part.
image
Your web part should then reappear in the list below.
image
Please note no IISRESET is required to do this.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi I am having a sharepoint home page, added with all the visual web parts. For a single visual webpart(in that page)I used "stop inheriting permissions" and then gave necessary groups permissions. But When I logged in as a user who do not have any permission i still shows me the webpart. Any thoughts?

    Thanks

    ReplyDelete