[英]Change permissions of a SharePoint list using JavaScript
I have an app that creates a list. 我有一个创建列表的应用程序。 I'd like the app to also set the list permissions to only allow admins to make changes to the list. 我希望该应用程序还将列表权限设置为仅允许管理员对列表进行更改。 I know how to hide the list, but I understand that this will not prevent clever users from typing in the URL of the list and modifying it anyway. 我知道如何隐藏列表,但我知道这不会阻止聪明的用户输入列表的URL并修改它。
I don't see a way of changing list permissions with JavaScript. 我没有看到用JavaScript更改列表权限的方法。 The functions available to me for lists don't seem to allow for modification of permissions, but it's possible I overlooked the correct one(s). 我可用于列表的功能似乎不允许修改权限,但我可能忽略了正确的权限。
Any pointers on what functions I should be looking at? 关于我应该看什么功能的任何指示?
Use SP.SecurableObject.hasUniqueRoleAssignments property to determine whether the role assignments are uniquely defined for a List or inherited from a parent securable object. 使用SP.SecurableObject.hasUniqueRoleAssignments属性确定角色分配是为List唯一定义的还是从父安全对象继承的。
Use SP.SecurableObject.breakRoleInheritance(copyRoleAssignments, clearSubscopes) Method to set unique role assignments for the List object. 使用SP.SecurableObject.breakRoleInheritance(copyRoleAssignments,clearSubscopes)方法为List对象设置唯一的角色分配。
Example 例
var listTitle = 'Documents';
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
context.load(list,'HasUniqueRoleAssignments');
context.executeQueryAsync(
function(){
var hasUniqueAssgns = list.get_hasUniqueRoleAssignments();
if(!hasUniqueAssgns) {
list.breakRoleInheritance(false, true);
context.executeQueryAsync(
function(){
console.log('Success');
},
function(sender,args){
console.log(args.get_message());
}
);
}
},
function(sender,args){
console.log(args.get_message());
}
);
The following example demonstrates how to break role inheritance for a List object and grant Full Control
permissions for a current user 以下示例演示如何中断List对象的角色继承并为当前用户授予Full Control
权限
Example 例
var listTitle = 'Documents';
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var currentUser = context.get_web().get_currentUser();
list.breakRoleInheritance(false, true); // break role inheritance first!
var roleDefBindingColl = SP.RoleDefinitionBindingCollection.newObject(context);
roleDefBindingColl.add(context.get_web().get_roleDefinitions().getByType(SP.RoleType.administrator));
list.get_roleAssignments().add(currentUser, roleDefBindingColl);
context.executeQueryAsync(
function(){
console.log('Success');
},
function(sender,args){
console.log(args.get_message());
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.