Skip to content

Commit 0007128

Browse files
author
Peter Di Pasquale
committed
Updated MCWS persistence to scrub the returned user ID of invalid characters to support full name returns from identity service
1 parent 91a0998 commit 0007128

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/persistence/BaseMCWSPersistenceProvider.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default class BaseMCWSPersistenceProvider {
106106

107107
const user = await this.openmct.user.getCurrentUser();
108108
const containedNamespaces = await this.getNamespacesFromMCWS(namespaceDefinition);
109-
const userNamespace = interpolateUsername(namespaceTemplate, user.id);
109+
const userNamespace = interpolateUsername(namespaceTemplate, user.name, user.id);
110110
const existingUserNamespace = containedNamespaces.find(namespace => namespace.url === userNamespace.url);
111111

112112
if (existingUserNamespace) {
@@ -118,7 +118,7 @@ export default class BaseMCWSPersistenceProvider {
118118

119119
containedNamespaces.unshift(userNamespace);
120120

121-
await this.createIfMissing(userNamespace, user.id);
121+
await this.createIfMissing(userNamespace, user.id, user.name);
122122

123123
return containedNamespaces;
124124
}
@@ -137,7 +137,7 @@ export default class BaseMCWSPersistenceProvider {
137137
const templateObject = namespaceDefinition.childTemplate;
138138
const userNamespaces = namespaces.map((namespace) => {
139139
const username = USERNAME_FROM_PATH_REGEX.exec(namespace.subject)[1]
140-
const userNamespaceDefinition = interpolateUsername(templateObject, username);
140+
const userNamespaceDefinition = interpolateUsername(templateObject, username, username);
141141

142142
userNamespaceDefinition.location = namespaceDefinition.id;
143143

@@ -156,7 +156,7 @@ export default class BaseMCWSPersistenceProvider {
156156
*/
157157
async getRootNamespaces() {
158158
const user = await this.openmct.user.getCurrentUser();
159-
let rootNamespaces = await Promise.all(this.roots.map((rootNamespace) => this.createIfMissing(rootNamespace, user.id)));
159+
let rootNamespaces = await Promise.all(this.roots.map((rootNamespace) => this.createIfMissing(rootNamespace, user.id, user.name)));
160160
rootNamespaces = rootNamespaces.filter(Boolean);
161161

162162
return this.filterNamespacesByPath(rootNamespaces);
@@ -172,7 +172,7 @@ export default class BaseMCWSPersistenceProvider {
172172
* @param {NamespaceDefinition} namespaceDefinition
173173
* @returns {Promise.<NamespaceDefinition>|Promise.<undefined>}
174174
*/
175-
async createIfMissing(namespaceDefinition, userId) {
175+
async createIfMissing(namespaceDefinition, userId, userName) {
176176
const namespace = mcws.namespace(namespaceDefinition.url);
177177

178178
try {

src/persistence/test/MCWSNamespaceServiceSpec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ describe('MCWSNamespaceService', () => {
104104
url: '/some/personal/namespace',
105105
containsNamespaces: true,
106106
childTemplate: {
107-
id: 'personal-${USER}:root',
108-
key: 'personal-${USER}',
109-
name: '${USER}',
110-
url: '/some/personal/namespace/${USER}'
107+
id: 'personal-${USERID}:root',
108+
key: 'personal-${USERID}',
109+
name: '${USERNAME}',
110+
url: '/some/personal/namespace/${USERID}'
111111
}
112112
};
113113
inaccessibleContainerRootDefinition = {
@@ -117,10 +117,10 @@ describe('MCWSNamespaceService', () => {
117117
url: '/inaccessible/personal/namespace',
118118
containsNamespaces: true,
119119
childTemplate: {
120-
id: 'inaccessible-personal-${USER}:root',
121-
key: 'inaccessible-personal-${USER}',
122-
name: '${USER}',
123-
url: '/inaccessible/personal/namespace/${USER}'
120+
id: 'inaccessible-personal-${USERID}:root',
121+
key: 'inaccessible-personal-${USERID}',
122+
name: '${USERNAME}',
123+
url: '/inaccessible/personal/namespace/${USERID}'
124124
}
125125
};
126126
missingContainerRootDefinition = {
@@ -130,10 +130,10 @@ describe('MCWSNamespaceService', () => {
130130
url: '/missing/personal/namespace',
131131
containsNamespaces: true,
132132
childTemplate: {
133-
id: 'missing-personal-${USER}:root',
134-
key: 'missing-personal-${USER}',
135-
name: '${USER}',
136-
url: '/missing/personal/namespace/${USER}'
133+
id: 'missing-personal-${USERID}:root',
134+
key: 'missing-personal-${USERID}',
135+
name: '${USERNAME}',
136+
url: '/missing/personal/namespace/${USERID}'
137137
}
138138
};
139139

src/persistence/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export function createNamespace(namespace) {
3636
url: namespace.url,
3737
containsNamespaces: true,
3838
childTemplate: {
39-
id: namespace.key + '-${USER}:root',
40-
key: namespace.key + '-${USER}',
41-
name: '${USER}',
42-
url: namespace.url + '/${USER}'
39+
id: namespace.key + '-${USERID}:root',
40+
key: namespace.key + '-${USERID}',
41+
name: '${USERNAME}',
42+
url: namespace.url + '/${USERID}'
4343
}
4444
};
4545
} else {
@@ -54,18 +54,19 @@ export function createNamespace(namespace) {
5454

5555
/**
5656
* Interpolate a username with all values in a supplied object, replacing
57-
* '${USER}' with the supplied username.
57+
* '${USERNAME}' with the supplied username and '${USERID} with the
58+
* supplied user ID.
5859
*
5960
* @private
6061
* @param {NamespaceTemplate} templateObject namespace template object.
6162
* @param {string} username a username.
6263
* @returns {NamespaceDefinition} a namespace definition object.
6364
*/
64-
export function interpolateUsername(templateObject, username) {
65+
export function interpolateUsername(templateObject, username, userid) {
6566
const namespaceDefinition = {};
6667

6768
Object.keys(templateObject).forEach(key => {
68-
namespaceDefinition[key] = templateObject[key].replace('${USER}', username);
69+
namespaceDefinition[key] = templateObject[key].replace('${USERNAME}', username).replace('${USERID}', userid);
6970
});
7071

7172
return namespaceDefinition;

src/services/identity/createMCWSUser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function createMCWSUser(UserClass) {
99
* @param {MCWSUserInfo} userInfo
1010
*/
1111
constructor(name) {
12-
super(name, name); // no id is returned, so we use name twice
12+
super(String(name).replace(/[^a-zA-Z0-9]/g, ''), name); // no id is returned, so we use name twice
1313
}
1414
};
1515
}

0 commit comments

Comments
 (0)