mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix(editor): Separate cloud endpoint calls (#7312)
This PR untangles calls to cloud endpoints so failure in one of them doesn't stop others to go through.
This commit is contained in:
parent
1691223789
commit
04dfcd73be
|
@ -144,8 +144,9 @@ export default defineComponent({
|
|||
console.log(HIRING_BANNER);
|
||||
}
|
||||
},
|
||||
async checkForCloudPlanData() {
|
||||
return this.cloudPlanStore.checkForCloudPlanData();
|
||||
async checkForCloudData() {
|
||||
await this.cloudPlanStore.checkForCloudPlanData();
|
||||
await this.cloudPlanStore.fetchUserCloudAccount();
|
||||
},
|
||||
async initialize(): Promise<void> {
|
||||
await this.initSettings();
|
||||
|
@ -237,7 +238,7 @@ export default defineComponent({
|
|||
await this.authenticate();
|
||||
await this.redirectIfNecessary();
|
||||
void this.checkForNewVersions();
|
||||
await this.checkForCloudPlanData();
|
||||
await this.checkForCloudData();
|
||||
void this.postAuthenticate();
|
||||
|
||||
this.loading = false;
|
||||
|
|
|
@ -123,7 +123,8 @@ describe('UI store', () => {
|
|||
.spyOn(cloudPlanApi, 'getCloudUserInfo')
|
||||
.mockResolvedValue(getUserCloudInfo(true));
|
||||
setupOwnerAndCloudDeployment();
|
||||
await cloudPlanStore.getOwnerCurrentPlan();
|
||||
await cloudPlanStore.checkForCloudPlanData();
|
||||
await cloudPlanStore.fetchUserCloudAccount();
|
||||
expect(fetchCloudSpy).toHaveBeenCalled();
|
||||
expect(fetchUserCloudAccountSpy).toHaveBeenCalled();
|
||||
expect(uiStore.bannerStack).toContain('TRIAL');
|
||||
|
@ -137,7 +138,8 @@ describe('UI store', () => {
|
|||
.spyOn(cloudPlanApi, 'getCloudUserInfo')
|
||||
.mockResolvedValue(getUserCloudInfo(true));
|
||||
setupOwnerAndCloudDeployment();
|
||||
await cloudPlanStore.getOwnerCurrentPlan();
|
||||
await cloudPlanStore.checkForCloudPlanData();
|
||||
await cloudPlanStore.fetchUserCloudAccount();
|
||||
expect(fetchCloudSpy).toHaveBeenCalled();
|
||||
expect(fetchUserCloudAccountSpy).toHaveBeenCalled();
|
||||
expect(uiStore.bannerStack).toContain('TRIAL_OVER');
|
||||
|
@ -151,7 +153,8 @@ describe('UI store', () => {
|
|||
.spyOn(cloudPlanApi, 'getCloudUserInfo')
|
||||
.mockResolvedValue(getUserCloudInfo(false));
|
||||
setupOwnerAndCloudDeployment();
|
||||
await cloudPlanStore.getOwnerCurrentPlan();
|
||||
await cloudPlanStore.checkForCloudPlanData();
|
||||
await cloudPlanStore.fetchUserCloudAccount();
|
||||
expect(fetchCloudSpy).toHaveBeenCalled();
|
||||
expect(fetchUserCloudAccountSpy).toHaveBeenCalled();
|
||||
expect(uiStore.bannerStack).toContain('TRIAL_OVER');
|
||||
|
|
|
@ -52,11 +52,27 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
|
|||
return state.usage?.executions >= state.data?.monthlyExecutionsLimit;
|
||||
});
|
||||
|
||||
const getOwnerCurrentPlan = async () => {
|
||||
const hasCloudPlan = computed(() => {
|
||||
const cloudUserId = settingsStore.settings.n8nMetadata?.userId;
|
||||
const hasCloudPlan =
|
||||
usersStore.currentUser?.isOwner && settingsStore.isCloudDeployment && cloudUserId;
|
||||
if (!hasCloudPlan) throw new Error('User does not have a cloud plan');
|
||||
return usersStore.currentUser?.isOwner && settingsStore.isCloudDeployment && cloudUserId;
|
||||
});
|
||||
|
||||
const getUserCloudAccount = async () => {
|
||||
if (!hasCloudPlan.value) throw new Error('User does not have a cloud plan');
|
||||
try {
|
||||
if (useUsersStore().isInstanceOwner) {
|
||||
await usersStore.fetchUserCloudAccount();
|
||||
if (!usersStore.currentUserCloudInfo?.confirmed) {
|
||||
useUIStore().pushBannerToStack('EMAIL_CONFIRMATION');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const getOwnerCurrentPlan = async () => {
|
||||
if (!hasCloudPlan.value) throw new Error('User does not have a cloud plan');
|
||||
state.loadingPlan = true;
|
||||
let plan;
|
||||
try {
|
||||
|
@ -71,13 +87,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
|
|||
useUIStore().pushBannerToStack('TRIAL');
|
||||
}
|
||||
}
|
||||
|
||||
if (useUsersStore().isInstanceOwner) {
|
||||
await usersStore.fetchUserCloudAccount();
|
||||
if (!usersStore.currentUserCloudInfo?.confirmed) {
|
||||
useUIStore().pushBannerToStack('EMAIL_CONFIRMATION');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
state.loadingPlan = false;
|
||||
throw new Error(error);
|
||||
|
@ -132,6 +141,12 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
|
|||
} catch {}
|
||||
};
|
||||
|
||||
const fetchUserCloudAccount = async () => {
|
||||
try {
|
||||
await getUserCloudAccount();
|
||||
} catch {}
|
||||
};
|
||||
|
||||
return {
|
||||
state,
|
||||
getOwnerCurrentPlan,
|
||||
|
@ -145,5 +160,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
|
|||
allExecutionsUsed,
|
||||
reset,
|
||||
checkForCloudPlanData,
|
||||
fetchUserCloudAccount,
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue