diff --git a/ui/app/components/wizard/features-selection.js b/ui/app/components/wizard/features-selection.js index be478aa62c87..615f701a4ee9 100644 --- a/ui/app/components/wizard/features-selection.js +++ b/ui/app/components/wizard/features-selection.js @@ -26,35 +26,33 @@ export default Component.extend({ }, hasSecretsPermission: computed(function() { - return this.permissions.hasPermission('sys/mounts/example', 'update'); + return this.permissions.hasPermission('sys/mounts/example', ['update']); }), hasAuthenticationPermission: computed(function() { - const canRead = this.permissions.hasPermission('sys/auth', 'read'); + const canRead = this.permissions.hasPermission('sys/auth', ['read']); const capabilities = ['update', 'sudo']; - const canUpdateOrCreate = capabilities.every(capability => { - return this.permissions.hasPermission('sys/auth/example', capability); - }); + const canUpdateOrCreate = this.permissions.hasPermission('sys/auth/example', capabilities); return canRead && canUpdateOrCreate; }), hasPoliciesPermission: computed(function() { - return this.permissions.hasPermission('sys/policies/acl', 'list'); + return this.permissions.hasPermission('sys/policies/acl', ['list']); }), hasReplicationPermission: computed(function() { const PATHS = ['sys/replication/performance/primary/enable', 'sys/replication/dr/primary/enable']; return PATHS.every(path => { - return this.permissions.hasPermission(path, 'update'); + return this.permissions.hasPermission(path, ['update']); }); }), hasToolsPermission: computed(function() { const PATHS = ['sys/wrapping/wrap', 'sys/wrapping/lookup', 'sys/wrapping/unwrap', 'sys/wrapping/rewrap']; return PATHS.every(path => { - return this.permissions.hasPermission(path, 'update'); + return this.permissions.hasPermission(path, ['update']); }); }), diff --git a/ui/app/services/permissions.js b/ui/app/services/permissions.js index d4fa0897b207..f838c62ab253 100644 --- a/ui/app/services/permissions.js +++ b/ui/app/services/permissions.js @@ -108,17 +108,23 @@ export default Service.extend({ } }, - hasPermission(pathName, capability) { + hasPermission(pathName, capabilities = []) { const path = this.pathNameWithNamespace(pathName); - if ( - this.canViewAll || - this.hasMatchingExactPath(path, capability) || - this.hasMatchingGlobPath(path, capability) - ) { + if (this.canViewAll) { return true; } - return false; + + if (capabilities.length) { + return capabilities.every(capability => { + if (this.hasMatchingExactPath(path, capability) || this.hasMatchingGlobPath(path, capability)) { + return true; + } + return false; + }); + } + + return this.hasMatchingExactPath(path) || this.hasMatchingGlobPath(path); }, hasMatchingExactPath(pathName, capability) { diff --git a/ui/tests/unit/services/permissions-test.js b/ui/tests/unit/services/permissions-test.js index 63bb0d47da3a..7e2e34d5c0e1 100644 --- a/ui/tests/unit/services/permissions-test.js +++ b/ui/tests/unit/services/permissions-test.js @@ -97,16 +97,16 @@ module('Unit | Service | permissions', function(hooks) { let service = this.owner.lookup('service:permissions'); service.set('exactPaths', PERMISSIONS_RESPONSE.data.exact_paths); service.set('globPaths', PERMISSIONS_RESPONSE.data.glob_paths); - assert.equal(service.hasPermission('bar/bee', 'create'), true); - assert.equal(service.hasPermission('baz/biz', 'read'), true); + assert.equal(service.hasPermission('bar/bee', ['create']), true); + assert.equal(service.hasPermission('baz/biz', ['read']), true); }); test('it returns false if a policy does not have the specified capabilities on a path', function(assert) { let service = this.owner.lookup('service:permissions'); service.set('exactPaths', PERMISSIONS_RESPONSE.data.exact_paths); service.set('globPaths', PERMISSIONS_RESPONSE.data.glob_paths); - assert.equal(service.hasPermission('bar/bee', 'delete'), false); - assert.equal(service.hasPermission('foo', 'create'), false); + assert.equal(service.hasPermission('bar/bee', ['delete']), false); + assert.equal(service.hasPermission('foo', ['create']), false); }); test('defaults to show all items when policy cannot be found', async function(assert) {