refactor(editor): Migrate users.store to composition API (no-changelog) (#9960)

This commit is contained in:
Ricardo Espinoza
2024-07-08 10:21:03 -04:00
committed by GitHub
parent 4ff4534454
commit f40f9b0287
11 changed files with 407 additions and 370 deletions

View File

@@ -1376,13 +1376,6 @@ export interface IVersionsState {
currentVersion: IVersion | undefined; currentVersion: IVersion | undefined;
} }
export interface IUsersState {
initialized: boolean;
currentUserId: null | string;
users: { [userId: string]: IUser };
currentUserCloudInfo: Cloud.UserAccount | null;
}
export interface IWorkflowsState { export interface IWorkflowsState {
currentWorkflowExecutions: ExecutionSummary[]; currentWorkflowExecutions: ExecutionSummary[];
activeWorkflowExecution: ExecutionSummary | null; activeWorkflowExecution: ExecutionSummary | null;

View File

@@ -119,7 +119,7 @@ export default defineComponent({
...mapStores(useUsersStore, useProjectsStore), ...mapStores(useUsersStore, useProjectsStore),
userToDelete(): IUser | null { userToDelete(): IUser | null {
if (!this.activeId) return null; if (!this.activeId) return null;
return this.usersStore.getUserById(this.activeId); return this.usersStore.usersById[this.activeId];
}, },
isPending(): boolean { isPending(): boolean {
return this.userToDelete ? this.userToDelete && !this.userToDelete.firstName : false; return this.userToDelete ? this.userToDelete && !this.userToDelete.firstName : false;

View File

@@ -254,7 +254,7 @@ const onSetupClick = async () => {
const getMfaQR = async () => { const getMfaQR = async () => {
try { try {
const response = await userStore.getMfaQR(); const response = await userStore.fetchMfaQR();
qrCode.value = response.qrCode; qrCode.value = response.qrCode;
secret.value = response.secret; secret.value = response.secret;
recoveryCodes.value = response.recoveryCodes; recoveryCodes.value = response.recoveryCodes;

View File

@@ -69,7 +69,7 @@ const firstLicensedRole = computed(() => projectRoles.value.find((role) => role.
const onAddMember = (userId: string) => { const onAddMember = (userId: string) => {
isDirty.value = true; isDirty.value = true;
const user = usersStore.getUserById(userId); const user = usersStore.usersById[userId];
if (!user) return; if (!user) return;
const { id, firstName, lastName, email } = user; const { id, firstName, lastName, email } = user;

View File

@@ -23,7 +23,7 @@ const initialState = {
}, },
[STORES.USERS]: { [STORES.USERS]: {
currentUserId: 'aaa-bbb', currentUserId: 'aaa-bbb',
users: { usersById: {
'aaa-bbb': { 'aaa-bbb': {
id: 'aaa-bbb', id: 'aaa-bbb',
role: ROLE.Owner, role: ROLE.Owner,

View File

@@ -23,7 +23,7 @@ const pinia = createTestingPinia({
}, },
}, },
[STORES.USERS]: { [STORES.USERS]: {
users: { usersById: {
123: { 123: {
email: 'john@doe.com', email: 'john@doe.com',
firstName: 'John', firstName: 'John',

View File

@@ -23,9 +23,8 @@ describe('V1 Banner', () => {
}); });
it('should render banner with dismiss call if user is owner', () => { it('should render banner with dismiss call if user is owner', () => {
vi.spyOn(usersStore, 'currentUser', 'get').mockReturnValue({ usersStore.usersById = { '1': { role: ROLE.Owner } as IUser };
role: ROLE.Owner, usersStore.currentUserId = '1';
} as IUser);
const { container } = render(V1Banner); const { container } = render(V1Banner);
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();

View File

@@ -45,7 +45,7 @@ function setCurrentUser() {
function resetStores() { function resetStores() {
useSettingsStore().$reset(); useSettingsStore().$reset();
useUsersStore().$reset(); useUsersStore().reset();
} }
function setup() { function setup() {

View File

@@ -1,32 +1,11 @@
import type { IUpdateUserSettingsReqPayload, UpdateGlobalRolePayload } from '@/api/users'; import type { IUpdateUserSettingsReqPayload, UpdateGlobalRolePayload } from '@/api/users';
import { import * as usersApi from '@/api/users';
changePassword,
deleteUser,
getPasswordResetLink,
getUsers,
login,
loginCurrentUser,
logout,
sendForgotPasswordEmail,
setupOwner,
submitPersonalizationSurvey,
updateCurrentUser,
updateCurrentUserPassword,
updateCurrentUserSettings,
updateOtherUserSettings,
validatePasswordToken,
validateSignupToken,
updateGlobalRole,
} from '@/api/users';
import { PERSONALIZATION_MODAL_KEY, STORES, ROLE } from '@/constants'; import { PERSONALIZATION_MODAL_KEY, STORES, ROLE } from '@/constants';
import type { import type {
Cloud, Cloud,
IInviteResponse,
IPersonalizationLatestVersion, IPersonalizationLatestVersion,
IRole,
IUser, IUser,
IUserResponse, IUserResponse,
IUsersState,
CurrentUserResponse, CurrentUserResponse,
InvitableRoleName, InvitableRoleName,
} from '@/Interface'; } from '@/Interface';
@@ -37,51 +16,58 @@ import { usePostHog } from './posthog.store';
import { useSettingsStore } from './settings.store'; import { useSettingsStore } from './settings.store';
import { useUIStore } from './ui.store'; import { useUIStore } from './ui.store';
import { useCloudPlanStore } from './cloudPlan.store'; import { useCloudPlanStore } from './cloudPlan.store';
import { disableMfa, enableMfa, getMfaQR, verifyMfaToken } from '@/api/mfa'; import * as mfaApi from '@/api/mfa';
import { confirmEmail, getCloudUserInfo } from '@/api/cloudPlans'; import * as cloudApi from '@/api/cloudPlans';
import { useRBACStore } from '@/stores/rbac.store'; import { useRBACStore } from '@/stores/rbac.store';
import type { Scope } from '@n8n/permissions'; import type { Scope } from '@n8n/permissions';
import { inviteUsers, acceptInvitation } from '@/api/invitation'; import * as invitationsApi from '@/api/invitation';
import { useNpsSurveyStore } from './npsSurvey.store'; import { useNpsSurveyStore } from './npsSurvey.store';
import { computed, ref } from 'vue';
const isPendingUser = (user: IUserResponse | null) => !!user?.isPending; const _isPendingUser = (user: IUserResponse | null) => !!user?.isPending;
const isInstanceOwner = (user: IUserResponse | null) => user?.role === ROLE.Owner; const _isInstanceOwner = (user: IUserResponse | null) => user?.role === ROLE.Owner;
const isDefaultUser = (user: IUserResponse | null) => isInstanceOwner(user) && isPendingUser(user); const _isDefaultUser = (user: IUserResponse | null) =>
_isInstanceOwner(user) && _isPendingUser(user);
export const useUsersStore = defineStore(STORES.USERS, { export const useUsersStore = defineStore(STORES.USERS, () => {
state: (): IUsersState => ({ const initialized = ref(false);
initialized: false, const currentUserId = ref<string | null>(null);
currentUserId: null, const usersById = ref<Record<string, IUser>>({});
users: {}, const currentUserCloudInfo = ref<Cloud.UserAccount | null>(null);
currentUserCloudInfo: null,
}), // Stores
getters: {
allUsers(): IUser[] { const RBACStore = useRBACStore();
return Object.values(this.users); const npsSurveyStore = useNpsSurveyStore();
}, const uiStore = useUIStore();
userActivated(): boolean { const rootStore = useRootStore();
return Boolean(this.currentUser?.settings?.userActivated); const settingsStore = useSettingsStore();
}, const cloudPlanStore = useCloudPlanStore();
currentUser(): IUser | null {
return this.currentUserId ? this.users[this.currentUserId] : null; // Composables
},
isDefaultUser(): boolean { const postHogStore = usePostHog();
return isDefaultUser(this.currentUser);
}, // Computed
isInstanceOwner(): boolean {
return isInstanceOwner(this.currentUser); const allUsers = computed(() => Object.values(usersById.value));
},
mfaEnabled(): boolean { const currentUser = computed(() =>
return this.currentUser?.mfaEnabled ?? false; currentUserId.value ? usersById.value[currentUserId.value] : null,
}, );
getUserById(state) {
return (userId: string): IUser | null => state.users[userId]; const userActivated = computed(() => Boolean(currentUser.value?.settings?.userActivated));
},
globalRoleName(): IRole { const isDefaultUser = computed(() => _isDefaultUser(currentUser.value));
return this.currentUser?.role ?? 'default';
}, const isInstanceOwner = computed(() => _isInstanceOwner(currentUser.value));
personalizedNodeTypes(): string[] {
const user = this.currentUser; const mfaEnabled = computed(() => currentUser.value?.mfaEnabled ?? false);
const globalRoleName = computed(() => currentUser.value?.role ?? 'default');
const personalizedNodeTypes = computed(() => {
const user = currentUser.value;
if (!user) { if (!user) {
return []; return [];
} }
@@ -91,36 +77,13 @@ export const useUsersStore = defineStore(STORES.USERS, {
return []; return [];
} }
return getPersonalizedNodeTypes(answers); return getPersonalizedNodeTypes(answers);
}, });
},
actions: {
async initialize() {
if (this.initialized) {
return;
}
try { // Methods
await this.loginWithCookie();
this.initialized = true;
} catch (e) {}
},
setCurrentUser(user: CurrentUserResponse) {
this.addUsers([user]);
this.currentUserId = user.id;
const defaultScopes: Scope[] = []; const addUsers = (newUsers: IUserResponse[]) => {
useRBACStore().setGlobalScopes(user.globalScopes || defaultScopes); newUsers.forEach((userResponse: IUserResponse) => {
usePostHog().init(user.featureFlags); const prevUser = usersById.value[userResponse.id] || {};
useNpsSurveyStore().setupNpsSurveyOnLogin(user.id, user.settings);
},
unsetCurrentUser() {
this.currentUserId = null;
this.currentUserCloudInfo = null;
useRBACStore().setGlobalScopes([]);
},
addUsers(users: IUserResponse[]) {
users.forEach((userResponse: IUserResponse) => {
const prevUser = this.users[userResponse.id] || {};
const updatedUser = { const updatedUser = {
...prevUser, ...prevUser,
...userResponse, ...userResponse,
@@ -130,251 +93,333 @@ export const useUsersStore = defineStore(STORES.USERS, {
fullName: userResponse.firstName fullName: userResponse.firstName
? `${updatedUser.firstName} ${updatedUser.lastName || ''}` ? `${updatedUser.firstName} ${updatedUser.lastName || ''}`
: undefined, : undefined,
isDefaultUser: isDefaultUser(updatedUser), isDefaultUser: _isDefaultUser(updatedUser),
isPendingUser: isPendingUser(updatedUser), isPendingUser: _isPendingUser(updatedUser),
}; };
this.users = { usersById.value = {
...this.users, ...usersById.value,
[user.id]: user, [user.id]: user,
}; };
}); });
},
deleteUserById(userId: string): void {
const { [userId]: _, ...users } = this.users;
this.users = users;
},
setPersonalizationAnswers(answers: IPersonalizationLatestVersion): void {
if (!this.currentUser) {
return;
}
this.users = {
...this.users,
[this.currentUser.id]: {
...this.currentUser,
personalizationAnswers: answers,
},
}; };
},
async loginWithCookie(): Promise<void> { const setCurrentUser = (user: CurrentUserResponse) => {
const rootStore = useRootStore(); addUsers([user]);
const user = await loginCurrentUser(rootStore.restApiContext); currentUserId.value = user.id;
const defaultScopes: Scope[] = [];
RBACStore.setGlobalScopes(user.globalScopes || defaultScopes);
postHogStore.init(user.featureFlags);
npsSurveyStore.setupNpsSurveyOnLogin(user.id, user.settings);
};
const loginWithCookie = async () => {
const user = await usersApi.loginCurrentUser(rootStore.restApiContext);
if (!user) { if (!user) {
return; return;
} }
this.setCurrentUser(user); setCurrentUser(user);
};
const initialize = async () => {
if (initialized.value) {
return;
}
try {
await loginWithCookie();
initialized.value = true;
} catch (e) {}
};
const unsetCurrentUser = () => {
currentUserId.value = null;
currentUserCloudInfo.value = null;
RBACStore.setGlobalScopes([]);
};
const deleteUserById = (userId: string) => {
const { [userId]: _, ...rest } = usersById.value;
usersById.value = rest;
};
const setPersonalizationAnswers = (answers: IPersonalizationLatestVersion) => {
if (!currentUser.value) {
return;
}
usersById.value = {
...usersById.value,
[currentUser.value.id]: {
...currentUser.value,
personalizationAnswers: answers,
}, },
async loginWithCreds(params: { };
};
const loginWithCreds = async (params: {
email: string; email: string;
password: string; password: string;
mfaToken?: string; mfaToken?: string;
mfaRecoveryCode?: string; mfaRecoveryCode?: string;
}): Promise<void> { }) => {
const rootStore = useRootStore(); const user = await usersApi.login(rootStore.restApiContext, params);
const user = await login(rootStore.restApiContext, params);
if (!user) { if (!user) {
return; return;
} }
this.setCurrentUser(user); setCurrentUser(user);
}, };
async logout(): Promise<void> {
const rootStore = useRootStore(); const logout = async () => {
await logout(rootStore.restApiContext); await usersApi.logout(rootStore.restApiContext);
this.unsetCurrentUser(); unsetCurrentUser();
useCloudPlanStore().reset(); cloudPlanStore.reset();
usePostHog().reset(); postHogStore.reset();
useUIStore().clearBannerStack(); uiStore.clearBannerStack();
useNpsSurveyStore().resetNpsSurveyOnLogOut(); npsSurveyStore.resetNpsSurveyOnLogOut();
}, };
async createOwner(params: {
const createOwner = async (params: {
firstName: string; firstName: string;
lastName: string; lastName: string;
email: string; email: string;
password: string; password: string;
}): Promise<void> { }) => {
const rootStore = useRootStore(); const user = await usersApi.setupOwner(rootStore.restApiContext, params);
const user = await setupOwner(rootStore.restApiContext, params);
const settingsStore = useSettingsStore();
if (user) { if (user) {
this.setCurrentUser(user); setCurrentUser(user);
settingsStore.stopShowingSetupPage(); settingsStore.stopShowingSetupPage();
} }
}, };
async validateSignupToken(params: {
inviteeId: string; const validateSignupToken = async (params: { inviteeId: string; inviterId: string }) => {
inviterId: string; return await usersApi.validateSignupToken(rootStore.restApiContext, params);
}): Promise<{ inviter: { firstName: string; lastName: string } }> { };
const rootStore = useRootStore();
return await validateSignupToken(rootStore.restApiContext, params); const acceptInvitation = async (params: {
},
async acceptInvitation(params: {
inviteeId: string; inviteeId: string;
inviterId: string; inviterId: string;
firstName: string; firstName: string;
lastName: string; lastName: string;
password: string; password: string;
}): Promise<void> { }) => {
const rootStore = useRootStore(); const user = await invitationsApi.acceptInvitation(rootStore.restApiContext, params);
const user = await acceptInvitation(rootStore.restApiContext, params);
if (user) { if (user) {
this.setCurrentUser(user); setCurrentUser(user);
} }
}, };
async sendForgotPasswordEmail(params: { email: string }): Promise<void> {
const rootStore = useRootStore(); const sendForgotPasswordEmail = async (params: { email: string }) => {
await sendForgotPasswordEmail(rootStore.restApiContext, params); await usersApi.sendForgotPasswordEmail(rootStore.restApiContext, params);
}, };
async validatePasswordToken(params: { token: string }): Promise<void> {
const rootStore = useRootStore(); const validatePasswordToken = async (params: { token: string }) => {
await validatePasswordToken(rootStore.restApiContext, params); await usersApi.validatePasswordToken(rootStore.restApiContext, params);
}, };
async changePassword(params: {
token: string; const changePassword = async (params: { token: string; password: string; mfaToken?: string }) => {
password: string; await usersApi.changePassword(rootStore.restApiContext, params);
mfaToken?: string; };
}): Promise<void> {
const rootStore = useRootStore(); const updateUser = async (params: {
await changePassword(rootStore.restApiContext, params);
},
async updateUser(params: {
id: string; id: string;
firstName: string; firstName: string;
lastName: string; lastName: string;
email: string; email: string;
}): Promise<void> { }) => {
const rootStore = useRootStore(); const user = await usersApi.updateCurrentUser(rootStore.restApiContext, params);
const user = await updateCurrentUser(rootStore.restApiContext, params); addUsers([user]);
this.addUsers([user]); };
},
async updateUserSettings(settings: IUpdateUserSettingsReqPayload): Promise<void> { const updateUserSettings = async (settings: IUpdateUserSettingsReqPayload) => {
const rootStore = useRootStore(); const updatedSettings = await usersApi.updateCurrentUserSettings(
const updatedSettings = await updateCurrentUserSettings(rootStore.restApiContext, settings); rootStore.restApiContext,
if (this.currentUser) { settings,
this.currentUser.settings = updatedSettings; );
this.addUsers([this.currentUser]); if (currentUser.value) {
currentUser.value.settings = updatedSettings;
addUsers([currentUser.value]);
} }
}, };
async updateOtherUserSettings(
const updateOtherUserSettings = async (
userId: string, userId: string,
settings: IUpdateUserSettingsReqPayload, settings: IUpdateUserSettingsReqPayload,
): Promise<void> { ) => {
const rootStore = useRootStore(); const updatedSettings = await usersApi.updateOtherUserSettings(
const updatedSettings = await updateOtherUserSettings(
rootStore.restApiContext, rootStore.restApiContext,
userId, userId,
settings, settings,
); );
this.users[userId].settings = updatedSettings; usersById.value[userId].settings = updatedSettings;
this.addUsers([this.users[userId]]); addUsers([usersById.value[userId]]);
}, };
async updateCurrentUserPassword({
const updateCurrentUserPassword = async ({
password, password,
currentPassword, currentPassword,
}: { }: {
password: string; password: string;
currentPassword: string; currentPassword: string;
}): Promise<void> { }) => {
const rootStore = useRootStore(); await usersApi.updateCurrentUserPassword(rootStore.restApiContext, {
await updateCurrentUserPassword(rootStore.restApiContext, {
newPassword: password, newPassword: password,
currentPassword, currentPassword,
}); });
}, };
async deleteUser(params: { id: string; transferId?: string }): Promise<void> {
const rootStore = useRootStore(); const deleteUser = async (params: { id: string; transferId?: string }) => {
await deleteUser(rootStore.restApiContext, params); await usersApi.deleteUser(rootStore.restApiContext, params);
this.deleteUserById(params.id); deleteUserById(params.id);
}, };
async fetchUsers(): Promise<void> {
const rootStore = useRootStore(); const fetchUsers = async () => {
const users = await getUsers(rootStore.restApiContext); const users = await usersApi.getUsers(rootStore.restApiContext);
this.addUsers(users); addUsers(users);
}, };
async inviteUsers(
params: Array<{ email: string; role: InvitableRoleName }>, const inviteUsers = async (params: Array<{ email: string; role: InvitableRoleName }>) => {
): Promise<IInviteResponse[]> { const invitedUsers = await invitationsApi.inviteUsers(rootStore.restApiContext, params);
const rootStore = useRootStore(); addUsers(
const users = await inviteUsers(rootStore.restApiContext, params); invitedUsers.map(({ user }, index) => ({
this.addUsers(
users.map(({ user }, index) => ({
isPending: true, isPending: true,
globalRole: { name: params[index].role }, globalRole: { name: params[index].role },
...user, ...user,
})), })),
); );
return users; return invitedUsers;
}, };
async reinviteUser({ email, role }: { email: string; role: InvitableRoleName }): Promise<void> {
const rootStore = useRootStore(); const reinviteUser = async ({ email, role }: { email: string; role: InvitableRoleName }) => {
const invitationResponse = await inviteUsers(rootStore.restApiContext, [{ email, role }]); const invitationResponse = await invitationsApi.inviteUsers(rootStore.restApiContext, [
{ email, role },
]);
if (!invitationResponse[0].user.emailSent) { if (!invitationResponse[0].user.emailSent) {
throw Error(invitationResponse[0].error); throw Error(invitationResponse[0].error);
} }
}, };
async getUserPasswordResetLink(params: { id: string }): Promise<{ link: string }> {
const rootStore = useRootStore(); const getUserPasswordResetLink = async (params: { id: string }) => {
return await getPasswordResetLink(rootStore.restApiContext, params); return await usersApi.getPasswordResetLink(rootStore.restApiContext, params);
}, };
async submitPersonalizationSurvey(results: IPersonalizationLatestVersion): Promise<void> {
const rootStore = useRootStore(); const submitPersonalizationSurvey = async (results: IPersonalizationLatestVersion) => {
await submitPersonalizationSurvey(rootStore.restApiContext, results); await usersApi.submitPersonalizationSurvey(rootStore.restApiContext, results);
this.setPersonalizationAnswers(results); setPersonalizationAnswers(results);
}, };
async showPersonalizationSurvey(): Promise<void> {
const settingsStore = useSettingsStore(); const showPersonalizationSurvey = async () => {
const surveyEnabled = settingsStore.isPersonalizationSurveyEnabled; const surveyEnabled = settingsStore.isPersonalizationSurveyEnabled;
const currentUser = this.currentUser; if (surveyEnabled && currentUser.value && !currentUser.value.personalizationAnswers) {
if (surveyEnabled && currentUser && !currentUser.personalizationAnswers) {
const uiStore = useUIStore();
uiStore.openModal(PERSONALIZATION_MODAL_KEY); uiStore.openModal(PERSONALIZATION_MODAL_KEY);
} }
}, };
async getMfaQR(): Promise<{ qrCode: string; secret: string; recoveryCodes: string[] }> {
const rootStore = useRootStore(); const fetchMfaQR = async () => {
return await getMfaQR(rootStore.restApiContext); return await mfaApi.getMfaQR(rootStore.restApiContext);
}, };
async verifyMfaToken(data: { token: string }): Promise<void> {
const rootStore = useRootStore(); const verifyMfaToken = async (data: { token: string }) => {
return await verifyMfaToken(rootStore.restApiContext, data); return await mfaApi.verifyMfaToken(rootStore.restApiContext, data);
}, };
async enableMfa(data: { token: string }) {
const rootStore = useRootStore(); const enableMfa = async (data: { token: string }) => {
const usersStore = useUsersStore(); await mfaApi.enableMfa(rootStore.restApiContext, data);
await enableMfa(rootStore.restApiContext, data); if (currentUser.value) {
const currentUser = usersStore.currentUser; currentUser.value.mfaEnabled = true;
if (currentUser) {
currentUser.mfaEnabled = true;
} }
}, };
async disabledMfa() {
const rootStore = useRootStore(); const disableMfa = async () => {
const usersStore = useUsersStore(); await mfaApi.disableMfa(rootStore.restApiContext);
await disableMfa(rootStore.restApiContext); if (currentUser.value) {
const currentUser = usersStore.currentUser; currentUser.value.mfaEnabled = false;
if (currentUser) {
currentUser.mfaEnabled = false;
} }
}, };
async fetchUserCloudAccount() {
const disabledMfa = async () => {
await mfaApi.disableMfa(rootStore.restApiContext);
if (currentUser.value) {
currentUser.value.mfaEnabled = false;
}
};
const fetchUserCloudAccount = async () => {
let cloudUser: Cloud.UserAccount | null = null; let cloudUser: Cloud.UserAccount | null = null;
try { try {
cloudUser = await getCloudUserInfo(useRootStore().restApiContext); cloudUser = await cloudApi.getCloudUserInfo(rootStore.restApiContext);
this.currentUserCloudInfo = cloudUser; currentUserCloudInfo.value = cloudUser;
} catch (error) { } catch (error) {
throw new Error(error); throw new Error(error);
} }
}, };
async confirmEmail() {
await confirmEmail(useRootStore().restApiContext);
},
async updateGlobalRole({ id, newRoleName }: UpdateGlobalRolePayload) { const confirmEmail = async () => {
const rootStore = useRootStore(); await cloudApi.confirmEmail(rootStore.restApiContext);
await updateGlobalRole(rootStore.restApiContext, { id, newRoleName }); };
await this.fetchUsers();
}, const updateGlobalRole = async ({ id, newRoleName }: UpdateGlobalRolePayload) => {
}, await usersApi.updateGlobalRole(rootStore.restApiContext, { id, newRoleName });
await fetchUsers();
};
const reset = () => {
initialized.value = false;
currentUserId.value = null;
usersById.value = {};
currentUserCloudInfo.value = null;
};
return {
initialized,
currentUserId,
usersById,
currentUserCloudInfo,
allUsers,
currentUser,
userActivated,
isDefaultUser,
isInstanceOwner,
mfaEnabled,
globalRoleName,
personalizedNodeTypes,
addUsers,
setCurrentUser,
loginWithCookie,
initialize,
unsetCurrentUser,
deleteUserById,
setPersonalizationAnswers,
loginWithCreds,
logout,
createOwner,
validateSignupToken,
acceptInvitation,
sendForgotPasswordEmail,
validatePasswordToken,
changePassword,
updateUser,
updateUserSettings,
updateOtherUserSettings,
updateCurrentUserPassword,
deleteUser,
fetchUsers,
inviteUsers,
reinviteUser,
getUserPasswordResetLink,
submitPersonalizationSurvey,
showPersonalizationSurvey,
fetchMfaQR,
verifyMfaToken,
enableMfa,
disableMfa,
fetchUserCloudAccount,
confirmEmail,
updateGlobalRole,
disabledMfa,
reset,
};
}); });

View File

@@ -216,13 +216,13 @@ export default defineComponent({
this.uiStore.openModal(INVITE_USER_MODAL_KEY); this.uiStore.openModal(INVITE_USER_MODAL_KEY);
}, },
async onDelete(userId: string) { async onDelete(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user) { if (user) {
this.uiStore.openDeleteUserModal(userId); this.uiStore.openDeleteUserModal(userId);
} }
}, },
async onReinvite(userId: string) { async onReinvite(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user?.email && user?.role) { if (user?.email && user?.role) {
if (!['global:admin', 'global:member'].includes(user.role)) { if (!['global:admin', 'global:member'].includes(user.role)) {
throw new Error('Invalid role name on reinvite'); throw new Error('Invalid role name on reinvite');
@@ -245,7 +245,7 @@ export default defineComponent({
} }
}, },
async onCopyInviteLink(userId: string) { async onCopyInviteLink(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user?.inviteAcceptUrl) { if (user?.inviteAcceptUrl) {
void this.clipboard.copy(user.inviteAcceptUrl); void this.clipboard.copy(user.inviteAcceptUrl);
@@ -257,7 +257,7 @@ export default defineComponent({
} }
}, },
async onCopyPasswordResetLink(userId: string) { async onCopyPasswordResetLink(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user) { if (user) {
const url = await this.usersStore.getUserPasswordResetLink(user); const url = await this.usersStore.getUserPasswordResetLink(user);
void this.clipboard.copy(url.link); void this.clipboard.copy(url.link);
@@ -270,7 +270,7 @@ export default defineComponent({
} }
}, },
async onAllowSSOManualLogin(userId: string) { async onAllowSSOManualLogin(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user) { if (user) {
if (!user.settings) { if (!user.settings) {
user.settings = {}; user.settings = {};
@@ -286,7 +286,7 @@ export default defineComponent({
} }
}, },
async onDisallowSSOManualLogin(userId: string) { async onDisallowSSOManualLogin(userId: string) {
const user = this.usersStore.getUserById(userId); const user = this.usersStore.usersById[userId];
if (user?.settings) { if (user?.settings) {
user.settings.allowSSOManualLogin = false; user.settings.allowSSOManualLogin = false;
await this.usersStore.updateOtherUserSettings(userId, user.settings); await this.usersStore.updateOtherUserSettings(userId, user.settings);

View File

@@ -41,7 +41,7 @@ describe('SettingsPersonalView', () => {
usersStore = useUsersStore(pinia); usersStore = useUsersStore(pinia);
uiStore = useUIStore(pinia); uiStore = useUIStore(pinia);
usersStore.users[currentUser.id] = currentUser; usersStore.usersById[currentUser.id] = currentUser;
usersStore.currentUserId = currentUser.id; usersStore.currentUserId = currentUser.id;
await settingsStore.getSettings(); await settingsStore.getSettings();