简体   繁体   中英

Get SharePoint group permissions level name based on group name Using SharePoint Rest API

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')

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

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');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM