added unlock action
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbUserRepository } from '../../repository/user.repository';
|
||||
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
export class UmbUnlockUserEntityBulkAction extends UmbEntityBulkActionBase<UmbUserRepository> {
|
||||
constructor(host: UmbControllerHostElement, repositoryAlias: string, selection: Array<string>) {
|
||||
@@ -8,7 +8,6 @@ export class UmbUnlockUserEntityBulkAction extends UmbEntityBulkActionBase<UmbUs
|
||||
}
|
||||
|
||||
async execute() {
|
||||
//TODO: Implement
|
||||
alert('Bulk unlock is not implemented yet');
|
||||
await this.repository?.unlock(this.selection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbUserUnlockDataSource } from '../../types';
|
||||
import { UserResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* A data source for Data Type items that fetches data from the server
|
||||
* @export
|
||||
* @class UmbUserUnlockServerDataSource
|
||||
*/
|
||||
export class UmbUserUnlockServerDataSource implements UmbUserUnlockDataSource {
|
||||
#host: UmbControllerHostElement;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbUserUnlockServerDataSource.
|
||||
* @param {UmbControllerHostElement} host
|
||||
* @memberof UmbUserUnlockServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* unlock users
|
||||
* @param {Array<string>} id
|
||||
* @return {*}
|
||||
* @memberof UmbUserUnlockServerDataSource
|
||||
*/
|
||||
async unlock(userIds: string[]) {
|
||||
if (!userIds) throw new Error('User ids are missing');
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
UserResource.postUserUnlock({
|
||||
requestBody: {
|
||||
userIds,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { UMB_USER_ITEM_STORE_CONTEXT_TOKEN, UmbUserItemStore } from './user-item
|
||||
import { UmbUserSetGroupsServerDataSource } from './sources/user-set-group.server.data';
|
||||
import { UmbUserEnableServerDataSource } from './sources/user-enable.server.data';
|
||||
import { UmbUserDisableServerDataSource } from './sources/user-disable.server.data';
|
||||
import { UmbUserUnlockServerDataSource } from './sources/user-unlock.server.data';
|
||||
import {
|
||||
UmbCollectionDataSource,
|
||||
UmbCollectionRepository,
|
||||
@@ -41,8 +42,10 @@ export class UmbUserRepository
|
||||
#itemStore?: UmbUserItemStore;
|
||||
#setUserGroupsSource: UmbUserSetGroupDataSource;
|
||||
|
||||
//ACTIONS
|
||||
#enableSource: UmbUserEnableServerDataSource;
|
||||
#disableSource: UmbUserDisableServerDataSource;
|
||||
#unlockSource: UmbUserUnlockServerDataSource;
|
||||
|
||||
#collectionSource: UmbCollectionDataSource<UserResponseModel>;
|
||||
|
||||
@@ -55,6 +58,7 @@ export class UmbUserRepository
|
||||
this.#collectionSource = new UmbUserCollectionServerDataSource(this.#host);
|
||||
this.#enableSource = new UmbUserEnableServerDataSource(this.#host);
|
||||
this.#disableSource = new UmbUserDisableServerDataSource(this.#host);
|
||||
this.#unlockSource = new UmbUserUnlockServerDataSource(this.#host);
|
||||
this.#itemSource = new UmbUserItemServerDataSource(this.#host);
|
||||
this.#setUserGroupsSource = new UmbUserSetGroupsServerDataSource(this.#host);
|
||||
|
||||
@@ -226,4 +230,16 @@ export class UmbUserRepository
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
}
|
||||
|
||||
async unlock(ids: Array<string>) {
|
||||
if (ids.length === 0) throw new Error('User ids are missing');
|
||||
|
||||
const { error } = await this.#unlockSource.unlock(ids);
|
||||
|
||||
if (!error) {
|
||||
//TODO: UPDATE STORE
|
||||
const notification = { data: { message: `${ids.length > 1 ? 'Users' : 'User'} unlocked` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ export interface UmbUserDisableDataSource {
|
||||
export interface UmbUserEnableDataSource {
|
||||
enable(userIds: string[]): Promise<UmbDataSourceErrorResponse>;
|
||||
}
|
||||
export interface UmbUserUnlockDataSource {
|
||||
unlock(userIds: string[]): Promise<UmbDataSourceErrorResponse>;
|
||||
}
|
||||
|
||||
export interface UmbUserDetailRepository
|
||||
extends UmbDetailRepository<
|
||||
|
||||
Reference in New Issue
Block a user