Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stefano Beretta 101 posts 246 karma points
    May 16, 2019 @ 08:27
    Stefano Beretta
    0

    Prevent user from edit node name

    Hi everyone!

    Is it possible to prevent some users (belonging to a specific group) from changing the node name (content and/or media)?

    Thank you

    S

  • Harrison 42 posts 254 karma points
    May 16, 2019 @ 10:15
    Harrison
    2

    You can, but you would have to setup a custom check using an ApplicationEventHandler.

    An example would be something along the lines of below. It hooks in to the Saving event in the content service, and checks if the name has been changed on the saved entity.

    public class ContentSavingEvents : 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 savedItem in e.SavedEntities)
            {
                var currentPage = sender.GetById(savedItem.Id);
                if (!currentPage.Name.Equals(savedItem.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    //Check user roles here to check if have permission to edit node name
                   if(!userCanEdit){
                         e.Cancel = true;
                         e.Messages.Add(new EventMessage("Error", "Message", EventMessageType.Error));
                }
            }
        }
    }
    
  • Stefano Beretta 101 posts 246 karma points
    May 16, 2019 @ 12:14
    Stefano Beretta
    0

    Thank you Harrison!

    Yeah, that's my current scenario, but I was thinking about something implemented on the client-side (sorry, I didn't give you info enough).

    I'd like to make read-only the node name textbox, any suggestion?

    Thank you again!

    S

Please Sign in or register to post replies

Write your reply to:

Draft