diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/conditions/user-allow-unlock-action.condition.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/conditions/user-allow-unlock-action.condition.ts new file mode 100644 index 0000000000..43a0c5a51a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/conditions/user-allow-unlock-action.condition.ts @@ -0,0 +1,40 @@ +import { UmbUserDetail } from '../types.js'; +import { UmbUserWorkspaceContext } from '../workspace/user-workspace.context.js'; +import { UserStateModel } from '@umbraco-cms/backoffice/backend-api'; +import { UmbBaseController } from '@umbraco-cms/backoffice/controller-api'; +import { + ManifestCondition, + UmbConditionConfigBase, + UmbConditionControllerArguments, + UmbExtensionCondition, +} from '@umbraco-cms/backoffice/extension-api'; +import { UMB_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace'; + +export class UmbUserAllowUnlockActionCondition extends UmbBaseController implements UmbExtensionCondition { + config: UmbConditionConfigBase; + permitted = false; + #onChange: () => void; + + constructor(args: UmbConditionControllerArguments) { + super(args.host); + this.config = args.config; + this.#onChange = args.onChange; + + this.consumeContext(UMB_WORKSPACE_CONTEXT, (context) => { + const userContext = context as UmbUserWorkspaceContext; + this.observe(userContext.data, (data) => this.onUserDataChange(data)); + }); + } + + onUserDataChange(user: UmbUserDetail | undefined) { + this.permitted = user?.state === UserStateModel.LOCKED_OUT; + this.#onChange(); + } +} + +export const manifest: ManifestCondition = { + type: 'condition', + name: 'User Allow Unlock Action Condition', + alias: 'Umb.Condition.User.AllowUnlockAction', + api: UmbUserAllowUnlockActionCondition, +}; diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/manifests.ts index c6da2e5981..571d701c59 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/manifests.ts @@ -2,6 +2,7 @@ import { CHANGE_USER_PASSWORD_REPOSITORY_ALIAS, DISABLE_USER_REPOSITORY_ALIAS, ENABLE_USER_REPOSITORY_ALIAS, + UNLOCK_USER_REPOSITORY_ALIAS, USER_REPOSITORY_ALIAS, } from '../repository/manifests.js'; import { UMB_USER_ENTITY_TYPE } from '../index.js'; @@ -84,9 +85,14 @@ const entityActions: Array = [ meta: { icon: 'umb:unlocked', label: 'Unlock', - repositoryAlias: CHANGE_USER_PASSWORD_REPOSITORY_ALIAS, + repositoryAlias: UNLOCK_USER_REPOSITORY_ALIAS, entityTypes: [UMB_USER_ENTITY_TYPE], }, + conditions: [ + { + alias: 'Umb.Condition.User.AllowUnlockAction', + }, + ], }, ];