fix(editor): Open update CTA docs in a new tab on self-hosted instances (#30571)

This commit is contained in:
Ricardo Espinoza 2026-05-18 11:32:37 -04:00 committed by GitHub
parent 341abecbfb
commit 3fca302df2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 41 deletions

View File

@ -138,54 +138,56 @@ describe('usePageRedirectionHelper', () => {
},
);
test.each([
[
'cloud',
'production',
ROLE.Owner,
`https://app.n8n.cloud/login?code=123&returnPath=${encodeURIComponent('/manage')}`,
],
[
'cloud',
'production',
ROLE.Member,
'https://docs.n8n.io/release-notes/#n8n1652?utm_source=n8n_app&utm_medium=instance_upgrade_releases',
],
])(
'"goToVersions" should generate the correct URL for "%s" deployment and "%s" license environment and user role "%s"',
async (type, environment, role, expectation) => {
// Arrange
usersStore.addUsers([
{
id: '1',
isPending: false,
role,
},
]);
describe('goToVersions', () => {
test('redirects in the same tab for cloud instance owners', async () => {
usersStore.addUsers([{ id: '1', isPending: false, role: ROLE.Owner }]);
usersStore.currentUserId = '1';
settingsStore.setSettings(
merge({}, defaultSettings, {
deployment: {
type,
},
license: {
environment,
},
deployment: { type: 'cloud' },
license: { environment: 'production' },
}),
);
// Act
const windowOpenSpy = vi.spyOn(window, 'open').mockReturnValue(null);
await pageRedirectionHelper.goToVersions();
// Assert
expect(location.href).toBe(
`https://app.n8n.cloud/login?code=123&returnPath=${encodeURIComponent('/manage')}`,
);
expect(windowOpenSpy).not.toHaveBeenCalled();
});
expect(location.href).toBe(expectation);
},
);
test.each([
['cloud', ROLE.Member],
['default', ROLE.Owner],
['default', ROLE.Member],
])('opens the docs URL in a new tab for "%s" deployment with role "%s"', async (type, role) => {
usersStore.addUsers([{ id: '1', isPending: false, role }]);
usersStore.currentUserId = '1';
settingsStore.setSettings(
merge({}, defaultSettings, {
deployment: { type },
license: { environment: 'production' },
}),
);
const initialHref = location.href;
const windowOpenSpy = vi.spyOn(window, 'open').mockReturnValue(null);
await pageRedirectionHelper.goToVersions();
expect(windowOpenSpy).toHaveBeenCalledWith(
'https://docs.n8n.io/release-notes/#n8n1652?utm_source=n8n_app&utm_medium=instance_upgrade_releases',
'_blank',
'noopener',
);
expect(location.href).toBe(initialHref);
});
});
test.each([
[

View File

@ -20,15 +20,14 @@ export function usePageRedirectionHelper() {
* Otherwise, it redirect them to our docs.
*/
const goToVersions = async () => {
let versionsLink = versionsStore.infoUrl;
if (usersStore.isInstanceOwner && settingsStore.isCloudDeployment) {
versionsLink = await cloudPlanStore.generateCloudDashboardAutoLoginLink({
location.href = await cloudPlanStore.generateCloudDashboardAutoLoginLink({
redirectionPath: '/manage',
});
return;
}
location.href = versionsLink;
window.open(versionsStore.infoUrl, '_blank', 'noopener');
};
const goToDashboard = async () => {