3

We're using Sitecore 8. We have a scenario to provide permission to one user to unlock items which are locked by other user in CE.

Could you please advise on it.

3

I wrote an article "How to add a Sitecore Unlock Item Button to the Content Editor ribbon".

The simplest code is:

public class UnlockItem : Command
{
    public override void Execute(CommandContext context)
    {
        using (new Sitecore.SecurityModel.SecurityDisabler())
        {
            context.Items[0].Locking.Unlock();
        }
    }
}

You need to register the new command:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="contenteditor:unlockitem" type="MyAssembly.Namespace.UnlockItem, MyAssembly" />
    </commands>
  </sitecore>
</configuration>

And add a button item in core database, e.g. under /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Locks item, with Click field set to contenteditor:unlockitem.

Or just download the Sitecore content package from the Sitecore Unlock Item Button article and install it on your CM server.

If you want to restrict the access to the command, break the inheritance of access rights on the new button and allow read access for it for the chosen role (or users) only.

  • Awesome. Man that is simple but worth its weight in gold to an editor. – Chris Auer May 31 '18 at 19:23
4

Below is a script I used as part of a Ribbon command in SPE.

$item = Get-Item -Path .
$user = Get-User -Id "sitecore\admin"
New-UsingBlock (New-Object Sitecore.Security.Accounts.UserSwitcher $user) {
    $item | Unlock-Item
}

Add the ribbon integration: enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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