Skip to content

Update membership filter to use MEMBERSHIP_WHITELIST in Constants.js #2402

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

Merged
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
10 changes: 10 additions & 0 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
@@ -150,6 +150,16 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
{resource: 'services', group: ''},
{resource: 'statefulsets', group: 'apps'}
],
MEMBERSHIP_WHITELIST: [
"admin",
"basic-user",
"edit",
"system:deployer",
"system:image-builder",
"system:image-puller",
"system:image-pusher",
"view",
],
// TODO:
// This map can drive both the drawer & toast messages by
// updating it to the following format:
5 changes: 2 additions & 3 deletions app/scripts/services/membership/membership.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

angular
.module('openshiftConsole')
.factory('MembershipService', function($filter) {
.factory('MembershipService', function($filter, Constants) {

var annotation = $filter('annotation');

@@ -120,8 +120,7 @@ angular

var filterRoles = function(roles) {
return _.filter(roles, function(item) {
// system-only must be explicitly <string> 'true' to hide the annotation
return annotation(item, 'systemOnly') !== 'true';
return _.includes(Constants.MEMBERSHIP_WHITELIST, item.metadata.name);
});
};

8 changes: 5 additions & 3 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
@@ -712,6 +712,7 @@ group: ""
resource: "statefulsets",
group: "apps"
} ],
MEMBERSHIP_WHITELIST: [ "admin", "basic-user", "edit", "system:deployer", "system:image-builder", "system:image-puller", "system:image-pusher", "view" ],
EVENTS_TO_SHOW: {
FailedCreate: !0,
FailedDelete: !0,
@@ -2343,8 +2344,9 @@ t[e.tag] = t[e.tag] || {}, t[e.tag].name = e.tag, t[e.tag].status = angular.copy
}), t;
}
};
}), angular.module("openshiftConsole").factory("MembershipService", [ "$filter", function(e) {
var t = e("annotation"), n = function() {
}), angular.module("openshiftConsole").factory("MembershipService", [ "$filter", "Constants", function(e, t) {
e("annotation");
var n = function() {
return _.reduce(_.slice(arguments), function(e, t, n) {
return t ? _.isEqual(n, 0) ? t : e + "-" + t : e;
}, "");
@@ -2398,7 +2400,7 @@ return _.sortBy(e, "metadata.name");
},
filterRoles: function(e) {
return _.filter(e, function(e) {
return "true" !== t(e, "systemOnly");
return _.includes(t.MEMBERSHIP_WHITELIST, e.metadata.name);
});
},
mapRolesForUI: function(e, t) {
29 changes: 11 additions & 18 deletions test/spec/services/membership/membershipSpec.js
Original file line number Diff line number Diff line change
@@ -84,28 +84,21 @@ describe('MembershipService', function() {
});

describe('#filterRoles', function() {
it('should filter out system-only roles', function() {
// constants.js window.OPENSHIFT_CONSTANTS.MEMBERSHIP_WHITELIST
it('should filter out roles that do not exist in MEMBERSHIP_WHITELIST', function() {
var fakeList = [
// the string 'true' is the only acceptable value for 'authorization.openshift.io/system-only'
{metadata: {name: 'system-only-role', annotations: {'authorization.openshift.io/system-only': 'true'}}},
// the rest of these will not be filtered
{metadata: {name: 'system-only-role2', annotations: {'authorization.openshift.io/system-only': 'false'}}},
{metadata: {name: 'system-only-role3', annotations: {'authorization.openshift.io/system-only': 'show'}}},
{metadata: {name: 'system-only-role4', annotations: {'authorization.openshift.io/system-only': ''}}},
{metadata: {name: 'system-only-role5', annotations: {'authorization.openshift.io/system-only': undefined}}},
{metadata: {name: 'system-only-role6', annotations: {'authorization.openshift.io/system-only': null}}},
{metadata : {name : 'not-system-only'}},
{metadata : {name : 'the-other-not-system-only' }}
{metadata: {name: 'admin'}},
{metadata: {name: 'basic-user'}},
{metadata: {name: 'edit'}},
{metadata: {name: 'not-an-admin'}},
{metadata: {name: 'not-a-basic-user'}},
{metadata: {name: 'system-only-thing-that-does-secret-stuff'}}
];

expect(MembershipService.filterRoles(fakeList)).toEqual([
{metadata: {name: 'system-only-role2', annotations: {'authorization.openshift.io/system-only': 'false'}}},
{metadata: {name: 'system-only-role3', annotations: {'authorization.openshift.io/system-only': 'show'}}},
{metadata: {name: 'system-only-role4', annotations: {'authorization.openshift.io/system-only': ''}}},
{metadata: {name: 'system-only-role5', annotations: {'authorization.openshift.io/system-only': undefined}}},
{metadata: {name: 'system-only-role6', annotations: {'authorization.openshift.io/system-only': null}}},
{metadata : {name : 'not-system-only'}},
{metadata : {name : 'the-other-not-system-only' }}
{metadata: {name: 'admin'}},
{metadata: {name: 'basic-user'}},
{metadata: {name: 'edit'}}
]);
});
});