8

One of the things I have to occasionally do as an administrator is unlock items which a user has forgotten to unlock before leaving on vacation. I've been asked if we could create a role which could perform this function (in order to back me up in this area), but which does not have other admin level functions, e.g. user administration.

I've been looking, but not been able to find a way to assign this specific function to a role. Is this possible?

Thanks for your help!

1

3 Answers 3

5

Delegated Administration with SPE

Let's say for example that you wanted to provide a Context Menu option for users to unlock items based on the following criteria.

  • Show when User is in the sitecore\Delegated Admin role
  • Enable when the item is locked

In between cooking eggs at home I was able to whip this up.

Unlock Elevated Context Menu

So here is how I built it.

  1. Create a new SPE Module with a Context Menu library.
  2. Create a new script for unlocking the selected item.
  3. Configure a rule for Show and Enable when certain conditions are met.

Script with Rules

Now the user is able to Lock and Edit.

Lock and Edit

Sample script for Unlock Elevated:

$item = Get-Item -Path .
# The user should be one granted the appropriate access.
$user = Get-User -Id "superuser"
New-UsingBlock (New-Object Sitecore.Security.Accounts.UserSwitcher $user) {
    $item | Unlock-Item
}

Note: This solution may be better suited as a Ribbon command. You can read more about how to do that here.

Unlock Elevated Ribbon


Turns out Richard Seal apparently had the same idea today and hosted this.

3
  • Your security looks neater tho. This question gave me the idea to blog about it :)
    – Richard Seal
    Commented Nov 2, 2016 at 3:09
  • Great to see others have a similar approach. Commented Nov 2, 2016 at 3:32
  • 1
    Was looking for a solution to this exact problem today! Realized I wrote the answer. Commented Apr 6, 2017 at 21:02
4

Assuming you're only interested in shell behaviour, there's a long and a short answer.

Short answer: no. The command that executes this functionality (Sitecore.Shell.Framework.Commands.CheckIn) only allows the unlock action to happen if the user is an administrator or if the user owns the lock. This is regardless of permissions you set on the button item.

Longer answer: yes. But you need to write your own command to do the unlock. This is actually quite straight-forward. You create a new command, register it in configuration, and then replace the command name on the item with your own (or add an extra button).

What you do in your command will depend on your Sitecore version. Offhand, I don't know when the change came in, but I think that the same check present in the command used to be present in the item.Locking.Unlock() method. If this doesn't work for you, you can cheat a bit and directly call ReleaseLock() on the lock field (which you can get by using (LockField)item.Fields[FieldIDs.Lock]).

You should make sure that your command performs the necessary security checks for your application; as you probably don't want it to be available to everyone.

1

Unfortunately, I do not believe there is a permission/role that can be assigned to a user to give them this ability. It is build into the special "admin" user.

However, you could write a script using Sitecore PowerShell Extensions (SPE) that does this, and give specific users access to run it via a custom button. You could do this by either creating a button that executes a script to unlock all items for all users, all items for the current user, open a SPEAK dialog where the user can select a specific item from the tree to unlock, a specific user to unlock all items for, or for the currently selected item in the content editor. Here are the docs for the Unlock-item SPE call.

Alternatively, you could also write a custom SPEAK tool for unlocking items using C#. In either scenario, you would selectively give users/roles Read access to the custom button(s) that open(s) or execute(s) the tool.

It is worth noting that either option involves you creating a custom button to run your tool, and any user that you give access see the custom button will have access to use the tool.

2
  • 2
    SPE is the way to go, write a module to enable right-click unlocking: sitecorenutsbolts.net/2016/11/01/…
    – Richard Seal
    Commented Nov 2, 2016 at 0:59
  • Like the solution in @RichardSeal's post is a great example of a custom button! Remember that you can use Securities to assign the Read permission to particular users/roles for the "button" in a context menu. Commented Nov 2, 2016 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.