rename logged in user to current user
This commit is contained in:
@@ -2,7 +2,7 @@ import { UmbEntityData } from './entity.data.js';
|
||||
import { umbUserGroupData } from './user-group.data.js';
|
||||
import { arrayFilter, stringFilter, queryFilter } from './utils.js';
|
||||
import { UmbId } from '@umbraco-cms/backoffice/id';
|
||||
import { UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import {
|
||||
CreateUserRequestModel,
|
||||
CreateUserResponseModel,
|
||||
@@ -21,8 +21,10 @@ const createUserItem = (item: UserResponseModel): UserItemResponseModel => {
|
||||
};
|
||||
};
|
||||
|
||||
const userGroupFilter = (filterOptions: any, item: UserResponseModel) => arrayFilter(filterOptions.userGroupIds, item.userGroupIds);
|
||||
const userStateFilter = (filterOptions: any, item: UserResponseModel) => stringFilter(filterOptions.userStates, item.state);
|
||||
const userGroupFilter = (filterOptions: any, item: UserResponseModel) =>
|
||||
arrayFilter(filterOptions.userGroupIds, item.userGroupIds);
|
||||
const userStateFilter = (filterOptions: any, item: UserResponseModel) =>
|
||||
stringFilter(filterOptions.userStates, item.state);
|
||||
const userQueryFilter = (filterOptions: any, item: UserResponseModel) => queryFilter(filterOptions.filter, item.name);
|
||||
|
||||
// Temp mocked database
|
||||
@@ -89,7 +91,7 @@ class UmbUserData extends UmbEntityData<UserResponseModel> {
|
||||
* @return {*} {UmbLoggedInUser}
|
||||
* @memberof UmbUserData
|
||||
*/
|
||||
getCurrentUser(): UmbLoggedInUser {
|
||||
getCurrentUser(): UmbCurrentUser {
|
||||
const firstUser = this.data[0];
|
||||
const permissions = firstUser.userGroupIds?.length ? umbUserGroupData.getPermissions(firstUser.userGroupIds) : [];
|
||||
|
||||
@@ -159,26 +161,31 @@ class UmbUserData extends UmbEntityData<UserResponseModel> {
|
||||
this.createUser(invitedUser);
|
||||
}
|
||||
|
||||
filter (options: any): PagedUserResponseModel {
|
||||
filter(options: any): PagedUserResponseModel {
|
||||
const { items: allItems } = this.getAll();
|
||||
|
||||
const filterOptions = {
|
||||
skip: options.skip || 0,
|
||||
take: options.take || 25,
|
||||
orderBy: options.orderBy || 'name',
|
||||
orderDirection: options.orderDirection || 'asc',
|
||||
userGroupIds: options.userGroupIds,
|
||||
userStates: options.userStates,
|
||||
filter: options.filter,
|
||||
};
|
||||
const filterOptions = {
|
||||
skip: options.skip || 0,
|
||||
take: options.take || 25,
|
||||
orderBy: options.orderBy || 'name',
|
||||
orderDirection: options.orderDirection || 'asc',
|
||||
userGroupIds: options.userGroupIds,
|
||||
userStates: options.userStates,
|
||||
filter: options.filter,
|
||||
};
|
||||
|
||||
const filteredItems = allItems.filter((item) => userGroupFilter(filterOptions, item) && userStateFilter(filterOptions, item) && userQueryFilter(filterOptions, item));
|
||||
const filteredItems = allItems.filter(
|
||||
(item) =>
|
||||
userGroupFilter(filterOptions, item) &&
|
||||
userStateFilter(filterOptions, item) &&
|
||||
userQueryFilter(filterOptions, item),
|
||||
);
|
||||
const totalItems = filteredItems.length;
|
||||
|
||||
const paginatedItems = filteredItems.slice(filterOptions.skip, filterOptions.skip + filterOptions.take);
|
||||
|
||||
return { total: totalItems, items: paginatedItems };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const data: Array<UserResponseModel & { type: string }> = [
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
UmbModalManagerContext,
|
||||
UMB_MODAL_MANAGER_CONTEXT_TOKEN,
|
||||
} from '@umbraco-cms/backoffice/modal';
|
||||
import { UMB_AUTH_CONTEXT, UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
|
||||
interface MediaPickerTargetData {
|
||||
altText?: string;
|
||||
@@ -26,7 +26,7 @@ interface MediaPickerResultData {
|
||||
|
||||
export default class UmbTinyMceMediaPickerPlugin extends UmbTinyMcePluginBase {
|
||||
#mediaHelper: UmbMediaHelper;
|
||||
#currentUser?: UmbLoggedInUser;
|
||||
#currentUser?: UmbCurrentUser;
|
||||
#modalContext?: UmbModalManagerContext;
|
||||
#auth?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
UMB_CURRENT_USER_MODAL,
|
||||
} from '@umbraco-cms/backoffice/modal';
|
||||
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
|
||||
import { UMB_AUTH_CONTEXT, type UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, type UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
|
||||
@customElement('umb-current-user-header-app')
|
||||
export class UmbCurrentUserHeaderAppElement extends UmbLitElement {
|
||||
@state()
|
||||
private _currentUser?: UmbLoggedInUser;
|
||||
private _currentUser?: UmbCurrentUser;
|
||||
|
||||
private _auth?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
private _modalContext?: UmbModalManagerContext;
|
||||
@@ -32,9 +32,13 @@ export class UmbCurrentUserHeaderAppElement extends UmbLitElement {
|
||||
private async _observeCurrentUser() {
|
||||
if (!this._auth) return;
|
||||
|
||||
this.observe(this._auth.currentUser, (currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
}, 'umbCurrentUserObserver');
|
||||
this.observe(
|
||||
this._auth.currentUser,
|
||||
(currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
},
|
||||
'umbCurrentUserObserver',
|
||||
);
|
||||
}
|
||||
|
||||
private _handleUserClick() {
|
||||
|
||||
@@ -3,11 +3,11 @@ import { UmbBaseController, UmbControllerHost } from '@umbraco-cms/backoffice/co
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { UserResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UMB_AUTH_CONTEXT, UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
export class UmbCurrentUserContext extends UmbBaseController {
|
||||
#currentUser = new UmbObjectState<UmbLoggedInUser | undefined>(undefined);
|
||||
#currentUser = new UmbObjectState<UmbCurrentUser | undefined>(undefined);
|
||||
readonly currentUser = this.#currentUser.asObservable();
|
||||
|
||||
readonly languageIsoCode = this.#currentUser.asObservablePart((user) => user?.languageIsoCode ?? 'en-us');
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
export * from './current-user-history.store.js';
|
||||
export * from './utils/index.js';
|
||||
export * from './current-user.context.js';
|
||||
export * from './types.js';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { UMB_APP } from '@umbraco-cms/backoffice/app';
|
||||
import { UMB_AUTH_CONTEXT, type UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, type UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
|
||||
import { css, CSSResultGroup, html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UmbModalContext } from '@umbraco-cms/backoffice/modal';
|
||||
@@ -11,7 +11,7 @@ export class UmbCurrentUserModalElement extends UmbLitElement {
|
||||
modalContext?: UmbModalContext;
|
||||
|
||||
@state()
|
||||
private _currentUser?: UmbLoggedInUser;
|
||||
private _currentUser?: UmbCurrentUser;
|
||||
|
||||
#authContext?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
|
||||
@@ -33,9 +33,13 @@ export class UmbCurrentUserModalElement extends UmbLitElement {
|
||||
private async _observeCurrentUser() {
|
||||
if (!this.#authContext) return;
|
||||
|
||||
this.observe(this.#authContext.currentUser, (currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
}, 'umbCurrentUserObserver');
|
||||
this.observe(
|
||||
this.#authContext.currentUser,
|
||||
(currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
},
|
||||
'umbCurrentUserObserver',
|
||||
);
|
||||
}
|
||||
|
||||
private _close() {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export type { CurrentUserResponseModel as UmbCurrentUser } from '@umbraco-cms/backoffice/backend-api';
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
UMB_CHANGE_PASSWORD_MODAL,
|
||||
UMB_MODAL_MANAGER_CONTEXT_TOKEN,
|
||||
} from '@umbraco-cms/backoffice/modal';
|
||||
import { UMB_AUTH_CONTEXT, type UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, type UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
|
||||
@customElement('umb-user-profile-app-profile')
|
||||
export class UmbUserProfileAppProfileElement extends UmbLitElement {
|
||||
@state()
|
||||
private _currentUser?: UmbLoggedInUser;
|
||||
private _currentUser?: UmbCurrentUser;
|
||||
|
||||
private _modalContext?: UmbModalManagerContext;
|
||||
private _auth?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
@@ -32,9 +32,13 @@ export class UmbUserProfileAppProfileElement extends UmbLitElement {
|
||||
private async _observeCurrentUser() {
|
||||
if (!this._auth) return;
|
||||
|
||||
this.observe(this._auth.currentUser, (currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
}, 'umbCurrentUserObserver');
|
||||
this.observe(
|
||||
this._auth.currentUser,
|
||||
(currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
},
|
||||
'umbCurrentUserObserver',
|
||||
);
|
||||
}
|
||||
|
||||
private _edit() {
|
||||
@@ -45,7 +49,7 @@ export class UmbUserProfileAppProfileElement extends UmbLitElement {
|
||||
}
|
||||
private _changePassword() {
|
||||
if (!this._modalContext) return;
|
||||
|
||||
|
||||
this._modalContext.open(UMB_CHANGE_PASSWORD_MODAL, {
|
||||
userId: this._currentUser?.id ?? '',
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UmbLoggedInUser } from './types.js';
|
||||
import type { UmbCurrentUser } from './types.js';
|
||||
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
|
||||
export interface IUmbAuth {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export type { CurrentUserResponseModel as UmbLoggedInUser } from '@umbraco-cms/backoffice/backend-api';
|
||||
export type { CurrentUserResponseModel as UmbCurrentUser } from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
Reference in New Issue
Block a user