Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete portalId/defaultPortal if account is present #394

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions packages/cms-lib/lib/__tests__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ describe('lib/config', () => {
},
"authType": "oauth2",
"name": "OAUTH2",
"portalId": 2223,
}
`);
});
Expand Down Expand Up @@ -942,14 +941,11 @@ describe('lib/config', () => {
setConfig(CONFIG);
});

it('supports both defaultPortal and defaultAccount', () => {
it('supports defaultAccount', () => {
drewjenkins marked this conversation as resolved.
Show resolved Hide resolved
updateDefaultAccount(LEGACY_ACCOUNTS[0].portalId);
expect(getConfig().defaultAccount).toEqual(
LEGACY_ACCOUNTS[0].portalId
);
expect(getConfig().defaultPortal).toEqual(
LEGACY_ACCOUNTS[0].portalId
);
});
});
});
Expand Down
22 changes: 15 additions & 7 deletions packages/cms-lib/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const setConfig = updatedConfig => {
const getConfigAccounts = config => {
const __config = config || getConfig();
if (!__config) return;

return __config.accounts || __config.portals;
};

Expand Down Expand Up @@ -417,11 +418,19 @@ const getEnv = nameOrId => {
return env;
};

const getAccountConfig = accountId =>
getConfigAccounts(getAndLoadConfigIfNeeded()).find(
const getAccountConfig = accountId => {
const account = getConfigAccounts(getAndLoadConfigIfNeeded()).find(
account => account.accountId === accountId || account.portalId === accountId
);

if (account && account.portalId) {
account.accountId = account.accountId || account.portalId;
delete account.portalId;
}
drewjenkins marked this conversation as resolved.
Show resolved Hide resolved

return account;
};

/*
* Returns a accountId from the config if it exists, else returns null
*/
Expand Down Expand Up @@ -529,6 +538,7 @@ const updateAccountConfig = configOptions => {
accounts = [nextAccountConfig];
}
}

return nextAccountConfig;
};

Expand All @@ -546,12 +556,10 @@ const updateDefaultAccount = defaultAccount => {
}

const config = getAndLoadConfigIfNeeded();
if (config.defaultAccount) {
config.defaultAccount = defaultAccount;
}
// Keep for backcompat
config.defaultAccount = defaultAccount;

if (config.defaultPortal) {
config.defaultPortal = defaultAccount;
delete config.defaultPortal;
drewjenkins marked this conversation as resolved.
Show resolved Hide resolved
}

setDefaultConfigPathIfUnset();
Expand Down