Skip to content
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
15 changes: 14 additions & 1 deletion public/apps/account/tenant-switch-panel.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const CUSTOM_TENANT_RADIO_ID = 'custom';
export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
const [tenants, setTenants] = React.useState<string[]>([]);
const [username, setUsername] = React.useState<string>('');
const [roles, setRoles] = React.useState<string[]>([]);
const [errorCallOut, setErrorCallOut] = React.useState<string>('');
const [tenantSwitchRadioIdSelected, setTenantSwitchRadioIdSelected] = React.useState<string>();
const [selectedCustomTenantOption, setSelectedCustomTenantOption] = React.useState<
Expand All @@ -81,6 +82,8 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
const fetchData = async () => {
try {
const accountInfo = await fetchAccountInfo(props.coreStart.http);
setRoles(accountInfo.data.roles);

const tenantsInfo = accountInfo.data.tenants || {};
setTenants(keys(tenantsInfo));

Expand Down Expand Up @@ -118,6 +121,12 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
const isGlobalEnabled = props.config.multitenancy.tenants.enable_global;
const isPrivateEnabled = props.config.multitenancy.tenants.enable_private;

const DEFAULT_READONLY_ROLES = ['kibana_read_only'];
const readonly = roles.some(
(role) =>
props.config.readonly_mode?.roles.includes(role) || DEFAULT_READONLY_ROLES.includes(role)
);

const shouldDisableGlobal = !isGlobalEnabled || !tenants.includes(GLOBAL_TENANT_KEY_NAME);
const getGlobalDisabledInstruction = () => {
if (!isGlobalEnabled) {
Expand All @@ -130,7 +139,7 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
};

// The key for private tenant is the user name.
const shouldDisablePrivate = !isPrivateEnabled || !tenants.includes(username);
const shouldDisablePrivate = !isPrivateEnabled || !tenants.includes(username) || readonly;
const getPrivateDisabledInstruction = () => {
if (!isPrivateEnabled) {
return 'Contact the administrator to enable private tenant.';
Expand All @@ -139,6 +148,10 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
if (!tenants.includes(username)) {
return 'Contact the administrator to get access to private tenant.';
}

if (readonly) {
return 'Your account has read-only privileges only, using the private tenant is not possible.';
}
};

// Tenant switch radios related.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,231 @@ exports[`Account menu -tenant switch panel confirm button and renders renders wh
</EuiModal>
</EuiOverlayMask>
`;

exports[`Account menu -tenant switch panel confirm button and renders renders when user has default read only role 1`] = `
<EuiOverlayMask>
<EuiModal
data-test-subj="tenant-switch-modal"
onClose={[MockFunction]}
>
<EuiSpacer />
<EuiModalBody>
<EuiTitle>
<h4>
Select your tenant
</h4>
</EuiTitle>
<EuiSpacer />
<EuiText
color="subdued"
size="s"
>
Tenants are useful for safely sharing your work with other OpenSearch Dashboards users. You can switch your tenant anytime by clicking the user avatar on top right.
</EuiText>
<EuiSpacer />
<EuiRadioGroup
data-test-subj="tenant-switch-radios"
name="tenantSwitchRadios"
onChange={[Function]}
options={
Array [
Object {
"disabled": false,
"id": "global",
"label": <React.Fragment>
Global
<EuiText
size="s"
>
The global tenant is shared between every OpenSearch Dashboards user.
</EuiText>
<EuiSpacer />
</React.Fragment>,
},
Object {
"disabled": true,
"id": "private",
"label": <React.Fragment>
Private
<EuiText
size="s"
>
The private tenant is exclusive to each user and can't be shared. You might use the private tenant for exploratory work.
</EuiText>
<i>
Your account has read-only privileges only, using the private tenant is not possible.
</i>
<EuiSpacer />
</React.Fragment>,
},
Object {
"disabled": false,
"id": "custom",
"label": <React.Fragment>
Choose from custom
</React.Fragment>,
},
]
}
/>
<EuiComboBox
async={false}
compressed={false}
fullWidth={false}
isClearable={true}
onChange={[Function]}
options={
Array [
Object {
"label": "tenant1",
},
]
}
selectedOptions={Array []}
singleSelection={
Object {
"asPlainText": true,
}
}
sortMatchesBy="none"
style={
Object {
"marginLeft": "24px",
}
}
/>
<EuiSpacer />
<EuiSpacer />
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
onClick={[MockFunction]}
>
Cancel
</EuiButtonEmpty>
<EuiButton
data-test-subj="confirm"
disabled={false}
fill={true}
onClick={[Function]}
>
Confirm
</EuiButton>
</EuiModalFooter>
</EuiModal>
</EuiOverlayMask>
`;

exports[`Account menu -tenant switch panel confirm button and renders renders when user has read only role 1`] = `
<EuiOverlayMask>
<EuiModal
data-test-subj="tenant-switch-modal"
onClose={[MockFunction]}
>
<EuiSpacer />
<EuiModalBody>
<EuiTitle>
<h4>
Select your tenant
</h4>
</EuiTitle>
<EuiSpacer />
<EuiText
color="subdued"
size="s"
>
Tenants are useful for safely sharing your work with other OpenSearch Dashboards users. You can switch your tenant anytime by clicking the user avatar on top right.
</EuiText>
<EuiSpacer />
<EuiRadioGroup
data-test-subj="tenant-switch-radios"
name="tenantSwitchRadios"
onChange={[Function]}
options={
Array [
Object {
"disabled": false,
"id": "global",
"label": <React.Fragment>
Global
<EuiText
size="s"
>
The global tenant is shared between every OpenSearch Dashboards user.
</EuiText>
<EuiSpacer />
</React.Fragment>,
},
Object {
"disabled": true,
"id": "private",
"label": <React.Fragment>
Private
<EuiText
size="s"
>
The private tenant is exclusive to each user and can't be shared. You might use the private tenant for exploratory work.
</EuiText>
<i>
Your account has read-only privileges only, using the private tenant is not possible.
</i>
<EuiSpacer />
</React.Fragment>,
},
Object {
"disabled": false,
"id": "custom",
"label": <React.Fragment>
Choose from custom
</React.Fragment>,
},
]
}
/>
<EuiComboBox
async={false}
compressed={false}
fullWidth={false}
isClearable={true}
onChange={[Function]}
options={
Array [
Object {
"label": "tenant1",
},
]
}
selectedOptions={Array []}
singleSelection={
Object {
"asPlainText": true,
}
}
sortMatchesBy="none"
style={
Object {
"marginLeft": "24px",
}
}
/>
<EuiSpacer />
<EuiSpacer />
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
onClick={[MockFunction]}
>
Cancel
</EuiButtonEmpty>
<EuiButton
data-test-subj="confirm"
disabled={false}
fill={true}
onClick={[Function]}
>
Confirm
</EuiButton>
</EuiModalFooter>
</EuiModal>
</EuiOverlayMask>
`;
Loading