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

Fixing dynamic tenancy changes for issues 1412 #1419

Merged
merged 5 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function AccountNavButton(props: {
}, [props.coreStart.http]);

// Check if the tenant modal should be shown on load
if (isMultiTenancyEnabled && getShouldShowTenantPopup()) {
if (isMultiTenancyEnabled && getShouldShowTenantPopup() && props.config.multitenancy.enabled) {
setShouldShowTenantPopup(false);
showTenantSwitchPanel();
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export function AccountNavButton(props: {
>
View roles and identities
</EuiButtonEmpty>
{isMultiTenancyEnabled && (
{isMultiTenancyEnabled && props.config.multitenancy.enabled && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be extracted as a class-level variable:

const { enabled: enabledInYmlConfig = true } = props.config?.multitenancy;

const shouldDisplaySwitchTenantsPanel = isMultiTenancyEnabled && enabledInYmlConfig;

and use the variable across the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarshitChanpura isMultiTenancyEnabled can change if we change the value of multitenancy_enabled in Security config. Therefore making a constant using it might not be the best idea.

<>
{horizontalRule}
<EuiButtonEmpty data-test-subj="switch-tenants" size="xs" onClick={showTenantSwitchPanel}>
Expand Down
2 changes: 1 addition & 1 deletion public/apps/account/test/account-nav-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ describe('Account navigation button, multitenancy disabled', () => {
currAuthType={'dummy'}
/>
);
expect(setState).toBeCalledTimes(1);
expect(setState).toBeCalledTimes(0);
});
});
4 changes: 0 additions & 4 deletions public/apps/configuration/panels/tenant-list/manage_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import { showTableStatusMessage } from '../../utils/loading-spinner-utils';
import { useContextMenuState } from '../../utils/context-menu';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also update the fetchDatat method to be:

const { http } = props.coreStart;

const fetchData = useCallback(async () => {
    try {
      setLoading(true);
      const rawTenantData = await fetchTenants(http);
      const processedTenantData = transformTenantData(rawTenantData);
      const activeTenant = await fetchCurrentTenant(http);
      const currentUser = await getCurrentUser(http);
      setCurrentUsername(currentUser);
      setCurrentTenant(resolveTenantName(activeTenant, currentUser));
      setTenantData(processedTenantData);
      const tenancyConfig = await getDashboardsInfo(http;
      setIsMultiTenancyEnabled tenancyConfig.multitenancy_enabled);
      setIsPrivateTenantEnabled(tenancyConfig.private_tenant_enabled);
      setDashboardsDefaultTenant(tenancyConfig.default_tenant);
    } catch (e) {
      console.log(e);
      setErrorFlag(true);
    } finally {
      setLoading(false);
    }
  }, [http]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do. Thanks.

import { generateResourceName } from '../../utils/resource-utils';
import { DocLinks } from '../../constants';
import { TenantInstructionView } from './tenant-instruction-view';
import { TenantList } from './tenant-list';
import { getBreadcrumbs, Route_MAP } from '../../app-router';
import { buildUrl } from '../../utils/url-builder';
Expand Down Expand Up @@ -479,9 +478,6 @@ export function ManageTab(props: AppDependencies) {
);
};

if (!props.config.multitenancy.enabled) {
return <TenantInstructionView />;
}
/* eslint-disable */
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ExternalLink } from '../../utils/display-utils';
import { displayBoolean } from '../../utils/display-utils';
import { DocLinks } from '../../constants';
import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils';
import { TenantInstructionView } from './tenant-instruction-view';

interface TenantListProps extends AppDependencies {
tabID: string;
Expand Down Expand Up @@ -127,6 +128,10 @@ export function TenantList(props: TenantListProps) {
));
};

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

return (
<>
<EuiPageHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Tenant list', () => {
config={config1 as any}
/>
);
expect(component.find(TenantInstructionView).length).toBe(1);
expect(component.find(TenantInstructionView).length).toBe(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, why we change the test case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changes the way manage tab would look when multitenancy.enabled is false. Hence the result will change. This is now same as before we merged our changes for dynamic tenancy config.

});

it('fetch data error', (done) => {
Expand Down