Subscribe:      
 

How to Programmatically Set User And Group Permissions

Written By: Ivan Ivanov -- 10/5/2011 -- join -- contribute -- (145) comments -- printer friendly version

Rating: Rate --

Categories: Design, MOSS 2007, Permission Management, Programming and Customizations, Visual Studio, Web Parts, WSS3

< Prev - 1 | 2 | 3 | 4 | 5 | 6 | - Next > | Become a paid author

Problem

There is a company with a lot of employees. The requirement is to automate the request process and the approval of employees’ holidays.

  • Each employee has to be able to submit requests for holidays.
  • The request has to be approved or rejected by the employee's manager.
  • Each employee has to have the ability to view only his/her own requests.
  • Each manager has to have the right to approve or reject only requests that are requested by employees in his/her department.
  • After the manager’s actions, the manager has to be able to only read requests related to his/her department.

Solution

Let’s assume there are 3 departments in the company – Sales, Accounting and IT.


To fulfill the requirement we are going to create a SharePoint list named “Holidays”. We will store the requests in this list. All users will need "Add item" permissions.



The following picture shows the columns needed:

Now we have to set the Add permission to all users.


Create 3 SharePoint groups - one for each department: Sales, Accounting and IT

The main point is how to set the appropriate user’s permissions on each step of the process. When the employee has made a request and then saves it, the saved item has to be denied for everybody, except for the creator and the manager. The Creator has to have read permission on the item and the corresponding manager has to have “Update” permissions on the item. After the manager’s action (approve or reject), the manager has to have read permission on the item. So does the creator.

To fulfill the requirements related to the permission rules, we can create two web parts – one for new requests and one for approvals and rejections. On the save action, we will programmatically set the appropriate permissions.

Let’s start with the creation of the web parts.

In order to make the web parts we will use Visual Studio 2008. On the Navigation Pane from the "File" menu, select "New Project". We will name this project "WPHolidays". Under "Project Types" select SharePoint, and under "Visual Studio installed Templates" select "WebPart Template". Type the project name and press OK.

Next is to select the trust level for this project. We chose Partial Trust.


< Prev - 1 | 2 | 3 | 4 | 5 | 6 | - Next >



Learn more about SharePoint



Sponsor Information




Copyright (c) 2010-2017 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


MSSharePointTips.com | MSSQLTips.com