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

Support migrating from reserved feature privileges #68504

Merged
merged 3 commits into from
Jun 11, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,36 @@ export const createFeature = (
config: Pick<FeatureConfig, 'id' | 'name' | 'subFeatures' | 'reserved' | 'privilegesTooltip'> & {
excludeFromBaseAll?: boolean;
excludeFromBaseRead?: boolean;
privileges?: FeatureConfig['privileges'];
}
) => {
const { excludeFromBaseAll, excludeFromBaseRead, ...rest } = config;
const { excludeFromBaseAll, excludeFromBaseRead, privileges, ...rest } = config;
return new Feature({
icon: 'discoverApp',
navLinkId: 'discover',
app: [],
catalogue: [],
privileges: {
all: {
excludeFromBasePrivileges: excludeFromBaseAll,
savedObject: {
all: ['all-type'],
read: ['read-type'],
},
ui: ['read-ui', 'all-ui', `read-${config.id}`, `all-${config.id}`],
},
read: {
excludeFromBasePrivileges: excludeFromBaseRead,
savedObject: {
all: [],
read: ['read-type'],
},
ui: ['read-ui', `read-${config.id}`],
},
},
privileges:
privileges === null
? null
: {
all: {
excludeFromBasePrivileges: excludeFromBaseAll,
savedObject: {
all: ['all-type'],
read: ['read-type'],
},
ui: ['read-ui', 'all-ui', `read-${config.id}`, `all-${config.id}`],
},
read: {
excludeFromBasePrivileges: excludeFromBaseRead,
savedObject: {
all: [],
read: ['read-type'],
},
ui: ['read-ui', `read-${config.id}`],
},
},
...rest,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,88 @@ describe('FeatureTable', () => {
},
});
});

it('renders a description for features with only reserved privileges (omitting the primary feature controls)', () => {
const role = createRole([
{
spaces: ['foo'],
base: [],
feature: {},
},
]);
const reservedFeature = createFeature({
id: 'reserved_feature',
name: 'Reserved Feature',
privileges: null,
reserved: {
description: 'this is my reserved feature description',
privileges: [
{
id: 'priv_1',
privilege: {
api: [],
savedObject: { all: [], read: [] },
ui: [],
},
},
],
},
});

const { wrapper } = setup({
role,
features: [reservedFeature],
privilegeIndex: 0,
calculateDisplayedPrivileges: false,
canCustomizeSubFeaturePrivileges: false,
});

expect(findTestSubject(wrapper, 'reservedFeatureDescription').text()).toMatchInlineSnapshot(
`"this is my reserved feature description"`
);

expect(findTestSubject(wrapper, 'primaryFeaturePrivilegeControl')).toHaveLength(0);
});

it('renders renders the primary feature controls when both primary and reserved privileges are specified', () => {
const role = createRole([
{
spaces: ['foo'],
base: [],
feature: {},
},
]);
const reservedFeature = createFeature({
id: 'reserved_feature',
name: 'Reserved Feature with primary feature privileges',
reserved: {
description: 'this is my reserved feature description',
privileges: [
{
id: 'priv_1',
privilege: {
api: [],
savedObject: { all: [], read: [] },
ui: [],
},
},
],
},
});

const { displayedPrivileges, wrapper } = setup({
role,
features: [reservedFeature],
privilegeIndex: 0,
calculateDisplayedPrivileges: true,
canCustomizeSubFeaturePrivileges: false,
});

expect(findTestSubject(wrapper, 'reservedFeatureDescription')).toHaveLength(0);
expect(displayedPrivileges).toEqual({
reserved_feature: {
primaryFeaturePrivilege: 'none',
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,16 @@ export class FeatureTable extends Component<Props, State> {
render: (roleEntry: Role, record: TableRow) => {
const { feature } = record;

if (feature.reserved) {
return <EuiText size={'s'}>{feature.reserved.description}</EuiText>;
}

const primaryFeaturePrivileges = feature.getPrimaryFeaturePrivileges();

if (feature.reserved && primaryFeaturePrivileges.length === 0) {
return (
<EuiText size={'s'} data-test-subj="reservedFeatureDescription">
{feature.reserved.description}
</EuiText>
);
}

if (primaryFeaturePrivileges.length === 0) {
return null;
}
Expand Down