locked
Breaking the Security Inheritance of a Item and Permissions of a User RRS feed

  • Question

  • Hello,

    Could you please help me with following:

    InfoPath 2010 forms, where need to change permission: from Contribute to Read access for "Members" group, if the field "Status" has value "Approved" or "Rejected".

    I found on MSDN following article:

    https://msdn.microsoft.com/en-us/library/office/hh185013(v=office.14).aspx

    Trying to run it on SharePoint 2010, nothing happens (The only I changed clientContext to var clientContext = SP.ClientContext.get_current();).

    Or can be this done, by SP Services js library?


    Wednesday, July 1, 2015 11:57 AM

Answers

  • Hi,

    According to your description, my understanding is that you want to break and reset permission for a user on a list item.

    As you are using SharePoint 2010 JSOM library, so  the code line method will not be available in SharePoint 2010:

    this.oListItem = oList.get_items().getById(itemId);
    
    this.oUser = clientContext.get_web().get_siteUsers().getByLoginName('DOMAIN\\alias');
    
    

    In SharePoint 2010, we need to write as below:

    this.oListItem = oList.getItemById(itemId);
    this.oUser = clientContext.get_web().ensureUser('SharePoint\\system');

    For resetting  item permission using SPService, per my knowledge, web service has limitation to get item level permission, so this method is not available.

    Here is a detailed article for your reference:

    Limitations of SharePoint Web Services

    Here is a similiar thread for your reference:

    SP ECMA/JS get_siteUsers() not working? trying to get user with getByLoginName()

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, July 2, 2015 6:15 AM

All replies

  • Hi,

    According to your description, my understanding is that you want to break and reset permission for a user on a list item.

    As you are using SharePoint 2010 JSOM library, so  the code line method will not be available in SharePoint 2010:

    this.oListItem = oList.get_items().getById(itemId);
    
    this.oUser = clientContext.get_web().get_siteUsers().getByLoginName('DOMAIN\\alias');
    
    

    In SharePoint 2010, we need to write as below:

    this.oListItem = oList.getItemById(itemId);
    this.oUser = clientContext.get_web().ensureUser('SharePoint\\system');

    For resetting  item permission using SPService, per my knowledge, web service has limitation to get item level permission, so this method is not available.

    Here is a detailed article for your reference:

    Limitations of SharePoint Web Services

    Here is a similiar thread for your reference:

    SP ECMA/JS get_siteUsers() not working? trying to get user with getByLoginName()

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, July 2, 2015 6:15 AM
  • Great, thank you very much. It's working now.

    Could you please help with this, I modified code but it doesn't work =(:

    Need conditionally change multiple items. The CAML query is correct, I've took that from view via Designer.

    function breakSecurityInheritanceAddUser() {
    
    	var clientContext = SP.ClientContext.get_current();
    	var oList = clientContext.get_web().get_lists().getByTitle('PMOC');
    
    	var camlQuery = new SP.CamlQuery();
    	camlQuery.set_viewXml("<View><Query><Where><Or><Eq><FieldRef Name='NewColumn1'/><Value Type='Text'>Approved</Value></Eq><Eq><FieldRef Name='NewColumn1'/><Value Type='Text'>Rejected</Value></Eq></Or></Where></Query></View>");
    	this.collListItem = oList.getItems(camlQuery);
    
    	collListItem.breakRoleInheritance(false);
    	this.oUser = clientContext.get_web().ensureUser('CT\\BFEP');
    
    	var collRoleDefinitionBinding = SP.RoleDefinitionBindingCollection.newObject(clientContext);
    
    	collRoleDefinitionBinding.add(clientContext.get_web().get_roleDefinitions().getByType(SP.RoleType.contributor));
    
    	collListItem.get_roleAssignments().add(oUser, collRoleDefinitionBinding);
    
    	clientContext.load(oUser);
    	clientContext.load(collListItem);
    
    	clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
    
    function onQuerySucceeded(sender, args) {
    
        var listItemInfo = '';
    
        var listItemEnumerator = collListItem.getEnumerator();
            
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            listItemInfo += '\nID: ' + oListItem.get_id() + 
                '\nTitle: ' + oListItem.get_item('Title');
        }
    
        alert(listItemInfo.toString());
    }
    
    function onQueryFailed(sender, args) {
    
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }






    Thursday, July 2, 2015 10:45 AM
  • Hi,

    If you need to reassign permission for multi items, you need to bind user permission in OnQuerySucceed function while loop.

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Monday, July 6, 2015 9:33 AM