使用 JavaScript 更改 SharePoint 列表的权限 [英] Change permissions of a SharePoint list using JavaScript

查看:13
本文介绍了使用 JavaScript 更改 SharePoint 列表的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建列表的应用程序.我希望该应用程序还可以将列表权限设置为仅允许管理员更改列表.我知道如何隐藏列表,但我明白这不会阻止聪明的用户输入列表的 URL 并进行修改.

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.

我看不到使用 JavaScript 更改列表权限的方法.我可用于列表的功能似乎不允许修改权限,但我可能忽略了正确的功能.

I don't see a way of changing list permissions with 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?

推荐答案

如何通过 JSOM 为 List 对象启用唯一权限

使用 SP.SecurableObject.hasUniqueRoleAssignments 属性 确定角色分配是为 List 唯一定义的还是从父安全对象继承的.

How to enable unique permissions for a List object via JSOM

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.breakRoleInheritance(copyRoleAssignments, clearSubscopes) 方法为 List 对象设置唯一的角色分配.

Use SP.SecurableObject.breakRoleInheritance(copyRoleAssignments, clearSubscopes) Method to set unique role assignments for the List object.

示例

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

如何通过 JSOM 为 List 对象授予自定义权限

以下示例演示了如何中断 List 对象的角色继承并为当前用户授予 Full Control 权限

示例

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

这篇关于使用 JavaScript 更改 SharePoint 列表的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆