From a95862b6e237b669bcf518e182ed66720332b4d7 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Mon, 10 Jul 2023 12:35:36 +0200 Subject: [PATCH] fix: Add postAuthenticate hook for source control preferences (no-changelog) (#6629) * feat: handle source control settings in post-authenticate app hook * fix: only trigger post authenticate when logging in * chore: remove console.log * chore: fix linting issues * test: update source control test --- packages/editor-ui/src/App.vue | 26 ++++++++++++++++--- .../server/endpoints/sourceControl.ts | 10 +++++++ .../src/views/SettingsSourceControl.vue | 9 +++++-- .../__tests__/SettingsSourceControl.test.ts | 7 +++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/editor-ui/src/App.vue b/packages/editor-ui/src/App.vue index 37ddb0e50f..84d5e9f4d3 100644 --- a/packages/editor-ui/src/App.vue +++ b/packages/editor-ui/src/App.vue @@ -92,6 +92,7 @@ export default defineComponent({ }, data() { return { + postAuthenticateDone: false, loading: true, }; }, @@ -215,6 +216,21 @@ export default defineComponent({ } catch {} }, CLOUD_TRIAL_CHECK_INTERVAL); }, + async postAuthenticate() { + if (this.postAuthenticateDone) { + return; + } + + if (!this.usersStore.currentUser) { + return; + } + + if (this.sourceControlStore.isEnterpriseSourceControlEnabled) { + await this.sourceControlStore.getPreferences(); + } + + this.postAuthenticateDone = true; + }, }, async mounted() { this.setTheme(); @@ -224,10 +240,7 @@ export default defineComponent({ this.redirectIfNecessary(); void this.checkForNewVersions(); void this.checkForCloudPlanData(); - - if (this.sourceControlStore.isEnterpriseSourceControlEnabled) { - await this.sourceControlStore.getPreferences(); - } + void this.postAuthenticate(); this.loading = false; @@ -239,6 +252,11 @@ export default defineComponent({ } }, watch: { + 'usersStore.currentUser'(currentValue, previousValue) { + if (currentValue && !previousValue) { + void this.postAuthenticate(); + } + }, $route(route) { this.authenticate(); this.redirectIfNecessary(); diff --git a/packages/editor-ui/src/__tests__/server/endpoints/sourceControl.ts b/packages/editor-ui/src/__tests__/server/endpoints/sourceControl.ts index 2b5fbe8799..445c76257a 100644 --- a/packages/editor-ui/src/__tests__/server/endpoints/sourceControl.ts +++ b/packages/editor-ui/src/__tests__/server/endpoints/sourceControl.ts @@ -18,6 +18,16 @@ export function routesForSourceControl(server: Server) { publicKey: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHEX+25m', }; + server.get(`${sourceControlApiRoot}/preferences`, (schema: AppSchema, request: Request) => { + return new Response( + 200, + {}, + { + data: defaultSourceControlPreferences, + }, + ); + }); + server.post(`${sourceControlApiRoot}/preferences`, (schema: AppSchema, request: Request) => { const requestBody: Partial = jsonParse(request.requestBody); diff --git a/packages/editor-ui/src/views/SettingsSourceControl.vue b/packages/editor-ui/src/views/SettingsSourceControl.vue index dd111bab13..2d2c70f195 100644 --- a/packages/editor-ui/src/views/SettingsSourceControl.vue +++ b/packages/editor-ui/src/views/SettingsSourceControl.vue @@ -1,5 +1,5 @@