User group permission per Document Type
# help-with-umbraco
s
Hi there. I've got a request to set up the user group, that will allow to delete content nodes of one Document Type. There are >500 nodes like that and they are placed as sub-content of the pages. -Folder -Page -NodeAllowDeletion -NodeAllowDeletion2 -Page2 -NodeAllowDeletion -NodeAllowDeletion2 Like that. So I can't just make a permission to the parent folder, because we don't wanna allow delete the pages. The perfect solution is to set up delete permission in the group for the Document Type. But looking the web I realized this is not OOTB and there was no direct solution. One of my idea was: Add Granular Permission to the group programmatically on "ContentSavedNotification" and add permissions to the existing content too.
Copy code
foreach (var entity in notification.SavedEntities)
        {
            if (entity.ContentType.Alias != StaffWriting.ModelTypeAlias)
            {
                continue;
            }

            _contentService.SetPermission(entity, 'F', new List<int> { userGroup.Id });
            _contentService.SetPermission(entity, 'D', new List<int> { userGroup.Id });
        }
Something like that. I don't think this is the best practice. What do you think is there better solution for the problem? Thank you for any help!
j
the savednotification has a publisherId which is the id of the user performing the save.. you could look up the usergroups of that user and then do a cancel notification with an error if they are not permitted
s
hi @Jemayn , thanks for the help. However I don't really have a problem to cancel deletion event to the user in the group. It's more about how to set up the Document Type, so the users in the group will see the delete button. Same words, if user is in the group => he should be able to delete the content of the document type.
j
Ahh I see what you mean - alright in that case the cleanest way would be to just hide the button for those users on rendertime. You can use AngularJs interceptors to catch the button view and replace it with your own which can use an AngularJS controller to perform the usergroup check. This is a bit old but it basically works the same in v13 and down: https://skrift.io/issues/changing-backoffice-functionality-without-changing-core-code/
s
I've got the idea, thank you @Jemayn !!!
8 Views