Skip to content

Commit

Permalink
Maintenance: Move account location to user current for better context.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikklein committed May 3, 2024
1 parent e42f4d9 commit 1b552ce
Show file tree
Hide file tree
Showing 229 changed files with 9,702 additions and 9,651 deletions.
Expand Up @@ -11,8 +11,8 @@ import { useCopyToClipboard } from '#desktop/composables/useCopyToClipboard.ts'
import { useForm } from '#shared/components/Form/useForm.ts'
import QueryHandler from '#shared/server/apollo/handler/QueryHandler.ts'
import MutationHandler from '#shared/server/apollo/handler/MutationHandler.ts'
import { useAccountTwoFactorVerifyMethodConfigurationMutation } from '#shared/entities/account/graphql/mutations/accountTwoFactorVerifyMethodConfiguration.api.ts'
import { useAccountTwoFactorInitiateMethodConfigurationQuery } from '#shared/entities/account/graphql/queries/accountTwoFactorInitiateMethodConfiguration.api.ts'
import { useUserCurrentTwoFactorVerifyMethodConfigurationMutation } from '#shared/entities/user/current/graphql/mutations/two-factor/userCurrentTwoFactorVerifyMethodConfiguration.api.ts'
import { useUserCurrentTwoFactorInitiateMethodConfigurationQuery } from '#shared/entities/user/current/graphql/queries/two-factor/userCurrentTwoFactorInitiateMethodConfiguration.api.ts'
import UserError from '#shared/errors/UserError.ts'
import type { FormSubmitData } from '#shared/components/Form/types.ts'
Expand All @@ -30,7 +30,7 @@ const twoFactorPlugin = twoFactorMethodLookup[props.type]
const headerIcon = computed(() => twoFactorPlugin.icon)
const initiationQuery = new QueryHandler(
useAccountTwoFactorInitiateMethodConfigurationQuery(
useUserCurrentTwoFactorInitiateMethodConfigurationQuery(
{
methodName: twoFactorPlugin.name,
},
Expand All @@ -52,15 +52,16 @@ const initiationError = ref<string | null>(null)
const { form, formSetErrors } = useForm()
const mutateMethodConfiguration = new MutationHandler(
useAccountTwoFactorVerifyMethodConfigurationMutation(),
useUserCurrentTwoFactorVerifyMethodConfigurationMutation(),
)
const verifyMethodConfiguration = async (securityCode: string) => {
return mutateMethodConfiguration.send({
methodName: twoFactorPlugin.name,
payload: securityCode,
configuration: {
...initiationResult.value?.accountTwoFactorInitiateMethodConfiguration,
...initiationResult.value
?.userCurrentTwoFactorInitiateMethodConfiguration,
},
})
}
Expand All @@ -78,12 +79,15 @@ const submitForm = async ({
message: __('Two-factor method has been configured successfully.'),
})
if (response?.accountTwoFactorVerifyMethodConfiguration?.recoveryCodes) {
if (
response?.userCurrentTwoFactorVerifyMethodConfiguration?.recoveryCodes
) {
props.formSubmitCallback?.({
nextState: 'recovery_codes',
options: {
recoveryCodes:
response?.accountTwoFactorVerifyMethodConfiguration?.recoveryCodes,
response?.userCurrentTwoFactorVerifyMethodConfiguration
?.recoveryCodes,
headerIcon: headerIcon.value,
},
})
Expand Down Expand Up @@ -150,11 +154,11 @@ const setupQrCode = async (provisioningUri: string, secret: string) => {
}
initiationQuery.onResult(({ data }) => {
if (data?.accountTwoFactorInitiateMethodConfiguration) {
if (data?.userCurrentTwoFactorInitiateMethodConfiguration) {
// eslint-disable-next-line camelcase
const { provisioning_uri, secret } =
// eslint-disable-next-line no-unsafe-optional-chaining
data?.accountTwoFactorInitiateMethodConfiguration
data?.userCurrentTwoFactorInitiateMethodConfiguration
setupQrCode(provisioning_uri, secret)
.catch(() => {
Expand Down
Expand Up @@ -7,7 +7,7 @@ import type { FormSubmitData } from '#shared/components/Form/types.ts'
import { useForm } from '#shared/components/Form/useForm.ts'
import { defineFormSchema } from '#shared/form/defineFormSchema.ts'
import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
import { useAccountPasswordCheckMutation } from '#desktop/entities/account/graphql/mutations/accountPasswordCheck.api.ts'
import { useUserCurrentPasswordCheckMutation } from '#desktop/entities/user/current/graphql/mutations/userCurrentPasswordCheck.api.ts'
import { useTwoFactorPlugins } from '#shared/entities/two-factor/composables/useTwoFactorPlugins.ts'
import type { TwoFactorConfigurationComponentProps } from '../types.ts'
Expand All @@ -29,7 +29,7 @@ const schema = defineFormSchema([
])
const passwordCheckMutation = new MutationHandler(
useAccountPasswordCheckMutation(),
useUserCurrentPasswordCheckMutation(),
{
errorNotificationMessage: __('Password could not be checked'),
},
Expand Down
Expand Up @@ -2,13 +2,14 @@

<script setup lang="ts">
import { computed, onBeforeMount, ref } from 'vue'
import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
import UserError from '#shared/errors/UserError.ts'
import { useUserCurrentTwoFactorRecoveryCodesGenerateMutation } from '#shared/entities/user/current/graphql/mutations/two-factor/userCurrentTwoFactorRecoveryCodesGenerate.api.ts'
import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
import CommonLoader from '#desktop/components/CommonLoader/CommonLoader.vue'
import { usePrintMode } from '#desktop/composables/usePrintMode.ts'
import { useCopyToClipboard } from '#desktop/composables/useCopyToClipboard.ts'
import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
import { useAccountTwoFactorRecoveryCodesGenerateMutation } from '#shared/entities/account/graphql/mutations/accountTwoFactorRecoveryCodesGenerate.api.ts'
import UserError from '#shared/errors/UserError.ts'
import type { TwoFactorConfigurationComponentProps } from '../types.ts'
const props = defineProps<TwoFactorConfigurationComponentProps>()
Expand All @@ -29,7 +30,7 @@ onBeforeMount(async () => {
loading.value = true
const recoveryCodesGenerate = new MutationHandler(
useAccountTwoFactorRecoveryCodesGenerateMutation(),
useUserCurrentTwoFactorRecoveryCodesGenerateMutation(),
{
errorNotificationMessage: __('Could not generate recovery codes'),
},
Expand All @@ -39,7 +40,7 @@ onBeforeMount(async () => {
.send()
.then((data) => {
recoveryCodes.value =
data?.accountTwoFactorRecoveryCodesGenerate?.recoveryCodes
data?.userCurrentTwoFactorRecoveryCodesGenerate?.recoveryCodes
})
.catch((err) => {
if (err instanceof UserError) {
Expand Down
Expand Up @@ -13,10 +13,10 @@ import {
MutationHandler,
QueryHandler,
} from '#shared/server/apollo/handler/index.ts'
import { useAccountTwoFactorGetMethodConfigurationQuery } from '#shared/entities/account/graphql/mutations/accountTwoFactorGetMethodConfiguration.api.ts'
import { useAccountTwoFactorInitiateMethodConfigurationLazyQuery } from '#shared/entities/account/graphql/queries/accountTwoFactorInitiateMethodConfiguration.api.ts'
import { useAccountTwoFactorVerifyMethodConfigurationMutation } from '#shared/entities/account/graphql/mutations/accountTwoFactorVerifyMethodConfiguration.api.ts'
import { useAccountTwoFactorRemoveMethodCredentialsMutation } from '#shared/entities/account/graphql/mutations/accountTwoFactorRemoveMethodCredentials.api.ts'
import { useUserCurrentTwoFactorGetMethodConfigurationQuery } from '#shared/entities/user/current/graphql/mutations/two-factor/userCurrentTwoFactorGetMethodConfiguration.api.ts'
import { useUserCurrentTwoFactorInitiateMethodConfigurationLazyQuery } from '#shared/entities/user/current/graphql/queries/two-factor/userCurrentTwoFactorInitiateMethodConfiguration.api.ts'
import { useUserCurrentTwoFactorVerifyMethodConfigurationMutation } from '#shared/entities/user/current/graphql/mutations/two-factor/userCurrentTwoFactorVerifyMethodConfiguration.api.ts'
import { useUserCurrentTwoFactorRemoveMethodCredentialsMutation } from '#shared/entities/user/current/graphql/mutations/two-factor/userCurrentTwoFactorRemoveMethodCredentials.api.ts'
import { useNotifications } from '#shared/components/CommonNotifications/useNotifications.ts'
import { NotificationTypes } from '#shared/components/CommonNotifications/types.ts'
import type { ObjectLike } from '#shared/types/utils.ts'
Expand Down Expand Up @@ -73,7 +73,7 @@ const footerActionOptions = computed(() => {
})
const configurationQuery = new QueryHandler(
useAccountTwoFactorGetMethodConfigurationQuery({
useUserCurrentTwoFactorGetMethodConfigurationQuery({
methodName: twoFactorPlugin.name,
}),
{
Expand All @@ -83,7 +83,8 @@ const configurationQuery = new QueryHandler(
const configuration = computed<ObjectLike>(
() =>
configurationQuery.result().value?.accountTwoFactorGetMethodConfiguration,
configurationQuery.result().value
?.userCurrentTwoFactorGetMethodConfiguration,
)
const credentials = computed<ObjectLike[]>(
Expand Down Expand Up @@ -113,7 +114,7 @@ const tableItems = computed(() =>
const { notify } = useNotifications()
const removeCredentialsMutation = new MutationHandler(
useAccountTwoFactorRemoveMethodCredentialsMutation(),
useUserCurrentTwoFactorRemoveMethodCredentialsMutation(),
{
errorNotificationMessage: __(
'Could not remove two-factor authentication method.',
Expand All @@ -136,7 +137,7 @@ const tableActions: MenuItem[] = [
})
if (
!removeCredentialsResult?.accountTwoFactorRemoveMethodCredentials
!removeCredentialsResult?.userCurrentTwoFactorRemoveMethodCredentials
?.success
)
return
Expand All @@ -159,7 +160,7 @@ const loading = ref(false)
const error = ref<string | null>(null)
const initiateQuery = new QueryHandler(
useAccountTwoFactorInitiateMethodConfigurationLazyQuery(
useUserCurrentTwoFactorInitiateMethodConfigurationLazyQuery(
{
methodName: twoFactorPlugin.name,
},
Expand All @@ -177,7 +178,7 @@ const setupCredential = async () => {
})
const initiateData =
initiateQueryResult.data?.accountTwoFactorInitiateMethodConfiguration
initiateQueryResult.data?.userCurrentTwoFactorInitiateMethodConfiguration
if (!initiateData)
throw new Error(
Expand All @@ -192,7 +193,7 @@ const setupCredential = async () => {
}
const verifyMutation = new MutationHandler(
useAccountTwoFactorVerifyMethodConfigurationMutation(),
useUserCurrentTwoFactorVerifyMethodConfigurationMutation(),
)
const verifyCredential = async (
Expand All @@ -209,7 +210,7 @@ const verifyCredential = async (
type: 'registration',
},
})
)?.accountTwoFactorVerifyMethodConfiguration
)?.userCurrentTwoFactorVerifyMethodConfiguration
return verifyResult
}
Expand Down
@@ -1,7 +1,7 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

import '#tests/graphql/builders/mocks.ts'
import { mockAccount } from '#tests/support/mock-account.ts'
import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
import { renderComponent } from '#tests/support/components/index.ts'

import { EnumAppearanceTheme } from '#shared/graphql/types.ts'
Expand All @@ -11,7 +11,7 @@ import AvatarMenuAppearanceItem from '../AvatarMenuAppearanceItem.vue'

describe('avatar menu apperance item', () => {
beforeEach(() => {
mockAccount({
mockUserCurrent({
lastname: 'Doe',
firstname: 'John',
preferences: {},
Expand Down
@@ -1,12 +1,12 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

import { renderComponent } from '#tests/support/components/index.ts'
import { mockAccount } from '#tests/support/mock-account.ts'
import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
import LayoutSidebarFooterMenu from '../LayoutSidebarFooterMenu.vue'

describe('layout sidebar footer menu', () => {
beforeEach(() => {
mockAccount({
mockUserCurrent({
lastname: 'Doe',
firstname: 'John',
})
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,22 @@
import * as Types from '#shared/graphql/types.ts';

import gql from 'graphql-tag';
import { ErrorsFragmentDoc } from '../../../../../../../shared/graphql/fragments/errors.api';
import * as VueApolloComposable from '@vue/apollo-composable';
import * as VueCompositionApi from 'vue';
export type ReactiveFunction<TParam> = () => TParam;

export const UserCurrentPasswordCheckDocument = gql`
mutation userCurrentPasswordCheck($password: String!) {
userCurrentPasswordCheck(password: $password) {
success
errors {
...errors
}
}
}
${ErrorsFragmentDoc}`;
export function useUserCurrentPasswordCheckMutation(options: VueApolloComposable.UseMutationOptions<Types.UserCurrentPasswordCheckMutation, Types.UserCurrentPasswordCheckMutationVariables> | ReactiveFunction<VueApolloComposable.UseMutationOptions<Types.UserCurrentPasswordCheckMutation, Types.UserCurrentPasswordCheckMutationVariables>> = {}) {
return VueApolloComposable.useMutation<Types.UserCurrentPasswordCheckMutation, Types.UserCurrentPasswordCheckMutationVariables>(UserCurrentPasswordCheckDocument, options);
}
export type UserCurrentPasswordCheckMutationCompositionFunctionResult = VueApolloComposable.UseMutationReturn<Types.UserCurrentPasswordCheckMutation, Types.UserCurrentPasswordCheckMutationVariables>;
@@ -0,0 +1,8 @@
mutation userCurrentPasswordCheck($password: String!) {
userCurrentPasswordCheck(password: $password) {
success
errors {
...errors
}
}
}
@@ -0,0 +1,12 @@
import * as Types from '#shared/graphql/types.ts';

import * as Mocks from '#tests/graphql/builders/mocks.ts'
import * as Operations from './userCurrentPasswordCheck.api.ts'

export function mockUserCurrentPasswordCheckMutation(defaults: Mocks.MockDefaultsValue<Types.UserCurrentPasswordCheckMutation, Types.UserCurrentPasswordCheckMutationVariables>) {
return Mocks.mockGraphQLResult(Operations.UserCurrentPasswordCheckDocument, defaults)
}

export function waitForUserCurrentPasswordCheckMutationCalls() {
return Mocks.waitForGraphQLMockCalls<Types.UserCurrentPasswordCheckMutation>(Operations.UserCurrentPasswordCheckDocument)
}
Expand Up @@ -7,12 +7,12 @@ import {
getByRole,
} from '@testing-library/vue'
import { visitView } from '#tests/support/components/visitView.ts'
import { mockAccount } from '#tests/support/mock-account.ts'
import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
import { mockLogoutMutation } from '#shared/graphql/mutations/logout.mocks.ts'

describe('Left sidebar', () => {
beforeEach(() => {
mockAccount({
mockUserCurrent({
id: 'gid://zammad/User/999',
firstname: 'Nicole',
lastname: 'Braun',
Expand Down
Expand Up @@ -72,11 +72,11 @@ describe('guided setup admin user creation', () => {
await view.events.type(passwordField, 'planetexpress')
await view.events.type(confirmPasswordField, 'planetexpress')

const createAccountButton = view.getByRole('button', {
const createUserCurrentButton = view.getByRole('button', {
name: 'Create account',
})

await view.events.click(createAccountButton)
await view.events.click(createUserCurrentButton)

await vi.waitFor(() => {
expect(
Expand Down
@@ -1,7 +1,7 @@
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

import { visitView } from '#tests/support/components/visitView.ts'
import { waitForAccountAppearanceMutationCalls } from '../graphql/mutations/accountAppearance.mocks.ts'
import { waitForUserCurrentAppearanceMutationCalls } from '../graphql/mutations/userCurrentAppearance.mocks.ts'

describe('appearance page', () => {
it('update appearance to dark', async () => {
Expand All @@ -13,7 +13,7 @@ describe('appearance page', () => {

await view.events.click(darkMode)
expect(view.getByLabelText('Dark')).toBeChecked()
const calls = await waitForAccountAppearanceMutationCalls()
const calls = await waitForUserCurrentAppearanceMutationCalls()
expect(calls.at(-1)?.variables).toEqual({ theme: 'dark' })
expect(window.matchMedia('(prefers-color-scheme: light)').matches).toBe(
false,
Expand Down

0 comments on commit 1b552ce

Please sign in to comment.