Allow reserved privileges to get their capabilities (#63698)

This commit is contained in:
Larry Gregory 2020-04-16 12:29:31 -04:00 committed by GitHub
parent 871f7209f9
commit d0b4ae7e29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -135,6 +135,42 @@ describe('populateUICapabilities', () => {
});
});
it(`supports capabilities from reserved privileges`, () => {
expect(
uiCapabilitiesForFeatures([
new Feature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
privileges: null,
reserved: {
description: '',
privileges: [
{
id: 'rp_1',
privilege: createFeaturePrivilege(['capability1', 'capability2']),
},
{
id: 'rp_2',
privilege: createFeaturePrivilege(['capability3', 'capability4', 'capability5']),
},
],
},
}),
])
).toEqual({
catalogue: {},
newFeature: {
capability1: true,
capability2: true,
capability3: true,
capability4: true,
capability5: true,
},
});
});
it(`supports merging features with sub privileges`, () => {
expect(
uiCapabilitiesForFeatures([

View file

@ -45,6 +45,9 @@ function getCapabilitiesFromFeature(feature: Feature): FeatureCapabilities {
...feature.subFeatures.map(sf => sf.privilegeGroups.map(pg => pg.privileges)).flat(2)
);
}
if (feature.reserved?.privileges) {
featurePrivileges.push(...feature.reserved.privileges.map(rp => rp.privilege));
}
featurePrivileges.forEach(privilege => {
UIFeatureCapabilities[feature.id] = {