add unlock condition
This commit is contained in:
@@ -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<UmbConditionConfigBase>) {
|
||||
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,
|
||||
};
|
||||
@@ -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<ManifestTypes> = [
|
||||
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',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user