Skip to content

Commit

Permalink
fix(editor): Fix initialize authenticated features (#9867)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik authored and netroy committed Jun 26, 2024
1 parent 4f1341d commit 4b88f65
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
11 changes: 0 additions & 11 deletions packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import { useUsageStore } from '@/stores/usage.store';
import { useUsersStore } from '@/stores/users.store';
import { useHistoryHelper } from '@/composables/useHistoryHelper';
import { useRoute } from 'vue-router';
import { initializeAuthenticatedFeatures } from '@/init';
import { useAIStore } from './stores/ai.store';
import AIAssistantChat from './components/AIAssistantChat/AIAssistantChat.vue';
Expand Down Expand Up @@ -103,26 +102,16 @@ export default defineComponent({
},
data() {
return {
onAfterAuthenticateInitialized: false,
loading: true,
};
},
watch: {
// eslint-disable-next-line @typescript-eslint/naming-convention
async 'usersStore.currentUser'(currentValue, previousValue) {
if (currentValue && !previousValue) {
await initializeAuthenticatedFeatures();
}
},
defaultLocale(newLocale) {
void loadLanguage(newLocale);
},
},
async mounted() {
this.logHiringBanner();
void initializeAuthenticatedFeatures();
void useExternalHooks().run('app.mount');
this.loading = false;
},
Expand Down
11 changes: 11 additions & 0 deletions packages/editor-ui/src/__tests__/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useSettingsStore } from '@/stores/settings.store';
import { useRBACStore } from '@/stores/rbac.store';
import type { Scope } from '@n8n/permissions';
import type { RouteRecordName } from 'vue-router';
import * as init from '@/init';

const App = {
template: '<div />',
Expand All @@ -15,6 +16,7 @@ const renderComponent = createComponentRenderer(App);

describe('router', () => {
let server: ReturnType<typeof setupServer>;
const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures');

beforeAll(async () => {
server = setupServer();
Expand All @@ -25,8 +27,13 @@ describe('router', () => {
renderComponent({ pinia });
});

beforeEach(() => {
initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve());
});

afterAll(() => {
server.shutdown();
vi.restoreAllMocks();
});

test.each([
Expand All @@ -42,6 +49,7 @@ describe('router', () => {
'should resolve %s to %s',
async (path, name) => {
await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name);
},
10000,
Expand All @@ -55,6 +63,7 @@ describe('router', () => {
'should redirect %s to %s if user does not have permissions',
async (path, name) => {
await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name);
},
10000,
Expand All @@ -73,6 +82,7 @@ describe('router', () => {
settingsStore.settings.enterprise.workflowHistory = true;

await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name);
},
10000,
Expand Down Expand Up @@ -111,6 +121,7 @@ describe('router', () => {
rbacStore.setGlobalScopes(scopes);

await router.push(path);
expect(initializeAuthenticatedFeaturesSpy).toHaveBeenCalled();
expect(router.currentRoute.value.name).toBe(name);
},
10000,
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { EnterpriseEditionFeature, VIEWS, EDITABLE_CANVAS_VIEWS } from '@/consta
import { useTelemetry } from '@/composables/useTelemetry';
import { middleware } from '@/utils/rbac/middleware';
import type { RouterMiddleware } from '@/types/router';
import { initializeCore } from '@/init';
import { initializeAuthenticatedFeatures, initializeCore } from '@/init';
import { tryToParseNumber } from '@/utils/typesUtils';
import { projectsRoutes } from '@/routes/projects.routes';

Expand Down Expand Up @@ -777,6 +777,7 @@ router.beforeEach(async (to: RouteLocationNormalized, from, next) => {
*/

await initializeCore();
await initializeAuthenticatedFeatures();

/**
* Redirect to setup page. User should be redirected to this only once
Expand Down
12 changes: 6 additions & 6 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4787,12 +4787,6 @@ export default defineComponent({
}
try {
await Promise.all([
this.loadVariables(),
this.tagsStore.fetchAll(),
this.loadCredentials(),
]);
if (workflowId !== null && !this.uiStore.stateIsDirty) {
const workflow: IWorkflowDb | undefined =
await this.workflowsStore.fetchWorkflow(workflowId);
Expand All @@ -4801,6 +4795,12 @@ export default defineComponent({
await this.openWorkflow(workflow);
}
}
await Promise.all([
this.loadVariables(),
this.tagsStore.fetchAll(),
this.loadCredentials(),
]);
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit 4b88f65

Please sign in to comment.