Skip to content

Commit

Permalink
replace user placeholder when security not enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Sep 3, 2024
1 parent cabf38a commit 6776cdc
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export class UserUISettingsClientWrapper {

private normalizeDocId(id: string, request: OpenSearchDashboardsRequest, core?: CoreStart) {
const userName = extractUserName(request, core);
if (userName && this.isUserLevelSetting(id)) {
return id.replace(CURRENT_USER, userName);
if (this.isUserLevelSetting(id)) {
if (userName) {
return id.replace(CURRENT_USER, userName);
} else {
return id.replace(`${CURRENT_USER}_`, '');

Check warning on line 47 in src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts#L47

Added line #L47 was not covered by tests
}
}
return id;
}
Expand Down Expand Up @@ -86,29 +90,37 @@ export class UserUISettingsClientWrapper {
const { id } = options || {};
const userLevel = this.isUserLevelSetting(id);

if (type === 'config' && userLevel && userName && id) {
const permissions = {
permissions: new ACL()
.addPermission(['write'], {
users: [userName],
})
.getPermissions()!,
};

if (type === 'config' && id) {
const docId = this.normalizeDocId(id, wrapperOptions.request, this.core);
// create with reference, the reference field will used for filter settings by user
return await wrapperOptions.client.create(type, attributes, {
...options,
id: docId,
references: [
{
type: 'user', // dummy type
id: userName,
name: userName,
},
],
...(this.savedObjectsPermissionEnabled ? permissions : {}),
});

if (userLevel && userName) {
const permissions = {
permissions: new ACL()
.addPermission(['write'], {
users: [userName],
})
.getPermissions()!,
};

// create with reference, the reference field will used for filter settings by user
return await wrapperOptions.client.create(type, attributes, {
...options,
id: docId,
references: [
{
type: 'user', // dummy type
id: userName,
name: userName,
},
],
...(this.savedObjectsPermissionEnabled ? permissions : {}),
});
} else {
return wrapperOptions.client.create(type, attributes, {
...options,
id: docId,
});
}
}
return wrapperOptions.client.create(type, attributes, options);
};
Expand Down

0 comments on commit 6776cdc

Please sign in to comment.