From f8f7831cc3bb3beaf3341ef48621002d8eeab6d6 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 2 Sep 2021 15:00:44 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20read=20capability?= =?UTF-8?q?=20and=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/core/translations/resources/en-us.yaml | 5 ++ ui/admin/app/templates/scopes/scope/edit.hbs | 36 ++++++++---- ui/admin/tests/acceptance/scopes/read-test.js | 55 +++++++++++++++++++ 3 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 ui/admin/tests/acceptance/scopes/read-test.js diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 52bd07d03..4d373e26d 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -346,3 +346,8 @@ credential-library: help: The body of the HTTP request the library sends to Vault when requesting credentials. Only allowed when HTTP method is set to POST. types: vault: Vault +scope: + title: Scope + title_plural: Scopes + messages: + cannot_read: While you do not have permission to read this scope, you may have permission to view resources within it. diff --git a/ui/admin/app/templates/scopes/scope/edit.hbs b/ui/admin/app/templates/scopes/scope/edit.hbs index 648a03111..d8f6dc683 100644 --- a/ui/admin/app/templates/scopes/scope/edit.hbs +++ b/ui/admin/app/templates/scopes/scope/edit.hbs @@ -28,13 +28,15 @@ - - - - {{t 'titles.details'}} - - - + {{#if (can 'read model' @model)}} + + + + {{t 'titles.details'}} + + + + {{/if}} {{#if (can 'delete model' @model)}} @@ -59,11 +61,21 @@ {{/if}} - + {{#if (can 'read model' @model)}} + + {{else}} + + + + {{t 'resources.scope.messages.cannot_read'}} + + + + {{/if}} \ No newline at end of file diff --git a/ui/admin/tests/acceptance/scopes/read-test.js b/ui/admin/tests/acceptance/scopes/read-test.js new file mode 100644 index 000000000..1ddd1e5a4 --- /dev/null +++ b/ui/admin/tests/acceptance/scopes/read-test.js @@ -0,0 +1,55 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | scopes | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + }; + const urls = { + orgScopeEdit: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + // Generate route URLs for resources + urls.orgScopeEdit = `/scopes/${instances.scopes.org.id}/edit`; + // Generate resource couner + authenticateSession({}); + }); + + test('visiting org scope edit', async function (assert) { + assert.expect(2); + await visit(urls.orgScopeEdit); + await a11yAudit(); + assert.equal(currentURL(), urls.orgScopeEdit); + assert.ok(find('main .rose-form')); + }); + + test('visiting org scope edit without read permission results in no form displayed', async function (assert) { + assert.expect(2); + instances.scopes.org.update({ authorized_actions: [] }); + await visit(urls.orgScopeEdit); + assert.equal(currentURL(), urls.orgScopeEdit); + assert.notOk(find('main .rose-form')); + }); +});