Skip to content

Commit

Permalink
Fleet privileges display fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-shostak committed Dec 16, 2024
1 parent bc5c097 commit 1d425b3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const FeatureTableExpandedRow = ({
onChange={(updatedPrivileges) => onChange(feature.id, updatedPrivileges)}
selectedFeaturePrivileges={selectedFeaturePrivileges}
disabled={disabled || !isCustomizing || isDisabledDueToSpaceSelection}
allSpacesSelected={allSpacesSelected}
/>
</EuiFlexItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Props {
onChange: (selectedPrivileges: string[]) => void;
disabled?: boolean;
categoryId?: string;
allSpacesSelected?: boolean;
}

export const SubFeatureForm = (props: Props) => {
Expand Down Expand Up @@ -157,12 +158,18 @@ export const SubFeatureForm = (props: Props) => {
privilegeGroup: SubFeaturePrivilegeGroup,
index: number
) {
const nonePrivilege = {
id: NO_PRIVILEGE_VALUE,
label: 'None',
isDisabled: props.disabled,
};

const firstSelectedPrivilege =
props.privilegeCalculator.getSelectedMutuallyExclusiveSubFeaturePrivilege(
props.featureId,
privilegeGroup,
props.privilegeIndex
);
) ?? nonePrivilege;

const options = [
...privilegeGroup.privileges.map((privilege, privilegeIndex) => {
Expand All @@ -174,11 +181,12 @@ export const SubFeatureForm = (props: Props) => {
}),
];

options.push({
id: NO_PRIVILEGE_VALUE,
label: 'None',
isDisabled: props.disabled,
});
options.push(nonePrivilege);

const idSelected =
props.subFeature.requireAllSpaces && !props.allSpacesSelected
? nonePrivilege.id
: firstSelectedPrivilege.id;

return (
<EuiButtonGroup
Expand All @@ -187,7 +195,7 @@ export const SubFeatureForm = (props: Props) => {
data-test-subj="mutexSubFeaturePrivilegeControl"
isFullWidth
options={options}
idSelected={firstSelectedPrivilege?.id ?? NO_PRIVILEGE_VALUE}
idSelected={idSelected}
isDisabled={props.disabled}
onChange={(selectedPrivilegeId: string) => {
// Deselect all privileges which belong to this mutually-exclusive group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { EffectiveFeaturePrivileges } from './privilege_summary_calculator'
interface Props {
feature: SecuredFeature;
effectiveFeaturePrivileges: Array<EffectiveFeaturePrivileges['featureId']>;
isAllSpacesSelected: boolean;
}

export const PrivilegeSummaryExpandedRow = (props: Props) => {
Expand All @@ -37,7 +38,9 @@ export const PrivilegeSummaryExpandedRow = (props: Props) => {
{props.effectiveFeaturePrivileges.map((privs, index) => {
return (
<EuiFlexItem key={index} data-test-subj={`entry-${index}`}>
{subFeature.getPrivilegeGroups().map(renderPrivilegeGroup(privs.subFeature))}
{subFeature
.getPrivilegeGroups()
.map(renderPrivilegeGroup(privs.subFeature, subFeature.requireAllSpaces))}
</EuiFlexItem>
);
})}
Expand All @@ -48,7 +51,10 @@ export const PrivilegeSummaryExpandedRow = (props: Props) => {
</EuiFlexGroup>
);

function renderPrivilegeGroup(effectiveSubFeaturePrivileges: string[]) {
function renderPrivilegeGroup(
effectiveSubFeaturePrivileges: string[],
requireAllSpaces: boolean
) {
return (privilegeGroup: SubFeaturePrivilegeGroup, index: number) => {
switch (privilegeGroup.groupType) {
case 'independent':
Expand All @@ -61,7 +67,8 @@ export const PrivilegeSummaryExpandedRow = (props: Props) => {
return renderMutuallyExclusivePrivilegeGroup(
effectiveSubFeaturePrivileges,
privilegeGroup,
index
index,
requireAllSpaces
);
default:
throw new Error(`Unsupported privilege group type: ${privilegeGroup.groupType}`);
Expand Down Expand Up @@ -112,11 +119,14 @@ export const PrivilegeSummaryExpandedRow = (props: Props) => {
function renderMutuallyExclusivePrivilegeGroup(
effectiveSubFeaturePrivileges: string[],
privilegeGroup: SubFeaturePrivilegeGroup,
index: number
index: number,
requireAllSpaces: boolean
) {
const firstSelectedPrivilege = privilegeGroup.privileges.find((p) =>
effectiveSubFeaturePrivileges.includes(p.id)
)?.name;
const isDisabledDueToSpaceSelection = requireAllSpaces && !props.isAllSpacesSelected;

const firstSelectedPrivilege = !isDisabledDueToSpaceSelection
? privilegeGroup.privileges.find((p) => effectiveSubFeaturePrivileges.includes(p.id))?.name
: null;

return (
<EuiFlexGroup gutterSize="s" key={index} data-test-subj="mutexPrivilege">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function showPrivilege(allSpacesSelected: boolean, primaryFeature?: PrimaryFeatu
if (
primaryFeature?.name == null ||
primaryFeature?.disabled ||
(primaryFeature.requireAllSpaces && !allSpacesSelected)
(primaryFeature?.requireAllSpaces && !allSpacesSelected)
) {
return 'None';
}
Expand Down Expand Up @@ -218,6 +218,8 @@ export const PrivilegeSummaryTable = (props: PrivilegeSummaryTableProps) => {
};
});

const isAllSpacesSelected = props.spaces.some((space) => space.id === ALL_SPACES_ID);

accordions.push(
<EuiAccordion
id={`privilegeSummaryFeatureCategory_${category.id}`}
Expand All @@ -242,6 +244,7 @@ export const PrivilegeSummaryTable = (props: PrivilegeSummaryTableProps) => {
<PrivilegeSummaryExpandedRow
feature={props.kibanaPrivileges.getSecuredFeature(featureId)}
effectiveFeaturePrivileges={Object.values(privileges).map((p) => p[featureId])}
isAllSpacesSelected={isAllSpacesSelected}
/>
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class SpaceAwarePrivilegeSection extends Component<Props, State> {
const viewMatrixButton = (
<PrivilegeSummary
role={this.props.role}
spaces={this.getDisplaySpaces()}
spaces={this.getSelectedSpaces()}
kibanaPrivileges={this.props.kibanaPrivileges}
canCustomizeSubFeaturePrivileges={this.props.canCustomizeSubFeaturePrivileges}
spacesApiUi={this.props.spacesApiUi}
Expand All @@ -240,6 +240,11 @@ export class SpaceAwarePrivilegeSection extends Component<Props, State> {
return [this.globalSpaceEntry, ...this.props.spaces];
};

private getSelectedSpaces = () =>
this.getDisplaySpaces().filter((space) =>
this.props.role.kibana.some((entry) => entry.spaces.includes(space.id))
);

private getAvailableSpaces = (includeSpacesFromPrivilegeIndex: number = -1) => {
const spacesToExclude = _.uniq(
_.flatten(
Expand Down

0 comments on commit 1d425b3

Please sign in to comment.