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.
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.
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.
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
}