Skip to content

Instantly share code, notes, and snippets.

@janhebnes
Created August 31, 2012 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janhebnes/3550850 to your computer and use it in GitHub Desktop.
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.
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