From dcf92489f7e73156e04eabcc6655428243e8672e Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Fri, 21 Oct 2022 15:12:34 -0700 Subject: [PATCH 1/9] Resolve review comments Signed-off-by: Chang Liu --- public/apps/account/tenant-switch-panel.tsx | 1 - .../role-edit/cluster-permission-panel.tsx | 2 +- .../role-edit/index-permission-panel.tsx | 2 +- .../panels/role-edit/tenant-panel.tsx | 2 +- .../apps/configuration/utils/tenant-utils.tsx | 16 +++++++++++++--- public/plugin.tsx | 18 ++---------------- server/plugin.ts | 1 - server/saved_objects/saved_objects_wrapper.ts | 5 +---- 8 files changed, 19 insertions(+), 28 deletions(-) diff --git a/public/apps/account/tenant-switch-panel.tsx b/public/apps/account/tenant-switch-panel.tsx index 6f5c07f88..55fbd4abb 100755 --- a/public/apps/account/tenant-switch-panel.tsx +++ b/public/apps/account/tenant-switch-panel.tsx @@ -91,7 +91,6 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) { const currentUserName = accountInfo.data.user_name; setUsername(currentUserName); - // @ts-ignore let currentRawTenantName: string | undefined; if (props.config.multitenancy.enable_aggregation_view) { currentRawTenantName = props.tenant; diff --git a/public/apps/configuration/panels/role-edit/cluster-permission-panel.tsx b/public/apps/configuration/panels/role-edit/cluster-permission-panel.tsx index 9c6068d35..e80d0d0e1 100644 --- a/public/apps/configuration/panels/role-edit/cluster-permission-panel.tsx +++ b/public/apps/configuration/panels/role-edit/cluster-permission-panel.tsx @@ -49,7 +49,7 @@ export function ClusterPermissionPanel(props: { options={optionUniverse} selectedOptions={state} onChange={setState} - id="cluster-permission-box" + id="roles-cluster-permission-box" /> {/* TODO: 'Browse and select' button with a pop-up modal for selection */} diff --git a/public/apps/configuration/panels/role-edit/index-permission-panel.tsx b/public/apps/configuration/panels/role-edit/index-permission-panel.tsx index e9272597c..75e2856e4 100644 --- a/public/apps/configuration/panels/role-edit/index-permission-panel.tsx +++ b/public/apps/configuration/panels/role-edit/index-permission-panel.tsx @@ -153,7 +153,7 @@ export function IndexPermissionRow(props: { options={props.permisionOptionsSet} selectedOptions={props.value} onChange={props.onChangeHandler} - id="index-permission-box" + id="roles-index-permission-box" /> {/* TODO: 'Browse and select' button with a pop-up modal for selection */} diff --git a/public/apps/configuration/panels/role-edit/tenant-panel.tsx b/public/apps/configuration/panels/role-edit/tenant-panel.tsx index 78a0dbd1c..2cce9e546 100644 --- a/public/apps/configuration/panels/role-edit/tenant-panel.tsx +++ b/public/apps/configuration/panels/role-edit/tenant-panel.tsx @@ -91,7 +91,7 @@ function generateTenantPermissionPanels( onChange={onValueChangeHandler('tenantPatterns')} onCreateOption={onCreateOptionHandler('tenantPatterns')} options={permisionOptionsSet} - id="tenant-permission-box" + id="roles-tenant-permission-box" /> diff --git a/public/apps/configuration/utils/tenant-utils.tsx b/public/apps/configuration/utils/tenant-utils.tsx index 080a93f1c..616e19834 100644 --- a/public/apps/configuration/utils/tenant-utils.tsx +++ b/public/apps/configuration/utils/tenant-utils.tsx @@ -36,9 +36,11 @@ import { httpDelete, httpGet, httpPost } from './request-utils'; import { getResourceUrl } from './resource-utils'; export const globalTenantName = 'global_tenant'; +export const GLOBAL_TENANT = ''; +export const PRIVATE_TENANT = '__user__'; export const GLOBAL_USER_DICT: { [key: string]: string } = { Label: 'Global', - Value: '', + Value: GLOBAL_TENANT, Description: 'Everyone can see it', }; @@ -62,10 +64,10 @@ export function transformTenantData( ): Tenant[] { // @ts-ignore const tenantList: Tenant[] = map(rawTenantData, (v: Tenant, k?: string) => ({ - tenant: k === globalTenantName ? GLOBAL_USER_DICT.Label : k || '', + tenant: k === globalTenantName ? GLOBAL_USER_DICT.Label : k || GLOBAL_TENANT, reserved: v.reserved, description: k === globalTenantName ? GLOBAL_USER_DICT.Description : v.description, - tenantValue: k === globalTenantName ? GLOBAL_USER_DICT.Value : k || '', + tenantValue: k === globalTenantName ? GLOBAL_USER_DICT.Value : k || GLOBAL_TENANT, })); if (isPrivateEnabled) { // Insert Private Tenant in List @@ -170,3 +172,11 @@ export function transformRoleTenantPermissions( permissionType: getTenantPermissionType(tenantPermission.allowed_actions), })); } + +export function isPrivateTenant(selectedTenant: string | null) { + return selectedTenant !== null && selectedTenant?.startsWith(PRIVATE_TENANT); +} + +export function isGlobalTenant(selectedTenant: string | null) { + return selectedTenant !== null && selectedTenant === GLOBAL_TENANT; +} diff --git a/public/plugin.tsx b/public/plugin.tsx index ca1d47388..3a38449ea 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -53,6 +53,7 @@ import { } from './types'; import { addTenantToShareURL } from './services/shared-link'; import { interceptError } from './utils/logout-utils'; +import { isGlobalTenant, isPrivateTenant } from './apps/configuration/utils/tenant-utils'; async function hasApiPermission(core: CoreSetup): Promise { try { @@ -73,8 +74,6 @@ const APP_ID_OPENSEARCH_DASHBOARDS = 'kibana'; const APP_LIST_FOR_READONLY_ROLE = [APP_ID_HOME, APP_ID_DASHBOARDS, APP_ID_OPENSEARCH_DASHBOARDS]; const GLOBAL_TENANT_RENDERING_TEXT = 'Global'; const PRIVATE_TENANT_RENDERING_TEXT = 'Private'; -const GLOBAL_TENANT = ''; -const PRIVATE_TENANT = '__user__'; export class SecurityPlugin implements @@ -169,7 +168,7 @@ export class SecurityPlugin name:
Tenant
, dataType: 'string', render: (value: any[][]) => { - let text = value[0][0]; + let text = value.flat()[0]; if (isGlobalTenant(text)) { text = GLOBAL_TENANT_RENDERING_TEXT; } else if (isPrivateTenant(text)) { @@ -204,21 +203,8 @@ export class SecurityPlugin if (config.multitenancy.enabled) { addTenantToShareURL(core); } - - if (config.multitenancy.enable_aggregation_view) { - const columns = deps.savedObjectsManagement.columns.getAll(); - } - return {}; } public stop() {} } - -function isPrivateTenant(selectedTenant: string) { - return selectedTenant.startsWith('__user__'); -} - -function isGlobalTenant(selectedTenant: string) { - return selectedTenant === null || selectedTenant === GLOBAL_TENANT; -} diff --git a/server/plugin.ts b/server/plugin.ts index e5fa06fe9..357364983 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -15,7 +15,6 @@ import { first } from 'rxjs/operators'; import { Observable } from 'rxjs'; -import _ from 'lodash'; import { PluginInitializerContext, CoreSetup, diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index 53c4d0dc6..33e7f539a 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -34,6 +34,7 @@ import { SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, } from 'opensearch-dashboards/server'; +import { isPrivateTenant } from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { @@ -176,7 +177,3 @@ export class SecuritySavedObjectsClientWrapper { }; }; } - -function isPrivateTenant(selectedTenant: string | undefined) { - return selectedTenant === '__user__'; -} From 851761f65273455d2fd3d18fbb01b30959dd1263 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Fri, 21 Oct 2022 17:14:08 -0700 Subject: [PATCH 2/9] Resolve review comments Signed-off-by: Chang Liu --- .../apps/configuration/utils/tenant-utils.tsx | 1 + server/auth/types/authentication_type.ts | 7 +++--- server/plugin.ts | 8 +++--- server/saved_objects/saved_objects_wrapper.ts | 25 +++++++++++++------ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/public/apps/configuration/utils/tenant-utils.tsx b/public/apps/configuration/utils/tenant-utils.tsx index 616e19834..590fb22a7 100644 --- a/public/apps/configuration/utils/tenant-utils.tsx +++ b/public/apps/configuration/utils/tenant-utils.tsx @@ -38,6 +38,7 @@ import { getResourceUrl } from './resource-utils'; export const globalTenantName = 'global_tenant'; export const GLOBAL_TENANT = ''; export const PRIVATE_TENANT = '__user__'; +export const DEFAULT_TENANT = 'default'; export const GLOBAL_USER_DICT: { [key: string]: string } = { Label: 'Global', Value: GLOBAL_TENANT, diff --git a/server/auth/types/authentication_type.ts b/server/auth/types/authentication_type.ts index 7234dcb5e..b09093dc2 100755 --- a/server/auth/types/authentication_type.ts +++ b/server/auth/types/authentication_type.ts @@ -26,7 +26,6 @@ import { IOpenSearchDashboardsResponse, AuthResult, } from 'opensearch-dashboards/server'; -import { any } from 'joi'; import { SecurityPluginConfigType } from '../..'; import { SecuritySessionCookie } from '../../session/security_cookie'; import { SecurityClient } from '../../backend/opensearch_security_client'; @@ -36,6 +35,7 @@ import { isValidTenant, } from '../../multitenancy/tenant_resolver'; import { UnauthenticatedError } from '../../errors'; +import { GLOBAL_TENANT } from '../../../public/apps/configuration/utils/tenant-utils'; export interface IAuthenticationType { type: string; @@ -102,7 +102,6 @@ export abstract class AuthenticationType implements IAuthenticationType { } const authState: OpenSearchDashboardsAuthState = {}; - const globalTenant = ''; // if browser request, auth logic is: // 1. check if request includes auth header or paramter(e.g. jwt in url params) is present, if so, authenticate with auth header. @@ -186,7 +185,7 @@ export abstract class AuthenticationType implements IAuthenticationType { // set tenant in header if (this.config.multitenancy.enable_aggregation_view) { // Store all saved objects in a single kibana index. - Object.assign(authHeaders, { securitytenant: globalTenant }); + Object.assign(authHeaders, { securitytenant: GLOBAL_TENANT }); } else { Object.assign(authHeaders, { securitytenant: tenant }); } @@ -245,7 +244,7 @@ export abstract class AuthenticationType implements IAuthenticationType { if (!authInfo) { try { authInfo = await this.securityClient.authinfo(request, authHeader); - } catch (error) { + } catch (error: any) { throw new UnauthenticatedError(error); } } diff --git a/server/plugin.ts b/server/plugin.ts index 357364983..09395bcc1 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -135,7 +135,7 @@ export class SecurityPlugin implements Plugin(); const config = await config$.pipe(first()).toPromise(); + + this.savedObjectClientWrapper.httpStart = core.http; + this.savedObjectClientWrapper.config = config; + if (config.multitenancy?.enabled) { const globalConfig$: Observable = this.initializerContext.config.legacy .globalConfig$; diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index 33e7f539a..a2f85e7d6 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -34,11 +34,19 @@ import { SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, } from 'opensearch-dashboards/server'; -import { isPrivateTenant } from '../../public/apps/configuration/utils/tenant-utils'; +import { Config } from 'packages/osd-config/target'; +import { SecurityPluginConfigType } from '..'; +import { + DEFAULT_TENANT, + GLOBAL_TENANT, + isPrivateTenant, + PRIVATE_TENANT, +} from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { public httpStart?: HttpServiceStart; + public config?: SecurityPluginConfigType; constructor() {} @@ -49,9 +57,8 @@ export class SecuritySavedObjectsClientWrapper { const selectedTenant = state.selectedTenant; const username = state.authInfo?.user_name; - const globalTenant = ''; - const defaultTenant = 'default'; - const privateTenant = '__user__'; + const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; + const isPrivateEnabled = this.config!.multitenancy.tenants.enable_private; let namespaceValue = selectedTenant; @@ -83,9 +90,13 @@ export class SecuritySavedObjectsClientWrapper { ): Promise> => { const tenants = state.authInfo?.tenants; const availableTenantNames = Object.keys(tenants!); - availableTenantNames.push(defaultTenant); - availableTenantNames.push(globalTenant); - availableTenantNames.push(privateTenant + state.authInfo?.user_name); + availableTenantNames.push(DEFAULT_TENANT); + if (isGlobalEnabled) { + availableTenantNames.push(GLOBAL_TENANT); + } + if (isPrivateEnabled) { + availableTenantNames.push(PRIVATE_TENANT + state.authInfo?.user_name); + } _.assign(options, { namespaces: availableTenantNames }); return await wrapperOptions.client.find(options); }; From 9dedb4fbc97aa432f07578e007d5f412456ee54c Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Fri, 21 Oct 2022 23:23:13 -0700 Subject: [PATCH 3/9] Resolve review comments + Add multitenancy.enabled to feature flag Signed-off-by: Chang Liu --- public/apps/account/account-app.tsx | 6 +++--- public/apps/account/tenant-switch-panel.tsx | 7 +++++-- public/plugin.tsx | 9 ++------- server/auth/types/authentication_type.ts | 2 +- server/plugin.ts | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/public/apps/account/account-app.tsx b/public/apps/account/account-app.tsx index 2379275e2..d6b4af397 100644 --- a/public/apps/account/account-app.tsx +++ b/public/apps/account/account-app.tsx @@ -37,7 +37,6 @@ function tenantSpecifiedInUrl() { export async function setupTopNavButton(coreStart: CoreStart, config: ClientConfigType) { const accountInfo = (await fetchAccountInfoSafe(coreStart.http))?.data; - const currentTenant = await fetchCurrentTenant(coreStart.http); if (accountInfo) { // Missing role error if (accountInfo.roles.length === 0 && !window.location.href.includes(CUSTOM_ERROR_PAGE_URI)) { @@ -46,11 +45,12 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf } let tenant: string | undefined; - if (config.multitenancy.enable_aggregation_view) { - tenant = currentTenant; + if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { + tenant = await fetchCurrentTenant(coreStart.http); } else { tenant = accountInfo.user_requested_tenant; } + let shouldShowTenantPopup = true; if (tenantSpecifiedInUrl() || getShouldShowTenantPopup() === false) { diff --git a/public/apps/account/tenant-switch-panel.tsx b/public/apps/account/tenant-switch-panel.tsx index 55fbd4abb..d825dc20f 100755 --- a/public/apps/account/tenant-switch-panel.tsx +++ b/public/apps/account/tenant-switch-panel.tsx @@ -92,7 +92,10 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) { setUsername(currentUserName); let currentRawTenantName: string | undefined; - if (props.config.multitenancy.enable_aggregation_view) { + if ( + props.config.multitenancy.enabled && + props.config.multitenancy.enable_aggregation_view + ) { currentRawTenantName = props.tenant; } else { currentRawTenantName = accountInfo.data.user_requested_tenant; @@ -105,7 +108,7 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) { }; fetchData(); - }, [props.coreStart.http, props.tenant, props.config.multitenancy.enable_aggregation_view]); + }, [props.coreStart.http, props.tenant, props.config.multitenancy]); // Custom tenant super select related. const onCustomTenantChange = (selectedOption: EuiComboBoxOptionOption[]) => { diff --git a/public/plugin.tsx b/public/plugin.tsx index 3a38449ea..89f837179 100644 --- a/public/plugin.tsx +++ b/public/plugin.tsx @@ -14,12 +14,7 @@ */ import { BehaviorSubject } from 'rxjs'; -import { - SavedObjectsManagementColumn, - SavedObjectsManagementRecord, -} from 'src/plugins/saved_objects_management/public'; -import { EuiTableFieldDataColumnType } from '@elastic/eui'; -import { string } from 'joi'; +import { SavedObjectsManagementColumn } from 'src/plugins/saved_objects_management/public'; import React from 'react'; import { i18n } from '@osd/i18n'; import { @@ -160,7 +155,7 @@ export class SecurityPlugin }) ); - if (config.multitenancy.enable_aggregation_view) { + if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { deps.savedObjectsManagement.columns.register(({ id: 'tenant_column', euiColumn: { diff --git a/server/auth/types/authentication_type.ts b/server/auth/types/authentication_type.ts index b09093dc2..f566c112b 100755 --- a/server/auth/types/authentication_type.ts +++ b/server/auth/types/authentication_type.ts @@ -183,7 +183,7 @@ export abstract class AuthenticationType implements IAuthenticationType { authState.selectedTenant = tenant; // set tenant in header - if (this.config.multitenancy.enable_aggregation_view) { + if (this.config.multitenancy.enabled && this.config.multitenancy.enable_aggregation_view) { // Store all saved objects in a single kibana index. Object.assign(authHeaders, { securitytenant: GLOBAL_TENANT }); } else { diff --git a/server/plugin.ts b/server/plugin.ts index 09395bcc1..b7c9e0ce8 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -133,7 +133,7 @@ export class SecurityPlugin implements Plugin Date: Sat, 22 Oct 2022 22:59:43 -0700 Subject: [PATCH 4/9] Resolve more comments Signed-off-by: Chang Liu --- server/saved_objects/saved_objects_wrapper.ts | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index a2f85e7d6..7b4a20386 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -36,17 +36,12 @@ import { } from 'opensearch-dashboards/server'; import { Config } from 'packages/osd-config/target'; import { SecurityPluginConfigType } from '..'; -import { - DEFAULT_TENANT, - GLOBAL_TENANT, - isPrivateTenant, - PRIVATE_TENANT, -} from '../../public/apps/configuration/utils/tenant-utils'; +import { DEFAULT_TENANT, GLOBAL_TENANT, isPrivateTenant, PRIVATE_TENANT } from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { public httpStart?: HttpServiceStart; - public config?: SecurityPluginConfigType; + public config? : SecurityPluginConfigType; constructor() {} @@ -57,7 +52,7 @@ export class SecuritySavedObjectsClientWrapper { const selectedTenant = state.selectedTenant; const username = state.authInfo?.user_name; - const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; + const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; const isPrivateEnabled = this.config!.multitenancy.tenants.enable_private; let namespaceValue = selectedTenant; @@ -67,7 +62,7 @@ export class SecuritySavedObjectsClientWrapper { attributes: T, options?: SavedObjectsCreateOptions ) => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -78,7 +73,7 @@ export class SecuritySavedObjectsClientWrapper { objects: SavedObjectsBulkGetObject[] = [], options: SavedObjectsBaseOptions = {} ): Promise> => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -106,7 +101,7 @@ export class SecuritySavedObjectsClientWrapper { id: string, options: SavedObjectsBaseOptions = {} ): Promise> => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -119,7 +114,7 @@ export class SecuritySavedObjectsClientWrapper { attributes: Partial, options: SavedObjectsUpdateOptions = {} ): Promise> => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -130,7 +125,7 @@ export class SecuritySavedObjectsClientWrapper { objects: Array>, options?: SavedObjectsCreateOptions ): Promise> => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -141,7 +136,7 @@ export class SecuritySavedObjectsClientWrapper { objects: Array>, options?: SavedObjectsBulkUpdateOptions ): Promise> => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -153,7 +148,7 @@ export class SecuritySavedObjectsClientWrapper { id: string, options: SavedObjectsDeleteOptions = {} ) => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); @@ -164,7 +159,7 @@ export class SecuritySavedObjectsClientWrapper { objects: SavedObjectsCheckConflictsObject[] = [], options: SavedObjectsBaseOptions = {} ): Promise => { - if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) { + if (selectedTenant !== undefined && isPrivateEnabled && isPrivateTenant(selectedTenant)) { namespaceValue = selectedTenant + username; } _.assign(options, { namespace: [namespaceValue] }); From d2f2e229626df43a96a6667f074ba05afb4de548 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Sat, 22 Oct 2022 23:16:30 -0700 Subject: [PATCH 5/9] Fix lint Signed-off-by: Chang Liu --- server/saved_objects/saved_objects_wrapper.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index 7b4a20386..fb80175c1 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -36,12 +36,17 @@ import { } from 'opensearch-dashboards/server'; import { Config } from 'packages/osd-config/target'; import { SecurityPluginConfigType } from '..'; -import { DEFAULT_TENANT, GLOBAL_TENANT, isPrivateTenant, PRIVATE_TENANT } from '../../public/apps/configuration/utils/tenant-utils'; +import { + DEFAULT_TENANT, + GLOBAL_TENANT, + isPrivateTenant, + PRIVATE_TENANT, +} from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { public httpStart?: HttpServiceStart; - public config? : SecurityPluginConfigType; + public config?: SecurityPluginConfigType; constructor() {} @@ -52,7 +57,7 @@ export class SecuritySavedObjectsClientWrapper { const selectedTenant = state.selectedTenant; const username = state.authInfo?.user_name; - const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; + const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; const isPrivateEnabled = this.config!.multitenancy.tenants.enable_private; let namespaceValue = selectedTenant; From 27d4715497a336b8112a9f2af3780ef0edf78942 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Sun, 23 Oct 2022 23:48:16 -0700 Subject: [PATCH 6/9] Resolve review comments Signed-off-by: Chang Liu --- public/apps/account/account-app.tsx | 6 +++- .../apps/configuration/utils/tenant-utils.tsx | 26 +++++++++++++++++ public/{plugin.tsx => plugin.ts} | 28 +++---------------- 3 files changed, 35 insertions(+), 25 deletions(-) rename public/{plugin.tsx => plugin.ts} (86%) diff --git a/public/apps/account/account-app.tsx b/public/apps/account/account-app.tsx index d6b4af397..e76fd1412 100644 --- a/public/apps/account/account-app.tsx +++ b/public/apps/account/account-app.tsx @@ -46,7 +46,11 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf let tenant: string | undefined; if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { - tenant = await fetchCurrentTenant(coreStart.http); + try { + tenant = await fetchCurrentTenant(coreStart.http); + } catch (e) { + console.log(e); + } } else { tenant = accountInfo.user_requested_tenant; } diff --git a/public/apps/configuration/utils/tenant-utils.tsx b/public/apps/configuration/utils/tenant-utils.tsx index 590fb22a7..606ba2fa7 100644 --- a/public/apps/configuration/utils/tenant-utils.tsx +++ b/public/apps/configuration/utils/tenant-utils.tsx @@ -15,6 +15,8 @@ import { HttpStart } from 'opensearch-dashboards/public'; import { map } from 'lodash'; +import React from 'react'; +import { i18n } from '@osd/i18n'; import { API_ENDPOINT_TENANTS, API_ENDPOINT_MULTITENANCY, @@ -39,6 +41,8 @@ export const globalTenantName = 'global_tenant'; export const GLOBAL_TENANT = ''; export const PRIVATE_TENANT = '__user__'; export const DEFAULT_TENANT = 'default'; +export const GLOBAL_TENANT_RENDERING_TEXT = 'Global'; +export const PRIVATE_TENANT_RENDERING_TEXT = 'Private'; export const GLOBAL_USER_DICT: { [key: string]: string } = { Label: 'Global', Value: GLOBAL_TENANT, @@ -181,3 +185,25 @@ export function isPrivateTenant(selectedTenant: string | null) { export function isGlobalTenant(selectedTenant: string | null) { return selectedTenant !== null && selectedTenant === GLOBAL_TENANT; } + +export const tenantColumn = { + id: 'tenant_column', + euiColumn: { + field: 'namespaces', + name:
Tenant
, + dataType: 'string', + render: (value: any[][]) => { + let text = value.flat()[0]; + if (isGlobalTenant(text)) { + text = GLOBAL_TENANT_RENDERING_TEXT; + } else if (isPrivateTenant(text)) { + text = PRIVATE_TENANT_RENDERING_TEXT; + } + text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', { + defaultMessage: text, + }); + return
{text}
; + }, + }, + loadData: () => {}, +}; diff --git a/public/plugin.tsx b/public/plugin.ts similarity index 86% rename from public/plugin.tsx rename to public/plugin.ts index 89f837179..2adb33a83 100644 --- a/public/plugin.tsx +++ b/public/plugin.ts @@ -15,8 +15,6 @@ import { BehaviorSubject } from 'rxjs'; import { SavedObjectsManagementColumn } from 'src/plugins/saved_objects_management/public'; -import React from 'react'; -import { i18n } from '@osd/i18n'; import { AppMountParameters, AppStatus, @@ -48,7 +46,7 @@ import { } from './types'; import { addTenantToShareURL } from './services/shared-link'; import { interceptError } from './utils/logout-utils'; -import { isGlobalTenant, isPrivateTenant } from './apps/configuration/utils/tenant-utils'; +import { tenantColumn } from './apps/configuration/utils/tenant-utils'; async function hasApiPermission(core: CoreSetup): Promise { try { @@ -156,27 +154,9 @@ export class SecurityPlugin ); if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { - deps.savedObjectsManagement.columns.register(({ - id: 'tenant_column', - euiColumn: { - field: 'namespaces', - name:
Tenant
, - dataType: 'string', - render: (value: any[][]) => { - let text = value.flat()[0]; - if (isGlobalTenant(text)) { - text = GLOBAL_TENANT_RENDERING_TEXT; - } else if (isPrivateTenant(text)) { - text = PRIVATE_TENANT_RENDERING_TEXT; - } - text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', { - defaultMessage: text, - }); - return
{text}
; - }, - }, - loadData: () => {}, - } as unknown) as SavedObjectsManagementColumn); + deps.savedObjectsManagement.columns.register( + (tenantColumn as unknown) as SavedObjectsManagementColumn + ); } // Return methods that should be available to other plugins From c99cd21cbcdc68b7e7a79ac811b9529c00945a65 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Sat, 22 Oct 2022 22:59:43 -0700 Subject: [PATCH 7/9] Resolve more comments Signed-off-by: Chang Liu --- server/saved_objects/saved_objects_wrapper.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index fb80175c1..7b4a20386 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -36,17 +36,12 @@ import { } from 'opensearch-dashboards/server'; import { Config } from 'packages/osd-config/target'; import { SecurityPluginConfigType } from '..'; -import { - DEFAULT_TENANT, - GLOBAL_TENANT, - isPrivateTenant, - PRIVATE_TENANT, -} from '../../public/apps/configuration/utils/tenant-utils'; +import { DEFAULT_TENANT, GLOBAL_TENANT, isPrivateTenant, PRIVATE_TENANT } from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { public httpStart?: HttpServiceStart; - public config?: SecurityPluginConfigType; + public config? : SecurityPluginConfigType; constructor() {} @@ -57,7 +52,7 @@ export class SecuritySavedObjectsClientWrapper { const selectedTenant = state.selectedTenant; const username = state.authInfo?.user_name; - const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; + const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; const isPrivateEnabled = this.config!.multitenancy.tenants.enable_private; let namespaceValue = selectedTenant; From 0ef67eca2c973e0e7b7688a3abce688223e82575 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Sat, 22 Oct 2022 23:16:30 -0700 Subject: [PATCH 8/9] Fix lint Signed-off-by: Chang Liu --- server/saved_objects/saved_objects_wrapper.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/saved_objects/saved_objects_wrapper.ts b/server/saved_objects/saved_objects_wrapper.ts index 7b4a20386..fb80175c1 100644 --- a/server/saved_objects/saved_objects_wrapper.ts +++ b/server/saved_objects/saved_objects_wrapper.ts @@ -36,12 +36,17 @@ import { } from 'opensearch-dashboards/server'; import { Config } from 'packages/osd-config/target'; import { SecurityPluginConfigType } from '..'; -import { DEFAULT_TENANT, GLOBAL_TENANT, isPrivateTenant, PRIVATE_TENANT } from '../../public/apps/configuration/utils/tenant-utils'; +import { + DEFAULT_TENANT, + GLOBAL_TENANT, + isPrivateTenant, + PRIVATE_TENANT, +} from '../../public/apps/configuration/utils/tenant-utils'; import { OpenSearchDashboardsAuthState } from '../auth/types/authentication_type'; export class SecuritySavedObjectsClientWrapper { public httpStart?: HttpServiceStart; - public config? : SecurityPluginConfigType; + public config?: SecurityPluginConfigType; constructor() {} @@ -52,7 +57,7 @@ export class SecuritySavedObjectsClientWrapper { const selectedTenant = state.selectedTenant; const username = state.authInfo?.user_name; - const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; + const isGlobalEnabled = this.config!.multitenancy.tenants.enable_global; const isPrivateEnabled = this.config!.multitenancy.tenants.enable_private; let namespaceValue = selectedTenant; From 5c7e1abaa569c8fc2402dd7f32775fef095170d1 Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Sun, 23 Oct 2022 23:48:16 -0700 Subject: [PATCH 9/9] Resolve review comments Signed-off-by: Chang Liu --- public/apps/account/account-app.tsx | 6 +++- .../apps/configuration/utils/tenant-utils.tsx | 26 +++++++++++++++++ public/{plugin.tsx => plugin.ts} | 28 +++---------------- 3 files changed, 35 insertions(+), 25 deletions(-) rename public/{plugin.tsx => plugin.ts} (86%) diff --git a/public/apps/account/account-app.tsx b/public/apps/account/account-app.tsx index d6b4af397..e76fd1412 100644 --- a/public/apps/account/account-app.tsx +++ b/public/apps/account/account-app.tsx @@ -46,7 +46,11 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf let tenant: string | undefined; if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { - tenant = await fetchCurrentTenant(coreStart.http); + try { + tenant = await fetchCurrentTenant(coreStart.http); + } catch (e) { + console.log(e); + } } else { tenant = accountInfo.user_requested_tenant; } diff --git a/public/apps/configuration/utils/tenant-utils.tsx b/public/apps/configuration/utils/tenant-utils.tsx index 590fb22a7..606ba2fa7 100644 --- a/public/apps/configuration/utils/tenant-utils.tsx +++ b/public/apps/configuration/utils/tenant-utils.tsx @@ -15,6 +15,8 @@ import { HttpStart } from 'opensearch-dashboards/public'; import { map } from 'lodash'; +import React from 'react'; +import { i18n } from '@osd/i18n'; import { API_ENDPOINT_TENANTS, API_ENDPOINT_MULTITENANCY, @@ -39,6 +41,8 @@ export const globalTenantName = 'global_tenant'; export const GLOBAL_TENANT = ''; export const PRIVATE_TENANT = '__user__'; export const DEFAULT_TENANT = 'default'; +export const GLOBAL_TENANT_RENDERING_TEXT = 'Global'; +export const PRIVATE_TENANT_RENDERING_TEXT = 'Private'; export const GLOBAL_USER_DICT: { [key: string]: string } = { Label: 'Global', Value: GLOBAL_TENANT, @@ -181,3 +185,25 @@ export function isPrivateTenant(selectedTenant: string | null) { export function isGlobalTenant(selectedTenant: string | null) { return selectedTenant !== null && selectedTenant === GLOBAL_TENANT; } + +export const tenantColumn = { + id: 'tenant_column', + euiColumn: { + field: 'namespaces', + name:
Tenant
, + dataType: 'string', + render: (value: any[][]) => { + let text = value.flat()[0]; + if (isGlobalTenant(text)) { + text = GLOBAL_TENANT_RENDERING_TEXT; + } else if (isPrivateTenant(text)) { + text = PRIVATE_TENANT_RENDERING_TEXT; + } + text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', { + defaultMessage: text, + }); + return
{text}
; + }, + }, + loadData: () => {}, +}; diff --git a/public/plugin.tsx b/public/plugin.ts similarity index 86% rename from public/plugin.tsx rename to public/plugin.ts index 89f837179..2adb33a83 100644 --- a/public/plugin.tsx +++ b/public/plugin.ts @@ -15,8 +15,6 @@ import { BehaviorSubject } from 'rxjs'; import { SavedObjectsManagementColumn } from 'src/plugins/saved_objects_management/public'; -import React from 'react'; -import { i18n } from '@osd/i18n'; import { AppMountParameters, AppStatus, @@ -48,7 +46,7 @@ import { } from './types'; import { addTenantToShareURL } from './services/shared-link'; import { interceptError } from './utils/logout-utils'; -import { isGlobalTenant, isPrivateTenant } from './apps/configuration/utils/tenant-utils'; +import { tenantColumn } from './apps/configuration/utils/tenant-utils'; async function hasApiPermission(core: CoreSetup): Promise { try { @@ -156,27 +154,9 @@ export class SecurityPlugin ); if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) { - deps.savedObjectsManagement.columns.register(({ - id: 'tenant_column', - euiColumn: { - field: 'namespaces', - name:
Tenant
, - dataType: 'string', - render: (value: any[][]) => { - let text = value.flat()[0]; - if (isGlobalTenant(text)) { - text = GLOBAL_TENANT_RENDERING_TEXT; - } else if (isPrivateTenant(text)) { - text = PRIVATE_TENANT_RENDERING_TEXT; - } - text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', { - defaultMessage: text, - }); - return
{text}
; - }, - }, - loadData: () => {}, - } as unknown) as SavedObjectsManagementColumn); + deps.savedObjectsManagement.columns.register( + (tenantColumn as unknown) as SavedObjectsManagementColumn + ); } // Return methods that should be available to other plugins