3
votes

Does anyone have any suggested strategies for preventing users from editing page names?

I'm developing a site on Umbraco where various partners have their own specific page they can edit exclusively. Access to this page is controlled through the standard Umbraco permissions. However we've found that some of these users have been editing the page title, but we'd like to limit them to only being able to edit the content.

I can't see any obvious way to control this through the built-in permissions.

Perhaps it's possible to plug in some page pre-save code that checks if the user has certain permissions, and if they don't the page name is set to it's pre-edit state?

Any suggestions / pointers are greatly appreciated.

1

1 Answers

8
votes

Yes, you can hook up to Umbraco ContentService events and check if Name has changed and do or not do something with this specific node. You can also add some additional checks to determine if user is permitted to change the name (e.g. you can control this by role or anything else whay you need).

Sample code will look like this:

public class UmbracoEvents : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Saving += ContentService_Saving;
    }

    private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
    {
        foreach (var changedItem in e.SavedEntities)
        {
            var currentVersion = sender.GetById(changedItem.Id);
            if (!currentVersion.Name.InvariantEquals(changedItem.Name))
            {
                // Additional checks here (or in the above condition) - role / property / etc...
                item.Name = currentVersion.Name;
            }
        }
    }
}

You can read more about specific events here too: https://our.umbraco.org/documentation/reference/events/contentservice-events.