SharePoint - converting permission mask into role
I have a problem retrieving permissions on a list or site. I'm using SharePoint's Permission Web Service and the GetPermissionCollection method. This method return something like this:
<Permission MemberID="4" Mask="1067654015" MemberIsUser="False" MemberGlobal="True" GroupName="Collaboration demo Owners" />
I'd like to be able to convert the permission mask into the role(s) it belongs to. (just like if you view the Permissions through the web site).
I find out that using the UserGroup Webservice , I can retrieve the list of Roles and their base permissions. GetRolesAndPermissionsForSite method from this service returns somethink like this:
<Role ID="1073741829" Name="Full Control" Description="Has full control." Hidden="False" Type="Administrator" BasePermissions="9223372036854775807"....
Is there any way to convert this BasePermi开发者_StackOverflow中文版ssions to Mask in order to compare them? Or Is any simpler way to convert the permission mask into the role(permission level) it belongs to?
I made this javascript sample thanks to @zanlok answer
I used JQuery, SPServices js (http://spservices.codeplex.com/) and this link for the masks codes http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx I Hope this helps you, I did this because I was needing it also, however it may also help others.
You need to replace the divid with the value of the control you want to place the html, and the LIST NAME HERE with the name of the list.
The script will spit everyone that has access to a list, and say if they can read, add, change and delete things. Hopes this helps you.
$('#divid').html('Working...').SPServices({
operation: "GetPermissionCollection",
objectName: 'LIST NAME HERE',
objectType: "List",
completefunc: function (xData, Status) {
var out = "<ul>";
$(xData.responseXML).find("Permission").each(function () {
if ($(this).attr("MemberIsUser") === "True") {
out += "<li>User: " + $(this).attr("UserLogin") + "</li>";
} else {
out += "<li>Group: " + $(this).attr("GroupName") + "</li>";
}
var readmask = 0x0000000000000001;
var addmask = 0x0000000000000002;
var editmask = 0x0000000000000004;
var deletemask = 0x0000000000000008;
out += "<li>Mask: " + $(this).attr("Mask") + "</li>";
var canread = readmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canadd = addmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canedit = editmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var candelete = deletemask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
out += "<li>Can Read: " + canread + "</li>";
out += "<li>Can Add: " + canadd + "</li>";
out += "<li>Can Edit: " + canedit + "</li>";
out += "<li>Can Delete: " + candelete + "</li>";
});
out += "</ul>";
$('#divid').html(out);
}
});
精彩评论