Copied to clipboard

Flag this post as spam?

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


  • Asembli 85 posts 259 karma points
    Mar 03, 2020 @ 20:29
    Asembli
    0

    Dictionary items - prevent deleting for certain users

    Hi,

    I would like to disable deleting dictionary items for certain user group. While LocalizationService Events not realy delete dictionary item - backend notification still shows build-in message and not mine. Dictionary item first dissapeared from the tree - till next tree refresh. But this is confusing for editor, because he thinks that item has been deleted, but has been not. Here is the code. Any hint?

            private void DeletingDictionaryItem(ILocalizationService sender, DeleteEventArgs<IDictionaryItem> e)
        {
            bool isEditorPlus = false;
            var userService = ApplicationContext.Current.Services.UserService;
            var currentUser = userService.GetByUsername(HttpContext.Current.User.Identity.Name);
            foreach (var group in currentUser.Groups)
            {
                if (group.Alias.ToLower() == "editorplus")
                {
                    isEditorPlus = true;
                }
            }
    
            if (isEditorPlus)
            {
                e.CancelOperation(new EventMessage("Restricted", "User cannot delete dictionary items!", EventMessageType.Error));
                //e.Cancel = true;
                // neither this work
                //e.Messages.Add(new EventMessage("Restricted", "User cannot delete dictionary items!", EventMessageType.Error));
            }
        }
    

    EventMessage never appears...

    Regards,

    /Asembli

Please Sign in or register to post replies

Write your reply to:

Draft