C# SharePoint 列表项权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1069588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SharePoint list item permissions
提问by Dan Revell
I want to programmatically make it so that users can see only particuar items on the list.
我想以编程方式制作它,以便用户只能看到列表中的特定项目。
Basically in an workflow that runs when an item is created I'm going to do some stuff and notify some people about this item. I also want it to change the permissions on the item so that only particular users (looked up on runtime based on the items contents) can read the item. The rest of the users that have access to the list will only see particular items but not all of them. The list item might not necessarily be owned but the user(s) that need to see it so I can't set the list permissions to letting users only see their own items.
基本上,在创建项目时运行的工作流中,我将做一些事情并通知一些人有关此项目的信息。我还希望它更改项目的权限,以便只有特定用户(根据项目内容在运行时查找)可以读取该项目。有权访问该列表的其余用户将只能看到特定项目,而不是所有项目。列表项可能不一定是拥有的,而是需要查看它的用户,因此我无法将列表权限设置为让用户只能看到他们自己的项目。
To put this into context if it helps- The list is registering job roles to a particular member. Every list item is a role assignment that contains a lookup to a role in the roles list and a lookup to a member in the members list. I'm not directly using a multilookup field in the members list for roles because each role assignment needs extra information held about it such as a description, a start date ect. Each role has a particular user/group that manages it. I want it so that when going to this big list of role assignments, a user can only see the role assignments for the roles that they are the manager of.
如果有帮助,将其放入上下文中 - 该列表正在向特定成员注册工作角色。每个列表项都是一个角色分配,其中包含对角色列表中角色的查找和对成员列表中成员的查找。我没有直接在角色的成员列表中使用多查找字段,因为每个角色分配都需要有关它的额外信息,例如描述、开始日期等。每个角色都有一个管理它的特定用户/组。我想要这样,当进入这个大的角色分配列表时,用户只能看到他们作为经理的角色的角色分配。
Advice would be much appreciated.
建议将不胜感激。
采纳答案by Ariel
You can assign permissions to individual list items. For ex.
您可以为单个列表项分配权限。例如。
// get list item
SPListItem item = <your list item>;
if (!item.HasUniqueRoleAssignments)
{
item.BreakRoleInheritance(true);
}
// get principal
SPPrincipal principal = <principal to grant permissions to>;
// get role definition
SPRoleDefinition rd = <role that contains the permissions to be granted to the principal>;
// create role assignment
SPRoleAssignment ra = new SPRoleAssignment(principal);
ra.RoleDefinitionBindings.Add(rd);
item.RoleAssignments.Add(ra);
But beware about the performance and operational implications of assigning permissions per list item.
但要注意为每个列表项分配权限的性能和操作影响。
In general, I would prefer
一般来说,我更喜欢
- Permissions assigned no deeper than the list level
- As much as possible, assign permissions to groups and then include individual users into those groups.
- 分配的权限不超过列表级别
- 尽可能为组分配权限,然后将单个用户包含到这些组中。