1

We have a multi-lingual multisite instance with v10.1.3
And there are authoring roles for each site & role.

A common occurrence is, items are locked by a person who is unavailable and the current author does not have the option to unlock/check-in. So, an admin would unlock those items.

For some items, the admin can see the Elevated unlock option and for some, that option is not available. So admin has to do a Review > Check-in.

  1. Is there a way to unlock items that are locked by a specific user, using powershell.
  2. Is there any way to give the option to the author itself, without making them an admin, like adding any default or custom role
0

1 Answer 1

1
  1. Solution for unlocking items locked by a specific user.
Get-ChildItem master:\content -rec -Language * | 
  Where-Object { $_.Locking.GetOwner() -eq "sitecore\USERNAME" } | 
  % { $_.Locking.Unlock() }
  1. Unlock Item command button in Sitecore Content Editor. Allow access of this button to specific role only.
public class UnlockItem : Command
    {
        public override void Execute(CommandContext context)
        {
            if (context.Items.Length != 1)
                return;

            var item = context.Items[0];
            if (item.Locking.IsLocked() && item.Access.CanWrite())
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    item.Locking.Unlock();
                }
            }
        }

        public override CommandState QueryState(CommandContext context)
        {
            if (context.Items.Length != 1)
                return CommandState.Hidden;

            var item = context.Items[0];

            if (!item.Locking.IsLocked() || !item.Access.CanWrite())
                return CommandState.Hidden;

            return base.QueryState(context);
        }
    }

Patch config

<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 new button in core database under: /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Locks item

Credit: https://www.skillcore.net/sitecore/sitecore-unlock-item-command

Hope it helps!

2
  • For #2 is there a just CMS approach, like adding a role?
    – sukesh
    Commented Sep 7, 2023 at 4:49
  • No, you need to do some level of custom development. Commented Sep 7, 2023 at 5:34

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