2

I have a list where one group of users is not allowed to delete items but they have view and edit permissions. All items in the list contain an attachment. However, users are not allowed to delete the attachments, I don't know if this is something that can be controlled within sharepoint so what I've done was write some Javascript to hide the div containing the delete attachment link:

function hideAttachmentDelete (){   
    $('td a').each(function(){
    var $this = $(this);
    if($this.text() == 'Delete'){
        $this.parent().html(' ');
    }
    });
}

However, I can't have this code run for FullControl Users. If they need to delete the attachment they should be able to. I started looking around for something that would allow me to get the current users permission level and run functions based on that. I can across this. Problem is that I don't understand it or what's going on and the documentation for this method simply just links to the example. This is the example:

<script type="text/javascript">
$(document).ready(function() {

   $().SPServices({
     operation: "GetRolesAndPermissionsForCurrentUser",
     async: false,
     completefunc: function(xData, Status) {
//        alert(xData.responseXML.xml);
        var userPerm = $(xData.responseXML).find("[nodeName=Permissions]").attr("Value");
//        alert("userPerm = " + userPerm);
        var nonAdminP = (33554432 & userPerm) == 33554432;
//        alert("nonAdminP == 33554432: " + nonAdminP);
        var adminP = userPerm == 9223372036854775807;
//        alert(adminP);
        var hideEdit = !(nonAdminP | adminP);
//        alert("hideEdit = " + hideEdit);


        if (hideEdit) {
           //alert("Hide");
           $("a[title='Edit Item']").parent().parent().parent().hide();
           $("td.ms-separator:nth-child(2)").hide();
        }
     }
   });

});
</script>

Can someone explain what's happening here or how I can get the current users permission and use that in an if statement to run or not run my hideAttachmentDelete() ?

1

The combination of various [SPBasePermissions][1] creates a permission mask. The above code uses a combination of these integer values. Here is the list of the permissions and mask values. Coming to your main requirement of finding the user with Full Control permissions, then you can do it using client object model also, if you are using SharePoint 2010. The main permission to check is FullMask permisson. If user has it, then the user has Full Control. This can be done using follwoing code:

   ClientContext context = new ClientContext("http://demo2010a:90")
   context.Load(context.Web);
   context.ExecuteQuery();
   BasePermissions permissionMask;
   ClientResult<bool> hasPermissions;
   permissionMask = new BasePermissions();
   permissionMask.Set(PermissionKind.FullMask);
   hasPermissions = context.Web.DoesUserHavePermissions(permissionMask);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.