Skip to content

Commit

Permalink
[Backport 2.x] Remove tenant tab when disabled via yaml (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#1960) (opensearch-project#1965)

* Remove tenant tab when disabled via yaml (opensearch-project#1960)

---------

Signed-off-by: Derek Ho <[email protected]>

* Update snapshot

Signed-off-by: Derek Ho <[email protected]>

---------

Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho authored May 21, 2024
1 parent 6295ef3 commit 788fe2c
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress-test-tenancy-disabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ jobs:
git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test.git
cd opensearch-dashboards-functional-test
npm install cypress --save-dev
yarn cypress:run-with-security --browser chrome --spec "cypress/integration/plugins/security-dashboards-plugin/inaccessible_tenancy_features.js"
yarn cypress:run-with-security --browser chrome --spec "cypress/integration/plugins/security/inaccessible_tenancy_features.js"
81 changes: 47 additions & 34 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ const ROUTE_MAP: { [key: string]: RouteItem } = {
name: 'Tenants',
href: buildUrl(ResourceType.tenants),
},
[ResourceType.tenantsManageTab]: {
name: 'TenantsManageTab',
href: buildUrl(ResourceType.tenantsManageTab),
},
[ResourceType.tenantsConfigureTab]: {
name: '',
href: buildUrl(ResourceType.tenantsConfigureTab),
Expand All @@ -83,21 +79,26 @@ const ROUTE_MAP: { [key: string]: RouteItem } = {
},
};

const ROUTE_LIST = [
ROUTE_MAP.getStarted,
ROUTE_MAP[ResourceType.auth],
ROUTE_MAP[ResourceType.roles],
ROUTE_MAP[ResourceType.users],
ROUTE_MAP[ResourceType.permissions],
ROUTE_MAP[ResourceType.tenants],
ROUTE_MAP[ResourceType.auditLogging],
ROUTE_MAP[ResourceType.tenantsConfigureTab],
];
const getRouteList = (multitenancyEnabled: boolean) => {
return [
ROUTE_MAP.getStarted,
ROUTE_MAP[ResourceType.auth],
ROUTE_MAP[ResourceType.roles],
ROUTE_MAP[ResourceType.users],
ROUTE_MAP[ResourceType.permissions],
...(multitenancyEnabled ? [ROUTE_MAP[ResourceType.tenants]] : []),
ROUTE_MAP[ResourceType.auditLogging],
];
};

const allNavPanelUrls = ROUTE_LIST.map((route) => route.href).concat([
buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT,
buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT,
]);
export const allNavPanelUrls = (multitenancyEnabled: boolean) =>
getRouteList(multitenancyEnabled)
.map((route) => route.href)
.concat([
buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT,
buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT,
...(multitenancyEnabled ? [buildUrl(ResourceType.tenantsConfigureTab)] : []),
]);

export function getBreadcrumbs(
resourceType?: ResourceType,
Expand Down Expand Up @@ -149,21 +150,46 @@ export const LocalCluster = { label: 'Local cluster', id: '' };
export const DataSourceContext = createContext<DataSourceContextType | null>(null);

export function AppRouter(props: AppDependencies) {
const multitenancyEnabled = props.config.multitenancy.enabled;
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs);
const dataSourceFromUrl = dataSourceEnabled ? getDataSourceFromUrl() : LocalCluster;

const [dataSource, setDataSource] = useState<DataSourceOption>(dataSourceFromUrl);

function getTenancyRoutes() {
if (multitenancyEnabled) {
return (
<>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
</>
);
}
return null;
}

return (
<DataSourceContext.Provider value={{ dataSource, setDataSource }}>
<Router basename={props.params.appBasePath}>
<EuiPage>
{allNavPanelUrls.map((route) => (
{allNavPanelUrls(multitenancyEnabled).map((route) => (
// Create different routes to update the 'selected' nav item .
<Route key={route} path={route} exact>
<EuiPageSideBar>
<NavPanel items={ROUTE_LIST} />
<NavPanel items={getRouteList(multitenancyEnabled)} />
</EuiPageSideBar>
</Route>
))}
Expand Down Expand Up @@ -254,27 +280,14 @@ export function AppRouter(props: AppDependencies) {
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
setGlobalBreadcrumbs();
return <GetStarted {...props} />;
}}
/>
{getTenancyRoutes()}
<Redirect exact from="/" to={LANDING_PAGE_URL} />
</Switch>
</EuiPageBody>
Expand Down
68 changes: 35 additions & 33 deletions public/apps/configuration/panels/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,39 +276,41 @@ export function GetStarted(props: AppDependencies) {

<EuiSpacer size="l" />

<EuiPanel paddingSize="l">
<EuiTitle size="s">
<h3>Optional: Multi-tenancy</h3>
</EuiTitle>
<EuiText size="s" color="subdued">
<p>
By default tenancy is activated in Dashboards. Tenants in OpenSearch Dashboards are
spaces for saving index patterns, visualizations, dashboards, and other OpenSearch
Dashboards objects.
</p>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
<EuiButton
fill
onClick={() => {
window.location.href = buildHashUrl(ResourceType.tenants);
}}
>
Manage Multi-tenancy
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => {
window.location.href = buildHashUrl(ResourceType.tenantsConfigureTab);
}}
>
Configure Multi-tenancy
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiText>
</EuiPanel>
{props.config.multitenancy.enabled ? (
<EuiPanel paddingSize="l">
<EuiTitle size="s">
<h3>Optional: Multi-tenancy</h3>
</EuiTitle>
<EuiText size="s" color="subdued">
<p>
By default tenancy is activated in Dashboards. Tenants in OpenSearch Dashboards are
spaces for saving index patterns, visualizations, dashboards, and other OpenSearch
Dashboards objects.
</p>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
<EuiButton
fill
onClick={() => {
window.location.href = buildHashUrl(ResourceType.tenants);
}}
>
Manage Multi-tenancy
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => {
window.location.href = buildHashUrl(ResourceType.tenantsConfigureTab);
}}
>
Configure Multi-tenancy
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiText>
</EuiPanel>
) : null}
</div>
<EuiGlobalToastList toasts={toasts} toastLifeTimeMs={10000} dismissToast={removeToast} />
</>
Expand Down

This file was deleted.

9 changes: 2 additions & 7 deletions public/apps/configuration/panels/tenant-list/tenant-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { AppDependencies } from '../../../types';
import { ExternalLink } from '../../utils/display-utils';
import { DocLinks } from '../../constants';
import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils';
import { TenantInstructionView } from './tenant-instruction-view';
import { LocalCluster } from '../../app-router';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';

Expand Down Expand Up @@ -59,8 +58,8 @@ export function TenantList(props: TenantListProps) {
<>
<EuiCallOut title="Tenancy is disabled" color="warning" iconType="iInCircle">
<p>
Tenancy is currently disabled and users don&apos;t have access to this feature. To create,
edit tenants you must enabled tenanc throught he configure tenancy page.
Tenancy is currently disabled and users don&apos;t have access to this feature. Enable
tenancy through the configure tenancy page.
</p>
<EuiButton
id="switchToConfigure"
Expand Down Expand Up @@ -129,10 +128,6 @@ export function TenantList(props: TenantListProps) {
));
};

if (!props.config.multitenancy.enabled) {
return <TenantInstructionView />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { EuiInMemoryTable } from '@elastic/eui';
import { useDeleteConfirmState } from '../../../utils/delete-confirm-modal-utils';
import { Tenant } from '../../../types';
import { TenantEditModal } from '../edit-modal';
import { TenantInstructionView } from '../tenant-instruction-view';
import { getDashboardsInfo } from '../../../../../utils/dashboards-info-utils';

jest.mock('../../../utils/tenant-utils');
Expand Down Expand Up @@ -107,33 +106,6 @@ describe('Tenant list', () => {
expect(component.find(EuiInMemoryTable).prop('items').length).toBe(0);
});

it('renders when multitenancy is disabled in the opensearch_dashboards.yml', () => {
(getDashboardsInfo as jest.Mock).mockImplementation(() => {
return {
multitenancy_enabled: false,
private_tenant_enabled: true,
default_tenant: '',
};
});
const config1 = {
multitenancy: {
enabled: false,
tenants: {
enable_private: true,
},
},
};
const component = shallow(
<ManageTab
coreStart={mockCoreStart as any}
depsStart={{} as any}
params={{} as any}
config={config1 as any}
/>
);
expect(component.find(TenantInstructionView).length).toBe(0);
});

it('fetch data error', (done) => {
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
// Hide the error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ exports[`Get started (landing page) renders when backend configuration is disabl
<Memo()
config={
Object {
"multitenancy": Object {
"enabled": true,
},
"ui": Object {
"backend_configurable": false,
},
Expand Down Expand Up @@ -284,6 +287,9 @@ exports[`Get started (landing page) renders when backend configuration is enable
<Memo()
config={
Object {
"multitenancy": Object {
"enabled": true,
},
"ui": Object {
"backend_configurable": true,
},
Expand Down
Loading

0 comments on commit 788fe2c

Please sign in to comment.