feat: Add user role select to users list settings page (#7796)

![CleanShot 2023-11-27 at 07 20
58](https://github.com/n8n-io/n8n/assets/5410822/40be0505-32ee-48a7-923e-ba6b4dbce670)
This commit is contained in:
Csaba Tuncsik
2023-11-27 13:38:03 +01:00
committed by GitHub
parent 5acb7b94c0
commit 137e23853f
9 changed files with 74 additions and 17 deletions

View File

@@ -15,6 +15,7 @@ import {
updateOtherUserSettings,
validatePasswordToken,
validateSignupToken,
updateRole,
} from '@/api/users';
import { PERSONALIZATION_MODAL_KEY, STORES } from '@/constants';
import type {
@@ -39,16 +40,13 @@ import { useCloudPlanStore } from './cloudPlan.store';
import { disableMfa, enableMfa, getMfaQR, verifyMfaToken } from '@/api/mfa';
import { confirmEmail, getCloudUserInfo } from '@/api/cloudPlans';
import { useRBACStore } from '@/stores/rbac.store';
import type { Scope } from '@n8n/permissions';
import type { Scope, ScopeLevel } from '@n8n/permissions';
import { inviteUsers, acceptInvitation } from '@/api/invitation';
const isDefaultUser = (user: IUserResponse | null) =>
Boolean(user && user.isPending && user.globalRole && user.globalRole.name === ROLE.Owner);
const isPendingUser = (user: IUserResponse | null) => Boolean(user && user.isPending);
const isInstanceOwner = (user: IUserResponse | null) =>
Boolean(user?.globalRole?.name === ROLE.Owner);
user?.isPending && user?.globalRole?.name === ROLE.Owner;
const isPendingUser = (user: IUserResponse | null) => !!user?.isPending;
const isInstanceOwner = (user: IUserResponse | null) => user?.globalRole?.name === ROLE.Owner;
export const useUsersStore = defineStore(STORES.USERS, {
state: (): IUsersState => ({
@@ -375,5 +373,11 @@ export const useUsersStore = defineStore(STORES.USERS, {
async confirmEmail() {
await confirmEmail(useRootStore().getRestApiContext);
},
async updateRole({ id, role }: { id: string; role: { scope: ScopeLevel; name: IRole } }) {
const rootStore = useRootStore();
await updateRole(rootStore.getRestApiContext, { id, role });
await this.fetchUsers();
},
},
});