I'm looking for a way to give content editors permission to archive certain types of items while preventing them from deleting these same items.
I've added a custom event handler to the item:deleting event. Since both archiving and deleting trigger this event, I would want add some code to the handler that checks whether the user is deleting or archiving the item. If the user is deleting the item, the delete action will be cancelled.
Is there any way to accomplish this?
1) item:deleting event does not make it possible
2) Consider disabling or removing the delete option for the content editor based on the role instead.
Details by John West from his Blog:
...Typically, you can do this by overriding the QueryState() method of the command. I think your QueryState would override the default to call that default. If that result is visible/enabled but your logic says that it should not be, then return disabled (to avoid a jittery UI, it's better to disable than hide commands). This has more detail about custom access rights (which could actually apply in your case), but some detail about QueryState: http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/02/allow-users-to-unlock-items-locked-to-others-in-the-sitecore-aspnet-cms.aspx Unless they invoke the same commands, you may need to consider other ways to trigger those actions, such as from within the Experience Editor (may require overriding another QueryState or two) and possibly elsewhere.