Created
August 31, 2012 09:36
-
-
Save janhebnes/3550850 to your computer and use it in GitHub Desktop.
Sitecore CMS - Field level security validation for the SaveUI Pipeline so we could make sure no editor suddenly made changes to restricted languages versions of the same items.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EnsureLanguageWriteAccess | |
{ | |
public int Limit | |
{ | |
get; | |
set; | |
} | |
public void Process(Sitecore.Pipelines.Save.SaveArgs args) | |
{ | |
Sitecore.Diagnostics.Assert.ArgumentNotNull(args, "args"); | |
if (args.Items == null) | |
{ | |
return; | |
} | |
foreach (Sitecore.Pipelines.Save.SaveArgs.SaveItem saveItem in args.Items) | |
{ | |
var itemlang = Sitecore.Client.ContentDatabase.GetItem(string.Format("/sitecore/system/Languages/{0}", saveItem.Language)); | |
if (itemlang != null && Sitecore.Security.AccessControl.AuthorizationManager.IsDenied(itemlang | |
, Sitecore.Security.AccessControl.AccessRight.LanguageWrite | |
, Sitecore.Context.User)) | |
{ | |
string loggedErrorMessage = string.Format("The user {0} has tried to edit a language {1} where AccessRight.LanguageWrite is denied. (item: {2})", Sitecore.Context.GetUserName(), saveItem.Language.Name, saveItem.ID.ToString()); | |
Log.Error(loggedErrorMessage, typeof(EnsureLanguageWriteAccess)); | |
SheerResponse.Alert(string.Format("You cannot edit this item because you do not have write access to the current language ({0})", saveItem.Language.Name)); | |
args.SaveAnimation = false; | |
args.AbortPipeline(); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment