Give users permissions on item in other list
this is what I'm working on. I have two lists:
- column user and column project that the user is assigned to.
- (a library): a list of all the projects.
I was wondering, how, by every row that is created in the first list (so adding a user and a project) it is possible to grant the user permissions on this project's reference in the second library (the projects library). Example: ProjectLibrary:
- Project1
- Project2
- Project3
The first list:
- user1 project1
- user1 project2
- user2 project2
- user2 project3
- user3 project3
Now I want to give each user permission to see the project he's assigned to so that 开发者_JS百科when he opens a third form, a combobox filled with projects will only show the projects he has permissions on.
Thank you so much!
As far as I know there is no standard way of setting permissions on certain items in Sharepoint. Only on whole list. If you want to filter combobox - you need to implement custom form (Application Page) and filter combo in your code.
In SharePoint 2007 item level permissions are supported.
You could create a list event handler (SPItemEventReceiver). Every time an user item is changed/added the handler could update the corresponding project item.
public class EventHanlder: SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
// collection user and project information from the item being updated.
SPListItem item = properties.ListItem;
SPUser user = new SPFieldUserValue(item.Web, item["UserFieldName"] as string).User;
int projectId = new SPFieldLookupValue(item["ProjectFieldName"]).Id;
// create role assignment for the user on the user item.
SPRoleAssignment ra = new SPRoleAssignment(user);
SPRoleDefinition rd = item.Web.RoleDefinitions.GetByType(SPRoleType.Reader);
ra.RoleDefinitionBindings.Add(rd);
ra.Update();
// get the project item and update the role assignments.
SPList projectList = // retrieve project list here...
SPListItem projectItem = projectList.GetItemById(projectId);
projectItem.RoleAssignments.Add(ra);
}
}
This is just sample code. I'm not 100% sure if the thing with the SPField***Value works like that.
Now I want to give each user permission to see the project he's assigned to so that when he opens a third form, a combobox filled with projects will only show the projects he has permissions on.
This should be done automatically with a lookup field, since only items a user has permissions on will be displayed.
精彩评论