Created
August 31, 2012 09:39
-
-
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
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 | |
{ | |
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