Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/persistence/BaseMCWSPersistenceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class BaseMCWSPersistenceProvider {

const user = await this.openmct.user.getCurrentUser();
const containedNamespaces = await this.getNamespacesFromMCWS(namespaceDefinition);
const userNamespace = interpolateUsername(namespaceTemplate, user.id);
const userNamespace = interpolateUsername(namespaceTemplate, user.id, user.name);
const existingUserNamespace = containedNamespaces.find(
(namespace) => namespace.url === userNamespace.url
);
Expand Down Expand Up @@ -185,6 +185,7 @@ export default class BaseMCWSPersistenceProvider {
*
* @private
* @param {NamespaceDefinition} namespaceDefinition
* @param {string} userId the user ID
* @returns {Promise.<NamespaceDefinition>|Promise.<undefined>}
*/
async createIfMissing(namespaceDefinition, userId) {
Expand Down
24 changes: 12 additions & 12 deletions src/persistence/test/MCWSNamespaceServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ describe('MCWSNamespaceService', () => {
url: '/some/personal/namespace',
containsNamespaces: true,
childTemplate: {
id: 'personal-${USER}:root',
key: 'personal-${USER}',
name: '${USER}',
url: '/some/personal/namespace/${USER}'
id: 'personal-${USERID}:root',
key: 'personal-${USERID}',
name: '${USERNAME}',
url: '/some/personal/namespace/${USERID}'
}
};
inaccessibleContainerRootDefinition = {
Expand All @@ -112,10 +112,10 @@ describe('MCWSNamespaceService', () => {
url: '/inaccessible/personal/namespace',
containsNamespaces: true,
childTemplate: {
id: 'inaccessible-personal-${USER}:root',
key: 'inaccessible-personal-${USER}',
name: '${USER}',
url: '/inaccessible/personal/namespace/${USER}'
id: 'inaccessible-personal-${USERID}:root',
key: 'inaccessible-personal-${USERID}',
name: '${USERNAME}',
url: '/inaccessible/personal/namespace/${USERID}'
}
};
missingContainerRootDefinition = {
Expand All @@ -125,10 +125,10 @@ describe('MCWSNamespaceService', () => {
url: '/missing/personal/namespace',
containsNamespaces: true,
childTemplate: {
id: 'missing-personal-${USER}:root',
key: 'missing-personal-${USER}',
name: '${USER}',
url: '/missing/personal/namespace/${USER}'
id: 'missing-personal-${USERID}:root',
key: 'missing-personal-${USERID}',
name: '${USERNAME}',
url: '/missing/personal/namespace/${USERID}'
}
};

Expand Down
18 changes: 10 additions & 8 deletions src/persistence/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export function createNamespace(namespace) {
url: namespace.url,
containsNamespaces: true,
childTemplate: {
id: namespace.key + '-${USER}' + ROOT_NAMESPACE_SUFFIX,
key: namespace.key + '-${USER}',
name: '${USER}',
url: namespace.url + '/${USER}'
id: namespace.key + '-${USERID}' + ROOT_NAMESPACE_SUFFIX,
key: namespace.key + '-${USERID}',
name: '${USERNAME}',
url: namespace.url + '/${USERID}'
}
};
} else {
Expand All @@ -65,18 +65,20 @@ export function createNamespace(namespace) {

/**
* Interpolate a username with all values in a supplied object, replacing
* '${USER}' with the supplied username.
* '${USERNAME}' with the supplied username and '${USERID}' with the
* supplied user ID.
*
* @private
* @param {NamespaceTemplate} templateObject namespace template object.
* @param {string} username a username.
* @param {string} userId the user ID
* @param {string} username the username (default is userId)
* @returns {NamespaceDefinition} a namespace definition object.
*/
export function interpolateUsername(templateObject, username) {
export function interpolateUsername(templateObject, userId, username = userId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const namespaceDefinition = {};

Object.keys(templateObject).forEach((key) => {
namespaceDefinition[key] = templateObject[key].replace('${USER}', username);
namespaceDefinition[key] = templateObject[key].replace('${USERNAME}', username).replace('${USERID}', userId);
});

return namespaceDefinition;
Expand Down
2 changes: 1 addition & 1 deletion src/services/identity/createMCWSUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @param {MCWSUserInfo} userInfo
*/
constructor(name) {
super(name, name); // no id is returned, so we use name twice
super(String(name).replace(/[^a-zA-Z0-9]/g, ''), name);

Check warning on line 11 in src/services/identity/createMCWSUser.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#replaceAll()` over `String#replace()`.

See more on https://sonarcloud.io/project/issues?id=NASA-AMMOS_openmct-mcws&issues=AZ2sofuA43vI1cIAlHpg&open=AZ2sofuA43vI1cIAlHpg&pullRequest=410
}
};
}
Loading