mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
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
This commit is contained in:
parent
9460bdd3be
commit
a95862b6e2
|
@ -92,6 +92,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
postAuthenticateDone: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -215,6 +216,21 @@ export default defineComponent({
|
||||||
} catch {}
|
} catch {}
|
||||||
}, CLOUD_TRIAL_CHECK_INTERVAL);
|
}, 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() {
|
async mounted() {
|
||||||
this.setTheme();
|
this.setTheme();
|
||||||
|
@ -224,10 +240,7 @@ export default defineComponent({
|
||||||
this.redirectIfNecessary();
|
this.redirectIfNecessary();
|
||||||
void this.checkForNewVersions();
|
void this.checkForNewVersions();
|
||||||
void this.checkForCloudPlanData();
|
void this.checkForCloudPlanData();
|
||||||
|
void this.postAuthenticate();
|
||||||
if (this.sourceControlStore.isEnterpriseSourceControlEnabled) {
|
|
||||||
await this.sourceControlStore.getPreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
|
@ -239,6 +252,11 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
'usersStore.currentUser'(currentValue, previousValue) {
|
||||||
|
if (currentValue && !previousValue) {
|
||||||
|
void this.postAuthenticate();
|
||||||
|
}
|
||||||
|
},
|
||||||
$route(route) {
|
$route(route) {
|
||||||
this.authenticate();
|
this.authenticate();
|
||||||
this.redirectIfNecessary();
|
this.redirectIfNecessary();
|
||||||
|
|
|
@ -18,6 +18,16 @@ export function routesForSourceControl(server: Server) {
|
||||||
publicKey: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHEX+25m',
|
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) => {
|
server.post(`${sourceControlApiRoot}/preferences`, (schema: AppSchema, request: Request) => {
|
||||||
const requestBody: Partial<SourceControlPreferences> = jsonParse(request.requestBody);
|
const requestBody: Partial<SourceControlPreferences> = jsonParse(request.requestBody);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, reactive, onBeforeMount, ref } from 'vue';
|
import { computed, reactive, ref, onMounted } from 'vue';
|
||||||
import type { Rule, RuleGroup } from 'n8n-design-system/types';
|
import type { Rule, RuleGroup } from 'n8n-design-system/types';
|
||||||
import { MODAL_CONFIRM, VALID_EMAIL_REGEX } from '@/constants';
|
import { MODAL_CONFIRM, VALID_EMAIL_REGEX } from '@/constants';
|
||||||
import { useUIStore, useSourceControlStore } from '@/stores';
|
import { useUIStore, useSourceControlStore } from '@/stores';
|
||||||
|
@ -101,11 +101,16 @@ const goToUpgrade = () => {
|
||||||
uiStore.goToUpgrade('source-control', 'upgrade-source-control');
|
uiStore.goToUpgrade('source-control', 'upgrade-source-control');
|
||||||
};
|
};
|
||||||
|
|
||||||
onBeforeMount(() => {
|
const initialize = async () => {
|
||||||
|
await sourceControlStore.getPreferences();
|
||||||
if (sourceControlStore.preferences.connected) {
|
if (sourceControlStore.preferences.connected) {
|
||||||
isConnected.value = true;
|
isConnected.value = true;
|
||||||
void sourceControlStore.getBranches();
|
void sourceControlStore.getBranches();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await initialize();
|
||||||
});
|
});
|
||||||
|
|
||||||
const formValidationStatus = reactive<Record<string, boolean>>({
|
const formValidationStatus = reactive<Record<string, boolean>>({
|
||||||
|
|
|
@ -69,10 +69,13 @@ describe('SettingsSourceControl', () => {
|
||||||
|
|
||||||
it('should render user flow happy path', async () => {
|
it('should render user flow happy path', async () => {
|
||||||
vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
|
vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
|
||||||
|
|
||||||
const updatePreferencesSpy = vi.spyOn(sourceControlStore, 'updatePreferences');
|
const updatePreferencesSpy = vi.spyOn(sourceControlStore, 'updatePreferences');
|
||||||
|
|
||||||
const { container, getByTestId, queryByTestId, getByRole } = renderComponent();
|
const { container, getByTestId, queryByTestId, getByRole } = renderComponent();
|
||||||
|
|
||||||
|
await waitFor(() => expect(sourceControlStore.preferences.publicKey).not.toEqual(''));
|
||||||
|
|
||||||
const connectButton = getByTestId('source-control-connect-button');
|
const connectButton = getByTestId('source-control-connect-button');
|
||||||
expect(connectButton).toBeDisabled();
|
expect(connectButton).toBeDisabled();
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ describe('SettingsSourceControl', () => {
|
||||||
await userEvent.type(authorEmail, 'com');
|
await userEvent.type(authorEmail, 'com');
|
||||||
await userEvent.tab();
|
await userEvent.tab();
|
||||||
|
|
||||||
expect(connectButton).toBeEnabled();
|
await waitFor(() => expect(connectButton).toBeEnabled());
|
||||||
expect(queryByTestId('source-control-save-settings-button')).not.toBeInTheDocument();
|
expect(queryByTestId('source-control-save-settings-button')).not.toBeInTheDocument();
|
||||||
|
|
||||||
await userEvent.click(connectButton);
|
await userEvent.click(connectButton);
|
||||||
|
@ -139,5 +142,5 @@ describe('SettingsSourceControl', () => {
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(),
|
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(),
|
||||||
);
|
);
|
||||||
});
|
}, 10000);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue