register unlock user entity action
This commit is contained in:
@@ -8,6 +8,7 @@ import { UMB_USER_ENTITY_TYPE } from '../index.js';
|
||||
import { UmbDisableUserEntityAction } from './disable/disable-user.action.js';
|
||||
import { UmbEnableUserEntityAction } from './enable/enable-user.action.js';
|
||||
import { UmbChangeUserPasswordEntityAction } from './change-password/change-user-password.action.js';
|
||||
import { UmbUnlockUserEntityAction } from './unlock/unlock-user.action.js';
|
||||
import { UmbDeleteEntityAction } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
@@ -74,6 +75,19 @@ const entityActions: Array<ManifestTypes> = [
|
||||
entityTypes: [UMB_USER_ENTITY_TYPE],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'entityAction',
|
||||
alias: 'Umb.EntityAction.User.Unlock',
|
||||
name: 'Unlock User Entity Action',
|
||||
weight: 600,
|
||||
api: UmbUnlockUserEntityAction,
|
||||
meta: {
|
||||
icon: 'umb:key',
|
||||
label: 'Change Password',
|
||||
repositoryAlias: CHANGE_USER_PASSWORD_REPOSITORY_ALIAS,
|
||||
entityTypes: [UMB_USER_ENTITY_TYPE],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions];
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { type UmbUnlockUserRepository, UmbUserRepository } from '../../repository/index.js';
|
||||
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import {
|
||||
type UmbModalManagerContext,
|
||||
UMB_MODAL_MANAGER_CONTEXT_TOKEN,
|
||||
UMB_CONFIRM_MODAL,
|
||||
} from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export class UmbUnlockUserEntityAction extends UmbEntityActionBase<UmbUnlockUserRepository> {
|
||||
#modalManager?: UmbModalManagerContext;
|
||||
#itemRepository: UmbUserRepository;
|
||||
|
||||
constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) {
|
||||
super(host, repositoryAlias, unique);
|
||||
|
||||
this.#itemRepository = new UmbUserRepository(this.host);
|
||||
|
||||
new UmbContextConsumerController(this.host, UMB_MODAL_MANAGER_CONTEXT_TOKEN, (instance) => {
|
||||
this.#modalManager = instance;
|
||||
});
|
||||
}
|
||||
|
||||
async execute() {
|
||||
if (!this.repository || !this.#modalManager) return;
|
||||
|
||||
const { data } = await this.#itemRepository.requestItems([this.unique]);
|
||||
|
||||
if (data) {
|
||||
const item = data[0];
|
||||
|
||||
const modalContext = this.#modalManager.open(UMB_CONFIRM_MODAL, {
|
||||
headline: `Unlock ${item.name}`,
|
||||
content: 'Are you sure you want to unlock this user?',
|
||||
confirmLabel: 'Unlock',
|
||||
});
|
||||
|
||||
await modalContext.onSubmit();
|
||||
await this.repository?.unlock([this.unique]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user