diff --git a/packages/editor-ui/src/api/cloudPlans.ts b/packages/editor-ui/src/api/cloudPlans.ts index aca826a6c9..fed694fb91 100644 --- a/packages/editor-ui/src/api/cloudPlans.ts +++ b/packages/editor-ui/src/api/cloudPlans.ts @@ -18,5 +18,5 @@ export async function confirmEmail(context: IRestApiContext): Promise { - return get(context.baseUrl, '/admin/login/code'); + return get(context.baseUrl, '/cloud/proxy/login/code'); } diff --git a/packages/editor-ui/src/stores/__tests__/ui.test.ts b/packages/editor-ui/src/stores/__tests__/ui.test.ts index f263d412f6..359b9baee0 100644 --- a/packages/editor-ui/src/stores/__tests__/ui.test.ts +++ b/packages/editor-ui/src/stores/__tests__/ui.test.ts @@ -12,20 +12,21 @@ import { getUserCloudInfo, getNotTrialingUserResponse, } from './utils/cloudStoreUtils'; +import type { IRole } from '@/Interface'; let uiStore: ReturnType; let settingsStore: ReturnType; let rootStore: ReturnType; let cloudPlanStore: ReturnType; -function setOwnerUser() { +function setUser(role: IRole) { useUsersStore().addUsers([ { id: '1', isPending: false, globalRole: { id: '1', - name: 'owner', + name: role, createdAt: new Date(), }, }, @@ -35,7 +36,7 @@ function setOwnerUser() { } function setupOwnerAndCloudDeployment() { - setOwnerUser(); + setUser('owner'); settingsStore.setSettings( merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, { n8nMetadata: { @@ -77,23 +78,34 @@ describe('UI store', () => { [ 'default', 'production', + 'owner', 'https://n8n.io/pricing?utm_campaign=utm-test-campaign&source=test_source', ], [ 'default', 'development', + 'owner', 'https://n8n.io/pricing?utm_campaign=utm-test-campaign&source=test_source', ], [ 'cloud', 'production', + 'owner', `https://app.n8n.cloud/login?code=123&returnPath=${encodeURIComponent( '/account/change-plan', )}&utm_campaign=utm-test-campaign&source=test_source`, ], + [ + 'cloud', + 'production', + 'member', + 'https://n8n.io/pricing?utm_campaign=utm-test-campaign&source=test_source', + ], ])( - '"upgradeLinkUrl" should generate the correct URL for "%s" deployment and "%s" license environment', - async (type, environment, expectation) => { + '"upgradeLinkUrl" should generate the correct URL for "%s" deployment and "%s" license environment and user role "%s"', + async (type, environment, role, expectation) => { + setUser(role as IRole); + settingsStore.setSettings( merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, { deployment: { diff --git a/packages/editor-ui/src/stores/ui.store.ts b/packages/editor-ui/src/stores/ui.store.ts index 52c9c0bfee..e28f3b18fa 100644 --- a/packages/editor-ui/src/stores/ui.store.ts +++ b/packages/editor-ui/src/stores/ui.store.ts @@ -55,7 +55,7 @@ import { defineStore } from 'pinia'; import { useRootStore } from '@/stores/n8nRoot.store'; import { getCurlToJson } from '@/api/curlHelper'; import { useWorkflowsStore } from '@/stores/workflows.store'; -import { useSettingsStore } from '@/stores/settings.store'; +import { useSettingsStore, useUsersStore } from '@/stores/settings.store'; import { useCloudPlanStore } from '@/stores/cloudPlan.store'; import { useTelemetryStore } from '@/stores/telemetry.store'; import { getStyleTokenValue } from '@/utils/htmlUtils'; @@ -346,9 +346,11 @@ export const useUIStore = defineStore(STORES.UI, { const searchParams = new URLSearchParams(); - if (deploymentType === 'cloud') { - const { code } = await useCloudPlanStore().getAutoLoginCode(); + const isOwner = useUsersStore().isInstanceOwner; + + if (deploymentType === 'cloud' && isOwner) { const adminPanelHost = new URL(window.location.href).host.split('.').slice(1).join('.'); + const { code } = await useCloudPlanStore().getAutoLoginCode(); linkUrl = `https://${adminPanelHost}/login`; searchParams.set('code', code); searchParams.set('returnPath', '/account/change-plan');