Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tenant tab when disabled via yaml #1960

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
83 changes: 48 additions & 35 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
name: 'Tenants',
href: buildUrl(ResourceType.tenants),
},
[ResourceType.tenantsManageTab]: {
name: 'TenantsManageTab',
href: buildUrl(ResourceType.tenantsManageTab),
},
[ResourceType.tenantsConfigureTab]: {
name: '',
href: buildUrl(ResourceType.tenantsConfigureTab),
Expand All @@ -88,22 +84,27 @@
},
};

const ROUTE_LIST = [
ROUTE_MAP.getStarted,
ROUTE_MAP[ResourceType.auth],
ROUTE_MAP[ResourceType.roles],
ROUTE_MAP[ResourceType.users],
ROUTE_MAP[ResourceType.serviceAccounts],
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.serviceAccounts],
ROUTE_MAP[ResourceType.permissions],
...(multitenancyEnabled ? [ROUTE_MAP[ResourceType.tenants]] : []),
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
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)
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
.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 @@ -155,21 +156,46 @@
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} />;

Check warning on line 174 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L172-L174

Added lines #L172 - L174 were not covered by tests
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;

Check warning on line 181 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L179-L181

Added lines #L179 - L181 were not covered by tests
}}
/>
</>
);
}
return null;

Check warning on line 187 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L187

Added line #L187 was not covered by tests
}

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 @@ -267,27 +293,14 @@
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
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 @@

<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);

Check warning on line 295 in public/apps/configuration/panels/get-started.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/get-started.tsx#L294-L295

Added lines #L294 - L295 were not covered by tests
}}
>
Manage Multi-tenancy
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => {
window.location.href = buildHashUrl(ResourceType.tenantsConfigureTab);

Check warning on line 304 in public/apps/configuration/panels/get-started.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/get-started.tsx#L303-L304

Added lines #L303 - L304 were not covered by tests
}}
>
Configure Multi-tenancy
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiText>
</EuiPanel>
) : null}
</div>
<EuiGlobalToastList toasts={toasts} toastLifeTimeMs={10000} dismissToast={removeToast} />
</>
Expand Down

This file was deleted.

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.
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
</p>
<EuiButton
id="switchToConfigure"
Expand Down Expand Up @@ -129,10 +128,6 @@ export function TenantList(props: TenantListProps) {
));
};

if (!props.config.multitenancy.enabled) {
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
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
Loading
Loading