I am trying to add permission to the list which I have created in my app. I am trying to give current user some permission to add update delete items from my list. I have used one article from MSDN site. And my code is as bellow:
function execOperation() {
debugger;
context = new SP.ClientContext(appweburl);
var factory =
new SP.ProxyWebRequestExecutorFactory(
appweburl
);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, appweburl);
var appContextSite2 = new SP.AppContextSite(context, hostweburl);
var siteColl = appContextSite2.get_site();
hostweb = appContextSite2.get_web();
context.load(hostweb);
web = appContextSite.get_web();
context.load(web);
user = web.get_currentUser();
context.load(user);
que_list = web.get_lists().getByTitle("MyList1");
context.load(que_list);
que_list.breakRoleInheritance(true, true);
var permissions = new SP.BasePermissions();
permissions.set(SP.PermissionKind.viewListItems);
permissions.set(SP.PermissionKind.addListItems);
permissions.set(SP.PermissionKind.editListItems);
permissions.set(SP.PermissionKind.deleteListItems);
// Create a new role definition.
var roleDefinitionCreationInfo = new SP.RoleDefinitionCreationInformation();
roleDefinitionCreationInfo.set_name('Manage List Items');
roleDefinitionCreationInfo.set_description('Allows a user to manage list items');
roleDefinitionCreationInfo.set_basePermissions(permissions);
var roleDefinition = web.get_roleDefinitions().add(roleDefinitionCreationInfo);
web.breakRoleInheritance(true, false);
// Create a new RoleDefinitionBindingCollection.
var newBindings = SP.RoleDefinitionBindingCollection.newObject(context);
// Add the role to the collection.
newBindings.add(roleDefinition);
// Get the RoleAssignmentCollection for the target list.
var assignments = que_list.get_roleAssignments();
que_list.breakRoleInheritance(true, true);
// Add the user to the target list and assign the use to the new RoleDefinitionBindingCollection.
var roleAssignment = assignments.add(web.get_currentUser(), newBindings);
context.executeQueryAsync(onSuccess, onFail);
}
I have just copied the code from that article. But when I run my app it give me error :
You cannot customize permission levels in a web site with inherited permission levels
Any suggestions, What am I doing wrong?
Any help will be appreciated...!
Thank you in advance...!