add enable and disable data sources

This commit is contained in:
Jesper Møller Jensen
2023-05-17 17:42:32 +12:00
parent 534a490328
commit 3d65361e39
4 changed files with 90 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbUserDisableDataSource } 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 UmbUserDisableServerDataSource
*/
export class UmbUserDisableServerDataSource implements UmbUserDisableDataSource {
#host: UmbControllerHostElement;
/**
* Creates an instance of UmbUserDisableServerDataSource.
* @param {UmbControllerHostElement} host
* @memberof UmbUserDisableServerDataSource
*/
constructor(host: UmbControllerHostElement) {
this.#host = host;
}
/**
* Set groups for users
* @param {Array<string>} id
* @return {*}
* @memberof UmbUserDisableServerDataSource
*/
async disable(userIds: string[]) {
if (!userIds) throw new Error('User ids are missing');
return tryExecuteAndNotify(
this.#host,
UserResource.postUserDisable({
requestBody: {
userIds,
},
})
);
}
}

View File

@@ -0,0 +1,41 @@
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbUserEnableDataSource } 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 UmbUserEnableServerDataSource
*/
export class UmbUserEnableServerDataSource implements UmbUserEnableDataSource {
#host: UmbControllerHostElement;
/**
* Creates an instance of UmbUserEnableServerDataSource.
* @param {UmbControllerHostElement} host
* @memberof UmbUserEnableServerDataSource
*/
constructor(host: UmbControllerHostElement) {
this.#host = host;
}
/**
* Set groups for users
* @param {Array<string>} id
* @return {*}
* @memberof UmbUserEnableServerDataSource
*/
async enable(userIds: string[]) {
if (!userIds) throw new Error('User ids are missing');
return tryExecuteAndNotify(
this.#host,
UserResource.postUserEnable({
requestBody: {
userIds,
},
})
);
}
}

View File

@@ -1,3 +1,4 @@
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import {
UmbUserCollectionFilterModel,
UmbUserDetailDataSource,
@@ -16,7 +17,6 @@ import {
UmbItemDataSource,
UmbItemRepository,
} from '@umbraco-cms/backoffice/repository';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import {
CreateUserRequestModel,
InviteUserRequestModel,

View File

@@ -44,6 +44,13 @@ export interface UmbUserSetGroupDataSource {
setGroups(userIds: string[], userGroupIds: string[]): Promise<UmbDataSourceErrorResponse>;
}
export interface UmbUserDisableDataSource {
disable(userIds: string[]): Promise<UmbDataSourceErrorResponse>;
}
export interface UmbUserEnableDataSource {
enable(userIds: string[]): Promise<UmbDataSourceErrorResponse>;
}
export interface UmbUserDetailRepository
extends UmbDetailRepository<
CreateUserRequestModel,