获取角色定义的可靠方法



获取预定义角色(如读者、管理员(的角色定义 ID 的最佳方法是什么?

我正在尝试配置一个文件夹,让成员只有读取权限。为此,我将删除成员的现有角色分配并向其添加读者角色。SharePoint REST API 要求我提供角色定义 ID,但我找不到可靠地获取它的方法。

似乎我可以按名称_api/web/roledefinitions/getbyname('Read')获得它,但我担心如何处理非英语语言环境的情况。我希望它可以按类型_api/web/roledefinitions/getbytypekind(2)搜索,但我无法让它工作。它给了我一个错误Cannot find resource for the request getbytypekind.

另外,是否可以删除默认角色定义?

好像我可以通过名字得到它 _api/web/roledefinitions/getbyname('Read'(,但我关心如何处理非英语语言环境的情况

没错,SP.RoleDefinition.name属性可能因区域设置而异,因此在这方面按角色类型检索角色定义肯定更可靠,SP.RoleDefinitionCollection.getByType可以使用此方法,例如:

/_api/web/roledefinitions/getByType(<roletypeid>)

其中roletypeid对应于SP.RoleType枚举

您可以通过以下方式获取角色定义列表

https://xxxx.sharepoint.com/_api/Web/RoleDefinitions

然后你可以通过id(如read(获取特定角色,所以我们不需要关心语言环境问题:

https://xxxx.sharepoint.com/_api/Web/RoleDefinitions(1073741826)

角色列表和 id:

FullControl(Web/RoleDefinitions(1073741829))
Design(Web/RoleDefinitions(1073741828))
Edit(Web/RoleDefinitions(1073741830))
Contribute(Web/RoleDefinitions(1073741827))
Read(Web/RoleDefinitions(1073741826))
Limited Access(Web/RoleDefinitions(1073741825))
System.LimitedView(Web/RoleDefinitions(1073741926))
System.LimitedEdit(Web/RoleDefinitions(1073741927))
Create new subsites(Web/RoleDefinitions(1073741924))
View Only(Web/RoleDefinitions(1073741925))

我们可以使用默认角色或自定义我们自己的角色,所以我认为Microsoft不需要提供用于删除内置角色的 API。

虽然我们也可以使用 getbytype 方法,但角色类型值列表不是很用户友好。(在下面的链接中查看更多信息(

https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_RoleDefinitionCollectionGetById https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_RoleDefinitionCollectionGetByType

相关内容

最新更新