Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/utils/urls/urlHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const hostUnknown = 'www.vg.no';
describe('Shared urlHelper.ts', () => {
test('returnUrlToMessageBox() returning correct environemnts', () => {
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostTT } as Location);
expect(getMessageBoxUrl()).toBe('https://tt02.altinn.no/ui/messagebox');
expect(getMessageBoxUrl()).toBe('https://af.tt02.altinn.no/');
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostAT } as Location);
expect(getMessageBoxUrl()).toBe('https://at21.altinn.cloud/ui/messagebox');
expect(getMessageBoxUrl()).toBe('https://af.at21.altinn.cloud/');
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostYT } as Location);
expect(getMessageBoxUrl()).toBe('https://yt01.altinn.cloud/ui/messagebox');
expect(getMessageBoxUrl()).toBe('https://af.yt01.altinn.cloud/');
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostProd } as Location);
expect(getMessageBoxUrl()).toBe('https://altinn.no/ui/messagebox');
expect(getMessageBoxUrl()).toBe('https://af.altinn.no/');
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostDocker } as Location);
expect(getMessageBoxUrl()).toBe('http://local.altinn.cloud/');
jest.spyOn(window, 'location', 'get').mockReturnValueOnce({ host: hostPodman } as Location);
Expand All @@ -55,12 +55,12 @@ describe('Shared urlHelper.ts', () => {
});

test('returnUrlTProfile() returning correct environments', () => {
expect(returnUrlToProfile(hostTT)).toBe('https://tt02.altinn.no/ui/profile');
expect(returnUrlToProfile(hostAT)).toBe('https://at21.altinn.cloud/ui/profile');
expect(returnUrlToProfile(hostYT)).toBe('https://yt01.altinn.cloud/ui/profile');
expect(returnUrlToProfile(hostProd)).toBe('https://altinn.no/ui/profile');
expect(returnUrlToProfile(hostDocker)).toBe('http://local.altinn.cloud/');
expect(returnUrlToProfile(hostPodman)).toBe('http://local.altinn.cloud:8000/');
expect(returnUrlToProfile(hostTT)).toBe('https://af.tt02.altinn.no/profile');
expect(returnUrlToProfile(hostAT)).toBe('https://af.at21.altinn.cloud/profile');
expect(returnUrlToProfile(hostYT)).toBe('https://af.yt01.altinn.cloud/profile');
expect(returnUrlToProfile(hostProd)).toBe('https://af.altinn.no/profile');
expect(returnUrlToProfile(hostDocker)).toBe('http://local.altinn.cloud/profile');
expect(returnUrlToProfile(hostPodman)).toBe('http://local.altinn.cloud:8000/profile');
expect(returnUrlToProfile(hostStudio)).toBe(undefined);
expect(returnUrlToProfile(hostStudioDev)).toBe(undefined);
expect(returnUrlToProfile(hostUnknown)).toBe(undefined);
Expand All @@ -79,10 +79,10 @@ describe('Shared urlHelper.ts', () => {
});

test('returnUrlToArchive() returning correct environments', () => {
expect(returnUrlToArchive(hostTT)).toBe('https://tt02.altinn.no/ui/messagebox/archive');
expect(returnUrlToArchive(hostAT)).toBe('https://at21.altinn.cloud/ui/messagebox/archive');
expect(returnUrlToArchive(hostYT)).toBe('https://yt01.altinn.cloud/ui/messagebox/archive');
expect(returnUrlToArchive(hostProd)).toBe('https://altinn.no/ui/messagebox/archive');
expect(returnUrlToArchive(hostTT)).toBe('https://af.tt02.altinn.no/');
expect(returnUrlToArchive(hostAT)).toBe('https://af.at21.altinn.cloud/');
expect(returnUrlToArchive(hostYT)).toBe('https://af.yt01.altinn.cloud/');
expect(returnUrlToArchive(hostProd)).toBe('https://af.altinn.no/');
expect(returnUrlToArchive(hostDocker)).toBe('http://local.altinn.cloud/');
expect(returnUrlToArchive(hostPodman)).toBe('http://local.altinn.cloud:8000/');
expect(returnUrlToArchive(hostStudio)).toBe(undefined);
Expand Down
86 changes: 48 additions & 38 deletions src/utils/urls/urlHelper.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,82 @@
export const altinnAppsIllustrationHelpCircleSvgUrl = 'https://altinncdn.no/img/illustration-help-circle.svg';
export const orgsListUrl = 'https://altinncdn.no/orgs/altinn-orgs.json';

const redirectAndChangeParty = (goTo: string, partyId: number) =>
`ui/Reportee/ChangeReporteeAndRedirect?goTo=${encodeURIComponent(goTo)}&R=${partyId}`;

const prodStagingRegex = /^\w+\.apps\.((\w+\.)?altinn\.(no|cloud))$/;
const localRegex = /^local\.altinn\.cloud(:\d+)?$/;

export const returnBaseUrlToAltinn = (host: string): string | undefined => {
const prodStagingMatch = host.match(prodStagingRegex);
if (prodStagingMatch) {
const altinnHost = prodStagingMatch[1];
function isLocalEnvironment(host: string): boolean {
return localRegex.test(host);
}

function extractAltinnHost(host: string): string | undefined {
const match = host.match(prodStagingRegex);
return match?.[1];
}

return `https://${altinnHost}/`;
function isProductionEnvironment(altinnHost: string): boolean {
return altinnHost === 'altinn.no';
}

function buildArbeidsflateUrl(altinnHost: string): string {
if (isProductionEnvironment(altinnHost)) {
return 'https://af.altinn.no/';
}

return `https://af.${altinnHost}/`;
}

export const returnBaseUrlToAltinn = (host: string): string | undefined => {
const altinnHost = extractAltinnHost(host);
if (!altinnHost) {
return undefined;
}
return `https://${altinnHost}/`;
};

export const getMessageBoxUrl = (partyId?: number | undefined): string | undefined => {
/**
* Returns the URL to the arbeidsflate (workspace) inbox.
* @param _partyId - Deprecated: Party selection is now handled by arbeidsflate itself
*/
export const getMessageBoxUrl = (_partyId?: number): string | undefined => {
const host = window.location.host;

if (host.match(localRegex)) {
if (isLocalEnvironment(host)) {
return `http://${host}/`;
}

const baseUrl = returnBaseUrlToAltinn(host);
if (!baseUrl) {
return;
}

const messageBoxUrl = `${baseUrl}ui/messagebox`;

if (partyId === undefined) {
return messageBoxUrl;
const altinnHost = extractAltinnHost(host);
if (!altinnHost) {
return undefined;
}

return `${baseUrl}${redirectAndChangeParty(messageBoxUrl, partyId)}`;
return buildArbeidsflateUrl(altinnHost);
};

export const returnUrlToArchive = (host: string): string | undefined => {
if (host.match(localRegex)) {
if (isLocalEnvironment(host)) {
return `http://${host}/`;
}

const baseUrl = returnBaseUrlToAltinn(host);
if (!baseUrl) {
return;
const altinnHost = extractAltinnHost(host);
if (!altinnHost) {
return undefined;
}

return `${baseUrl}ui/messagebox/archive`;
return buildArbeidsflateUrl(altinnHost);
};

export const returnUrlToProfile = (host: string, partyId?: number | undefined): string | undefined => {
if (host.match(localRegex)) {
return `http://${host}/`;
}

const baseUrl = returnBaseUrlToAltinn(host);
if (!baseUrl) {
return;
export const returnUrlToProfile = (host: string, _partyId?: number | undefined): string | undefined => {
if (isLocalEnvironment(host)) {
return `http://${host}/profile`;
}

const profileUrl = `${baseUrl}ui/profile`;

if (partyId === undefined) {
return profileUrl;
const altinnHost = extractAltinnHost(host);
if (!altinnHost) {
return undefined;
}

return `${baseUrl}${redirectAndChangeParty(profileUrl, partyId)}`;
const arbeidsflateUrl = buildArbeidsflateUrl(altinnHost);
return `${arbeidsflateUrl.replace(/\/$/, '')}/profile`;
};

export const returnUrlToAllForms = (host: string): string | undefined => {
Expand Down
Loading