Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a requirement to prevent all users from deleting documents of a certain document type, expect for the admin user.
My first thought was to attach an event to the ContentService.Trashing event handler to achieve this by setting args.Cancel
A Google turned up https://our.umbraco.com/forum/using-umbraco-and-getting-started/75966-contentservice-how-to-get-the-user-who-triggered-the-event that suggests e.Entity.WriterId could be used.
Unfortunately for the Trashing event this doesn't seem to work correctly. I have seen the WriterId come through as 0, even when I've triggered a deletion using a different user.
You can get the current logged in user from below link.
Now, you can check if this user has permission and if yes then only allow trashing event.
Thanks for your response Shasishav
My final solution used the following code
private static bool PrincipleHasPermission(ApplicationContext context, ContentServiceEventAction eventAction )
// Taken from https://stackoverflow.com/questions/35364220/get-current-user-in-umbraco-version-7-3-5 after trying
// several more elegant approaches that just didn't work
var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (userTicket != null)
var currentUser = context.Services.UserService.GetByUsername(userTicket.Name);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted