From 6776cdc16d4734117ec3362e544c8a5b00fb6696 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 3 Sep 2024 14:47:08 +0800 Subject: [PATCH] replace user placeholder when security not enabled Signed-off-by: Hailong Cui --- .../user_ui_settings_client_wrapper.ts | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts b/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts index 709441a7c142..c7c3fa74bce8 100644 --- a/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts +++ b/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts @@ -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}_`, ''); + } } return id; } @@ -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); };