Showing posts with label Permissions. Show all posts
Showing posts with label Permissions. Show all posts

Tuesday, July 19, 2016

Restricted Edit Event Receiver - SharePoint 2013

Scenario
  • You need to restrict edits to a document library based on the current value of a field.
  • Full trust farm solution for SharePoint 2013 scoped to Web.
Solution
  • I created a configurable event receiver that will restrict edits (metadata and content) based on the value in one of the document's metadata columns.
  • Additional feature: Delay implementation of the restriction for a number of seconds from Created Date to allow for additional automated processes to update new documents.
  • Additional feature: Exclude a document from the restriction based on a regular expression using its  filename.
  • Additional feature: Automatically populate the Title field (or other text field) based on another choice or text field.
  • Open-Source code is available here:  RestrictedSave ZIP
    • Feel free to modify and use this code.  You may not resell it or a modified version of it as part of a packaged solution without my permission.
  • Disclaimer:  This will only prevent edits that trigger the item updating event receiver.  Some programmatic and 3rd party API calls made using bulk edit operations, workflow actions, or other event receivers may bypass the event receiver.  In addition, this code is not hardened for high security scenarios and is only meant as a first line defense against unwanted typical user edits.
Installation
  • Download the RestrictedSave WSP file and deploy to your farm.
  • Enable the Restricted Save feature on your sub-site.
    • Feature Description:
      Configured via the RestrictedSave list. If this site does not have one, a RestrictedSave list will be added. Document libraries named in the RestrictedSave list will not save a file if the user is unauthorized and the assigned column contains a certain value. If no required permission is specified, then the field can only be edited if the restricted column's value is changed. Multiple document libraries, columns, or values may be configured but must exist in this subsite. Optional New File Delay and Regular Expression Exclusion may be configured as well. Will also set the document title and/or filename based on a choice field by using the 'Title Choice Field' columns.
  • Configure the RestrictedSave list that was added to the site according to your needs.
Example

  • A standard configuration of the RestrictedSave list to restrict edits on a document library named "RestrictDeleteTest" when the "LOBType" column is set to "Choice 1".

  • The resultant error displayed on a document's edit properties form in the "RestrictDeleteTest" library when a filename modification is attempted.


  • Error Message in clear text
UNABLE TO SAVE! -- When column "LOBType" is set to "Choice 1" the item is locked and cannot be updated. -- Please work from a new copy or change the column value.





RestrictedSave List Configurable Fields
  • Instructions are provided in-line on the form.
  • Add one line for each restriction.  All lines will be parsed for each document edited in the sub-site.

--------------------------------------------------------------------------------------


And again in text format for search-engines, visually impaired, and copy/paste:

Document Library Name *


Column Name


Column Value


Required Permission To Edit

   

New Item Delay Seconds


Title Exclusion Regex


Title Choice Field Name


Title Choice Target

   

Monday, November 16, 2009

Access Denied, Not a Site Collection Admin, and Cannot Create New Items

Scenario
  • You are a Site Collection Admin and Farm Admin for a SharePoint Farm
  • Someone has recently backed up a site collection using Stsadm which includes a site collection lock (SP2 supposedly does this automatically)
Issue
  • Attempt to edit the Site Collection Admins from Site Settings results in the following
    • Error:  You need to be a site collection administrator to set this property
  • Attempt to load a page which does any advanced processing
    • Access Denied
Resolution
  • The Site Collection was Locked (Read-only).  Unlock it via Central Admin (_admin/sitequota.aspx)
    • Set to Not locked

Friday, November 6, 2009

Reorder Page Permission Error

Scenario
  • Created a Links list with item level permissions and User Sorting enabled on a View.
  • Current user has Contribute access to the list with only access to some items (ex: only their own)
Issue
  • The following Error occurs when Clicking the Reorder Menu item

    • You don't have enough permission to access this page. at Microsoft.SharePoint.ApplicationPages.ReorderPage.OnLoad(EventArgs e)
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Resolution
  • You cannot use the out of the box reorder feature when you are using item-level permissions.
    • The user must have edit permissions on every item in the list in order to reorder.
  • Instead, create your own order column and manually configure the sort order in your Views.