0
votes

I am trying to get SharePoint User group permissions (Ex: Read, Contribute) based on the group name using SharePoint Rest API. My goal is to get the permission level of the group and disable features on our custom app based on the permission levels. I have tried the below url to get the group properties but couldn't get the permission level of the group. Could anyone please guide me on how to get the User group permissions.

Options Tried:

URL = http://Servename/Site/api/web/SiteGroups/getByName('group name')

2

2 Answers

0
votes

You won't be able to get this from the SiteGroup object alone. Your rest-call only retrieves group information (title, id, description and other metadata). To retrieve permission levels you will need to do a couple of more calls. See https://msdn.microsoft.com/en-us/library/office/dn531432.aspx to read more about RoleAssignment and RoleDefinition

0
votes

The function below returns Group Permission Level title and rest of the information:

function init() {       
    clientContext = new SP.ClientContext.get_current();
    oWeb = clientContext.get_web();
    currentUser = oWeb.get_currentUser();
    allGroups = currentUser.get_groups();
    clientContext.load(allGroups);

    clientContext.executeQueryAsync(OnSuccess, OnFailure);
    function OnSuccess() {
        var grpsEnumerator = allGroups.getEnumerator();

        while (grpsEnumerator.moveNext()) {         
        var group = grpsEnumerator.get_current();
        var grpTitle = group.get_title();
        var grpid = group.get_id();
        console.log('Group Id :' + grpid);
        console.log('Group Title :'+ grpTitle);

        roleBindings = oWeb.get_roleAssignments().getByPrincipalId(grpid).get_roleDefinitionBindings();
        clientContext.load(roleBindings);

            clientContext.executeQueryAsync(function () {
                var iterator = roleBindings.getEnumerator();
                while (iterator.moveNext()) {
                    current = iterator.get_current();
                    console.log('Show Role Defination Title : '+ current.get_name());

                    }
            });
        }
    }

    function OnFailure(){
    console.log('Process Failed');
    }
}