Friday 19 June 2015

Prevent users from accessing All Items page of SharePoint 2010

In our SharePoint portal we show users only Nintex Forms (can be accessed by links in emails sent by Workflows) and few web part pages restricting access to default SharePoint pages like AllItems.aspx.

To achieve this 
1. Upload 
             jquery-1.8.3.min.js   and
             jquery.SPServices-0.7.2.min.js

to Site Assets library

2. Edit AllItems.aspx page (or any page you want to restrict access to normal users) and add below script. (Even if the user try to access the page with link, they will be redirected to home page).

<script type="text/javascript" src="/SiteAssets/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.SPServices-0.7.2.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {$().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='SiteAdmins']").length != 1) {
                                location.href = $().SPServices.SPGetCurrentSite();
                                 }
                      }
       });
});
</script>

After adding above script, only members of SiteAdmins can access that page, all other user will be redirected to home page.

No comments: