1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-10 12:35:46 +03:00

fix: Add role check for upgrade path (#7374)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Mutasem <mutdmour@gmail.com>
This commit is contained in:
Ricardo Espinoza 2023-10-09 11:18:08 +02:00 committed by GitHub
parent 3fa27647d8
commit a43f720658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -18,5 +18,5 @@ export async function confirmEmail(context: IRestApiContext): Promise<Cloud.User
}
export async function getAdminPanelLoginCode(context: IRestApiContext): Promise<{ code: string }> {
return get(context.baseUrl, '/admin/login/code');
return get(context.baseUrl, '/cloud/proxy/login/code');
}

View File

@ -12,20 +12,21 @@ import {
getUserCloudInfo,
getNotTrialingUserResponse,
} from './utils/cloudStoreUtils';
import type { IRole } from '@/Interface';
let uiStore: ReturnType<typeof useUIStore>;
let settingsStore: ReturnType<typeof useSettingsStore>;
let rootStore: ReturnType<typeof useRootStore>;
let cloudPlanStore: ReturnType<typeof useCloudPlanStore>;
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: {

View File

@ -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');