mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -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() {
|
||||
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();
|
||||
|
|
|
@ -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<SourceControlPreferences> = jsonParse(request.requestBody);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<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 { MODAL_CONFIRM, VALID_EMAIL_REGEX } from '@/constants';
|
||||
import { useUIStore, useSourceControlStore } from '@/stores';
|
||||
|
@ -101,11 +101,16 @@ const goToUpgrade = () => {
|
|||
uiStore.goToUpgrade('source-control', 'upgrade-source-control');
|
||||
};
|
||||
|
||||
onBeforeMount(() => {
|
||||
const initialize = async () => {
|
||||
await sourceControlStore.getPreferences();
|
||||
if (sourceControlStore.preferences.connected) {
|
||||
isConnected.value = true;
|
||||
void sourceControlStore.getBranches();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await initialize();
|
||||
});
|
||||
|
||||
const formValidationStatus = reactive<Record<string, boolean>>({
|
||||
|
|
|
@ -69,10 +69,13 @@ describe('SettingsSourceControl', () => {
|
|||
|
||||
it('should render user flow happy path', async () => {
|
||||
vi.spyOn(settingsStore, 'isEnterpriseFeatureEnabled').mockReturnValue(true);
|
||||
|
||||
const updatePreferencesSpy = vi.spyOn(sourceControlStore, 'updatePreferences');
|
||||
|
||||
const { container, getByTestId, queryByTestId, getByRole } = renderComponent();
|
||||
|
||||
await waitFor(() => expect(sourceControlStore.preferences.publicKey).not.toEqual(''));
|
||||
|
||||
const connectButton = getByTestId('source-control-connect-button');
|
||||
expect(connectButton).toBeDisabled();
|
||||
|
||||
|
@ -104,7 +107,7 @@ describe('SettingsSourceControl', () => {
|
|||
await userEvent.type(authorEmail, 'com');
|
||||
await userEvent.tab();
|
||||
|
||||
expect(connectButton).toBeEnabled();
|
||||
await waitFor(() => expect(connectButton).toBeEnabled());
|
||||
expect(queryByTestId('source-control-save-settings-button')).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.click(connectButton);
|
||||
|
@ -139,5 +142,5 @@ describe('SettingsSourceControl', () => {
|
|||
await waitFor(() =>
|
||||
expect(queryByTestId('source-control-connected-content')).not.toBeInTheDocument(),
|
||||
);
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue