Skip to content

Instantly share code, notes, and snippets.

@janhebnes
Created August 31, 2012 09:39
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/3550889 to your computer and use it in GitHub Desktop.
Save janhebnes/3550889 to your computer and use it in GitHub Desktop.
Sitecore does not implement hard validation on the language write access at field level, so to make sure a local editor would never be able to mingle with a language he did not have access to, we added the restriction code to the Item:Saving event queue p
public class EnsureLanguageWriteAccess
{
protected void OnItemSaving(object sender, EventArgs args)
{
Item item = Event.ExtractParameter(args, 0) as Item;
Error.AssertNotNull(item, "No item in parameters");
var itemlang = item.Database.GetItem(string.Format("/sitecore/system/Languages/{0}", item.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(), item.Language.Name, item.Paths.ContentPath);
Log.Error(loggedErrorMessage, typeof(EnsureLanguageWriteAccess));
throw new Exception("You do not have access to write content in this Language context.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment