Pages

April 7, 2014

Quick & Useful Site Permissions Report

Objective:
In SharePoint 2010/2013, when Site Admin wants to view all site contents of a particular site, then he/she would see all site contents (securable objects) with permission details, to provide quick and easy permission reporting.

Here is how it looks in SharePoint 2010:


When clicking the 'unique lists' link:


And in SharePoint 2013:


Similar Work:
I found a similar idea here. Its nice but it only shows a true/false value for permissions fields, and it missed the '!' (not) sign and will display opposite permissions results! So I decided to build another much more detailed version.


How To:
By adding custom code to the OTB View All Items (_layouts/viewlsts.aspx) page:
- Added a permissions field to show type of site perms in different colors
- The field also displays info about unique items/lists/webs (if available) inside each item
- Unique items and lists are clickable to show the contents in popup window


Steps:
1. From layouts folder, backup the original Viewlsts.aspx page, then copy and rename it for example: ViewlstsEx.aspx

2. Add couple namespace references to the page:
<%@ Import Namespace="System.Collections.ObjectModel" %>
<%@ Import Namespace="System.Collections.Generic" %>


3. Add new column in SharePoint:UIVersionedContent UIVersion="4" section
<th scope="col" class="ms-vh2-nofilter" style="white-space:nowrap; width:25%;"><SharePoint:EncodedLiteral runat="server" text="Permissions" EncodeMethod='HtmlEncode'/>
</th>


4. Add column content in the list's section (table cells after code if (!bShowSites)):
<td class="ms-vb2" width="25%" >
<%
string ListPermOutput = "";
if (!spList.HasUniqueRoleAssignments) 
{
ListPermOutput = "<span style='color: green'>Inherited</span>";
}
else 
{
ListPermOutput = "<span style='color: red'>Unique</span>";
}
  if (spList.GetItemsWithUniquePermissions().Count > 0)
{
string str1 = spList.ParentWeb.Url + "/_layouts/uniqperm.aspx?obj=" + spList.ID.ToString("B").ToUpper() + ",List&List=" + spList.ID.ToString("B").ToUpper();
string str2 = SPHttpUtility.EcmaScriptStringLiteralEncode(SPHttpUtility.UrlPathEncode(str1, false));
ListPermOutput += " with " + "<a onclick='" + "javascript:ShowPopupDialog(\"" + str2 + "\");' href='javascript:'>unique items</a>";
}
SPHttpUtility.NoEncode(ListPermOutput, Response.Output);
%>
</td>


5. Add column content in the web's section (table cells after code foreach (SPWeb webToDisplay in webs)):
<td class="ms-vb2" width="25%" >
<%
StringBuilder WebPermOutput = new StringBuilder();
if (!webToDisplay.HasUniqueRoleAssignments) 
{
WebPermOutput.Append("<span style='color: green'>Inherited</span>");
}
else 
{
WebPermOutput.Append("<span style='color: red'>Unique</span>");
}

Collection<SPWebListInfo> UniqueObjects = webToDisplay.GetWebsAndListsWithUniquePermissions();
if (UniqueObjects.Count > 0)
{
List<string> UniqueSubWebs = new List<string>();
int UniqueSubWebsCount = 0;
int UniqueSubListsCount = 0;
foreach (SPWebListInfo item in UniqueObjects)
{
if (item.Type == Microsoft.SharePoint.SPObjectType.Web && item.HasUniqueRoleAssignments)
{
UniqueSubWebs.Add(item.WebId.ToString());
UniqueSubWebsCount++;
}
else if (item.Type == Microsoft.SharePoint.SPObjectType.List  && item.HasUniqueRoleAssignments)
{
UniqueSubListsCount++;
}
}

UniqueSubWebsCount--;
string SubWebsResult = "";
if (UniqueSubWebsCount > 0)
{
 SubWebsResult = " unique webs" ;
}

string SubListsResult = "";
if (UniqueSubListsCount > 0)
{
string str1 = webToDisplay.Url + "/_layouts/uniqperm.aspx";
string str2 = SPHttpUtility.EcmaScriptStringLiteralEncode(SPHttpUtility.UrlPathEncode(str1, false));
SubListsResult += "<a onclick='" + "javascript:ShowPopupDialog(\"" + str2 + "\");' href='javascript:'>unique items</a>";
}

if (SubListsResult != "" && SubWebsResult == "")
{
WebPermOutput.Append(" with "); WebPermOutput.Append(SubListsResult);
}

else if (SubListsResult == "" && SubWebsResult != "")
{
WebPermOutput.Append(" with "); WebPermOutput.Append(SubWebsResult);
}

else if (SubListsResult != "" && SubWebsResult != "")
{
WebPermOutput.Append(" with "); WebPermOutput.Append(SubListsResult);
WebPermOutput.Append(" and "); WebPermOutput.Append(SubWebsResult);
}
}

SPHttpUtility.NoEncode(WebPermOutput, Response.Output);
%>
</td>


The page is tested for SharePoint 2010, and SharePoint 2013.
Click here to download an example page viewlstsEx.aspx.

Have a nice SharePoint Administration!

Ibraheem


No comments:

Post a Comment