Skip to content

Commit

Permalink
Fetches mds feature flag dynamically and updates missed components
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed May 17, 2024
1 parent 74e9661 commit 3aaf012
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
38 changes: 17 additions & 21 deletions public/apps/configuration/panels/auth-view/auth-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export function AuthView(props: AppDependencies) {
setDataSource={setDataSource}
selectedDataSource={dataSource}
/>
<EuiTitle size="l">
<h1>Authentication and authorization</h1>
</EuiTitle>
{errorFlag ? (
<AccessErrorComponent dataSourceLabel={dataSource && dataSource.label} />
) : (
Expand All @@ -80,32 +83,25 @@ export function AuthView(props: AppDependencies) {
setDataSource={setDataSource}
selectedDataSource={dataSource}
/>
<EuiPageHeader>
<EuiTitle size="l">
<h1>Authentication and authorization</h1>
</EuiTitle>
{!errorFlag && props.config.ui.backend_configurable && (
<ExternalLinkButton
href={DocLinks.BackendConfigurationDoc}
text="Manage via config.yml"
/>
)}
</EuiPageHeader>
{errorFlag ? (
<>
<EuiPageHeader>
<EuiTitle size="l">
<h1>Authentication and authorization</h1>
</EuiTitle>
</EuiPageHeader>
<AccessErrorComponent dataSourceLabel={dataSource && dataSource.label} />
</>
<AccessErrorComponent dataSourceLabel={dataSource && dataSource.label} />
) : (
<>
<EuiPageHeader>
<EuiTitle size="l">
<h1>Authentication and authorization</h1>
</EuiTitle>
{props.config.ui.backend_configurable && (
<ExternalLinkButton
href={DocLinks.BackendConfigurationDoc}
text="Manage via config.yml"
/>
)}
</EuiPageHeader>
/* @ts-ignore */
{/* @ts-ignore */}
<AuthenticationSequencePanel authc={authentication} loading={loading} />
<EuiSpacer size="m" />
/* @ts-ignore */
{/* @ts-ignore */}
<AuthorizationPanel authz={authorization} loading={loading} config={props.config} />
</>
)}
Expand Down
15 changes: 15 additions & 0 deletions public/apps/configuration/panels/tenant-list/configure_tab1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
} from '../../utils/toast-utils';
import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils';
import { LOCAL_CLUSTER_ID } from '../../../../../common';
import { AccessErrorComponent } from '../../../access-error-component';
import { LocalCluster } from '../../app-router';

export function ConfigureTab1(props: AppDependencies) {
const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = useState(false);
Expand All @@ -76,6 +78,7 @@ export function ConfigureTab1(props: AppDependencies) {

const [toasts, addToast, removeToast] = useToastState();
const [selectedComboBoxOptions, setSelectedComboBoxOptions] = useState();
const [errorFlag, setErrorFlag] = React.useState(false);

const discardChangesFunction = async () => {
await setUpdatedConfiguration(originalConfiguration);
Expand Down Expand Up @@ -195,9 +198,11 @@ export function ConfigureTab1(props: AppDependencies) {
const rawTenantData = await fetchTenants(props.coreStart.http, LOCAL_CLUSTER_ID);
const processedTenantData = transformTenantData(rawTenantData);
setTenantData(processedTenantData);
setErrorFlag(false);
} catch (e) {
// TODO: switch to better error display.
console.error(e);
setErrorFlag(true);
}
};
fetchData();
Expand Down Expand Up @@ -306,6 +311,16 @@ export function ConfigureTab1(props: AppDependencies) {
The private tenant is disabled. Select another default tenant.
</EuiText>
);

if (errorFlag) {
return (
<AccessErrorComponent
dataSourceLabel={LocalCluster.label}
message="You do not have permissions to configure tenancy"
/>
);
}

return (
<>
<EuiPageHeader />
Expand Down
10 changes: 10 additions & 0 deletions public/apps/configuration/panels/tenant-list/manage_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { LocalCluster, getBreadcrumbs } from '../../app-router';
import { buildUrl } from '../../utils/url-builder';
import { CrossPageToast } from '../../cross-page-toast';
import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils';
import { AccessErrorComponent } from '../../../access-error-component';

export function ManageTab(props: AppDependencies) {
const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs);
Expand Down Expand Up @@ -108,6 +109,7 @@ export function ManageTab(props: AppDependencies) {
setIsMultiTenancyEnabled(tenancyConfig.multitenancy_enabled);
setIsPrivateTenantEnabled(tenancyConfig.private_tenant_enabled);
setDashboardsDefaultTenant(tenancyConfig.default_tenant);
setErrorFlag(false);
} catch (e) {
console.log(e);
setErrorFlag(true);
Expand Down Expand Up @@ -484,6 +486,14 @@ export function ManageTab(props: AppDependencies) {
);
};

if (errorFlag) {
return (
<AccessErrorComponent
dataSourceLabel={LocalCluster.label}
message="You do not have permissions to manage tenants"
/>
);
}
/* eslint-disable */
return (
<>
Expand Down
5 changes: 2 additions & 3 deletions public/apps/configuration/panels/tenant-list/tenant-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export function TenantList(props: TenantListProps) {
React.useEffect(() => {
const fetchData = async () => {
try {
await setIsMultiTenancyEnabled(
(await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled
);
const dashboardsInfo = await getDashboardsInfo(props.coreStart.http);
setIsMultiTenancyEnabled(dashboardsInfo?.multitenancy_enabled || false);
} catch (e) {
console.log(e);
}
Expand Down
2 changes: 1 addition & 1 deletion public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class SecurityPlugin
deps: SecurityPluginSetupDependencies
): Promise<SecurityPluginSetup> {
const apiPermission = await hasApiPermission(core);
const mdsEnabled = true;
const mdsEnabled = !!deps.dataSource?.dataSourceEnabled;

const config = this.initializerContext.config.get<ClientConfigType>();

Expand Down
2 changes: 1 addition & 1 deletion public/utils/test/datasource-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Tests datasource utils', () => {
'http://localhost:5601/app/security-dashboards-plugin?dataSource=%7B%22id%22%3A%22%22%2C%22label%22%3A%22Local+cluster%22%7D#/auth'
);
});

it('Tests getting the datasource from the url with undefined dataSource', () => {
const mockSearchUndefinedDataSource = '?dataSource=undefined';
Object.defineProperty(window, 'location', {
Expand Down

0 comments on commit 3aaf012

Please sign in to comment.