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

查看:85
本文介绍了使用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为列表对象启用唯一权限



使用 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对象的角色继承,并为当前用户授予完全控制权限

示例

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天全站免登陆