fix(editor): Fix initialize authenticated features (#9867)

This commit is contained in:
Csaba Tuncsik 2024-06-26 13:03:04 +02:00 committed by GitHub
parent 5bc58efde9
commit 4de58dcbf5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 18 deletions

View file

@ -60,7 +60,6 @@ import { useUsageStore } from '@/stores/usage.store';
import { useUsersStore } from '@/stores/users.store'; import { useUsersStore } from '@/stores/users.store';
import { useHistoryHelper } from '@/composables/useHistoryHelper'; import { useHistoryHelper } from '@/composables/useHistoryHelper';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { initializeAuthenticatedFeatures } from '@/init';
import { useAIStore } from './stores/ai.store'; import { useAIStore } from './stores/ai.store';
import AIAssistantChat from './components/AIAssistantChat/AIAssistantChat.vue'; import AIAssistantChat from './components/AIAssistantChat/AIAssistantChat.vue';
@ -103,26 +102,16 @@ export default defineComponent({
}, },
data() { data() {
return { return {
onAfterAuthenticateInitialized: false,
loading: true, loading: true,
}; };
}, },
watch: { watch: {
// eslint-disable-next-line @typescript-eslint/naming-convention
async 'usersStore.currentUser'(currentValue, previousValue) {
if (currentValue && !previousValue) {
await initializeAuthenticatedFeatures();
}
},
defaultLocale(newLocale) { defaultLocale(newLocale) {
void loadLanguage(newLocale); void loadLanguage(newLocale);
}, },
}, },
async mounted() { async mounted() {
this.logHiringBanner(); this.logHiringBanner();
void initializeAuthenticatedFeatures();
void useExternalHooks().run('app.mount'); void useExternalHooks().run('app.mount');
this.loading = false; this.loading = false;
}, },

View file

@ -7,6 +7,7 @@ import { useSettingsStore } from '@/stores/settings.store';
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 type { RouteRecordName } from 'vue-router'; import type { RouteRecordName } from 'vue-router';
import * as init from '@/init';
const App = { const App = {
template: '<div />', template: '<div />',
@ -15,6 +16,7 @@ const renderComponent = createComponentRenderer(App);
describe('router', () => { describe('router', () => {
let server: ReturnType<typeof setupServer>; let server: ReturnType<typeof setupServer>;
const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures');
beforeAll(async () => { beforeAll(async () => {
server = setupServer(); server = setupServer();
@ -25,8 +27,13 @@ describe('router', () => {
renderComponent({ pinia }); renderComponent({ pinia });
}); });
beforeEach(() => {
initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve());
});
afterAll(() => { afterAll(() => {
server.shutdown(); server.shutdown();
vi.restoreAllMocks();
}); });
test.each([ test.each([
@ -42,6 +49,7 @@ describe('router', () => {
'should resolve %s to %s', 'should resolve %s to %s',
async (path, name) => { async (path, name) => {
await router.push(path); await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name); expect(router.currentRoute.value.name).toBe(name);
}, },
10000, 10000,
@ -55,6 +63,7 @@ describe('router', () => {
'should redirect %s to %s if user does not have permissions', 'should redirect %s to %s if user does not have permissions',
async (path, name) => { async (path, name) => {
await router.push(path); await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name); expect(router.currentRoute.value.name).toBe(name);
}, },
10000, 10000,
@ -73,6 +82,7 @@ describe('router', () => {
settingsStore.settings.enterprise.workflowHistory = true; settingsStore.settings.enterprise.workflowHistory = true;
await router.push(path); await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name); expect(router.currentRoute.value.name).toBe(name);
}, },
10000, 10000,
@ -111,6 +121,7 @@ describe('router', () => {
rbacStore.setGlobalScopes(scopes); rbacStore.setGlobalScopes(scopes);
await router.push(path); await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name); expect(router.currentRoute.value.name).toBe(name);
}, },
10000, 10000,

View file

@ -15,7 +15,7 @@ import { EnterpriseEditionFeature, VIEWS, EDITABLE_CANVAS_VIEWS } from '@/consta
import { useTelemetry } from '@/composables/useTelemetry'; import { useTelemetry } from '@/composables/useTelemetry';
import { middleware } from '@/utils/rbac/middleware'; import { middleware } from '@/utils/rbac/middleware';
import type { RouterMiddleware } from '@/types/router'; import type { RouterMiddleware } from '@/types/router';
import { initializeCore } from '@/init'; import { initializeAuthenticatedFeatures, initializeCore } from '@/init';
import { tryToParseNumber } from '@/utils/typesUtils'; import { tryToParseNumber } from '@/utils/typesUtils';
import { projectsRoutes } from '@/routes/projects.routes'; import { projectsRoutes } from '@/routes/projects.routes';
@ -777,6 +777,7 @@ router.beforeEach(async (to: RouteLocationNormalized, from, next) => {
*/ */
await initializeCore(); await initializeCore();
await initializeAuthenticatedFeatures();
/** /**
* Redirect to setup page. User should be redirected to this only once * Redirect to setup page. User should be redirected to this only once

View file

@ -4789,12 +4789,6 @@ export default defineComponent({
} }
try { try {
await Promise.all([
this.loadVariables(),
this.tagsStore.fetchAll(),
this.loadCredentials(),
]);
if (workflowId !== null && !this.uiStore.stateIsDirty) { if (workflowId !== null && !this.uiStore.stateIsDirty) {
const workflow: IWorkflowDb | undefined = const workflow: IWorkflowDb | undefined =
await this.workflowsStore.fetchWorkflow(workflowId); await this.workflowsStore.fetchWorkflow(workflowId);
@ -4803,6 +4797,12 @@ export default defineComponent({
await this.openWorkflow(workflow); await this.openWorkflow(workflow);
} }
} }
await Promise.all([
this.loadVariables(),
this.tagsStore.fetchAll(),
this.loadCredentials(),
]);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }