From 119cbbe815130de6c79570abb98029ca6aaa30c8 Mon Sep 17 00:00:00 2001 From: dharini Date: Wed, 11 Aug 2021 13:51:18 -0700 Subject: [PATCH 01/18] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20user=20capabilitie?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/factories/user.js | 8 ++ ui/admin/app/components/form/user/index.hbs | 16 +-- .../templates/scopes/scope/users/index.hbs | 8 +- .../scopes/scope/users/user/-actions.hbs | 34 +++--- ui/admin/tests/acceptance/users-test.js | 107 ------------------ .../tests/acceptance/users/delete-test.js | 86 ++++++++++++++ ui/admin/tests/acceptance/users/read-test.js | 56 +++++++++ .../tests/acceptance/users/update-test.js | 94 +++++++++++++++ yarn.lock | 27 +---- 9 files changed, 281 insertions(+), 155 deletions(-) create mode 100644 ui/admin/tests/acceptance/users/delete-test.js create mode 100644 ui/admin/tests/acceptance/users/read-test.js create mode 100644 ui/admin/tests/acceptance/users/update-test.js diff --git a/addons/api/mirage/factories/user.js b/addons/api/mirage/factories/user.js index 39c5abf96..00c6e8639 100644 --- a/addons/api/mirage/factories/user.js +++ b/addons/api/mirage/factories/user.js @@ -1,5 +1,13 @@ import factory from '../generated/factories/user'; +import permissions from '../helpers/permissions'; export default factory.extend({ + authorized_actions: () => + permissions.authorizedActionsFor('account') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], id: (i) => `user-${i}`, }); diff --git a/ui/admin/app/components/form/user/index.hbs b/ui/admin/app/components/form/user/index.hbs index a0c3230ef..39571b820 100644 --- a/ui/admin/app/components/form/user/index.hbs +++ b/ui/admin/app/components/form/user/index.hbs @@ -45,12 +45,12 @@ {{/if}} - - - + {{#if (can 'save model' @model)}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/users/index.hbs b/ui/admin/app/templates/scopes/scope/users/index.hbs index 5d44a46b0..ab31bc1cf 100644 --- a/ui/admin/app/templates/scopes/scope/users/index.hbs +++ b/ui/admin/app/templates/scopes/scope/users/index.hbs @@ -37,9 +37,13 @@ {{#each @model as |user|}} - + {{#if (can 'read model' user)}} + + {{user.displayName}} + + {{else}} {{user.displayName}} - + {{/if}}

{{user.description}}

diff --git a/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs b/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs index 0947bef21..4f993d425 100644 --- a/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/users/user/-actions.hbs @@ -1,17 +1,19 @@ - - - {{t 'resources.user.actions.add-accounts'}} - - - - {{t 'resources.user.actions.delete'}} - - \ No newline at end of file + + {{t 'resources.user.actions.add-accounts'}} + + + + {{t 'resources.user.actions.delete'}} + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/tests/acceptance/users-test.js b/ui/admin/tests/acceptance/users-test.js index 065f8974b..b047a0d2a 100644 --- a/ui/admin/tests/acceptance/users-test.js +++ b/ui/admin/tests/acceptance/users-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { visit, currentURL, click, fillIn, 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 { Response } from 'miragejs'; import { authenticateSession, @@ -17,7 +16,6 @@ module('Acceptance | users', function (hooks) { let orgScope; let usersURL; - let userURL; let newUserURL; hooks.beforeEach(function () { @@ -29,31 +27,12 @@ module('Acceptance | users', function (hooks) { 'withChildren' ); - const user = this.server.create('user', { - scope: orgScope, - }); - usersURL = `/scopes/${orgScope.id}/users`; - userURL = `${usersURL}/${user.id}`; newUserURL = `${usersURL}/new`; authenticateSession({}); }); - test('visiting users', async function (assert) { - assert.expect(1); - await visit(usersURL); - await a11yAudit(); - assert.equal(currentURL(), usersURL); - }); - - test('visiting a user', async function (assert) { - assert.expect(1); - await visit(newUserURL); - await a11yAudit(); - assert.equal(currentURL(), newUserURL); - }); - test('can create new users', async function (assert) { assert.expect(1); const usersCount = this.server.db.users.length; @@ -108,90 +87,4 @@ module('Acceptance | users', function (hooks) { 'Displays field-level errors.' ); }); - - test('can save changes to an existing user', async function (assert) { - assert.expect(2); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated user name'); - await click('.rose-form-actions [type="submit"]'); - assert.equal(currentURL(), userURL); - assert.equal(this.server.db.users[0].name, 'Updated user name'); - }); - - test('can cancel changes to an existing user', async function (assert) { - assert.expect(1); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Unsaved user name'); - await click('.rose-form-actions [type="button"]'); - assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); - }); - - test('can delete an user', async function (assert) { - assert.expect(1); - const usersCount = this.server.db.users.length; - await visit(userURL); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(this.server.db.users.length, usersCount - 1); - }); - - test('saving an existing user with invalid fields displays error messages', async function (assert) { - assert.expect(2); - this.server.patch('/users/:id', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid.', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(userURL); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'User name'); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.', - 'Displays primary error message.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.', - 'Displays field-level errors.' - ); - }); - - test('errors are displayed when user deletion fails', async function (assert) { - assert.expect(1); - this.server.del('/users/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(userURL); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'Oops.', - 'Displays primary error message.' - ); - }); }); diff --git a/ui/admin/tests/acceptance/users/delete-test.js b/ui/admin/tests/acceptance/users/delete-test.js new file mode 100644 index 000000000..45933206a --- /dev/null +++ b/ui/admin/tests/acceptance/users/delete-test.js @@ -0,0 +1,86 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | users', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + let userURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + + instances.user = this.server.create('user', { + scope: orgScope, + }); + //instances.user = this.server.schema.users.all().models[0]; + usersURL = `/scopes/${orgScope.id}/users`; + userURL = `${usersURL}/${instances.user.id}`; + + authenticateSession({}); + }); + + test('can delete an user', async function (assert) { + assert.expect(1); + const usersCount = this.server.db.users.length; + await visit(userURL); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(this.server.db.users.length, usersCount - 1); + }); + + test('cannot delete a user without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'delete'); + await visit(userURL); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('errors are displayed when user deletion fails', async function (assert) { + assert.expect(1); + this.server.del('/users/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(userURL); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/users/read-test.js b/ui/admin/tests/acceptance/users/read-test.js new file mode 100644 index 000000000..551cf96f6 --- /dev/null +++ b/ui/admin/tests/acceptance/users/read-test.js @@ -0,0 +1,56 @@ +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 | users', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + instances.user = this.server.create('user', { + scope: orgScope, + }); + usersURL = `/scopes/${orgScope.id}/users`; + authenticateSession({}); + }); + + test('visiting users', async function (assert) { + assert.expect(1); + await visit(usersURL); + await a11yAudit(); + assert.equal(currentURL(), usersURL); + }); + + test('cannot navigate to an account form without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'read'); + await visit(usersURL); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); +}); diff --git a/ui/admin/tests/acceptance/users/update-test.js b/ui/admin/tests/acceptance/users/update-test.js new file mode 100644 index 000000000..eade03c6b --- /dev/null +++ b/ui/admin/tests/acceptance/users/update-test.js @@ -0,0 +1,94 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | users', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let orgScope; + let usersURL; + let userURL; + + hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + }, + 'withChildren' + ); + + const user = this.server.create('user', { + scope: orgScope, + }); + + usersURL = `/scopes/${orgScope.id}/users`; + userURL = `${usersURL}/${user.id}`; + + authenticateSession({}); + }); + test('can save changes to an existing user', async function (assert) { + assert.expect(2); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated user name'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), userURL); + assert.equal(this.server.db.users[0].name, 'Updated user name'); + }); + + test('can cancel changes to an existing user', async function (assert) { + assert.expect(1); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Unsaved user name'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); + }); + + test('saving an existing user with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.patch('/users/:id', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(userURL); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'User name'); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.', + 'Displays primary error message.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.', + 'Displays field-level errors.' + ); + }); +}); diff --git a/yarn.lock b/yarn.lock index e32eb765e..796961516 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7682,7 +7682,7 @@ debug@^3.0.0, debug@^3.0.1, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -12399,7 +12399,7 @@ import-lazy@^4.0.0: resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-4.0.0.tgz#e8eb627483a0a43da3c03f3e35548be5cb0cc153" integrity sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw== -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -14091,11 +14091,6 @@ lodash._baseflatten@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -14104,16 +14099,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*, lodash._bindcallback@^3.0.0: +lodash._bindcallback@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - lodash._createassigner@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11" @@ -14123,19 +14113,12 @@ lodash._createassigner@^3.0.0: lodash._isiterateecall "^3.0.0" lodash.restparam "^3.0.0" -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: +lodash._getnative@^3.0.0: version "3.9.1" resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= @@ -14353,7 +14336,7 @@ lodash.pick@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM= -lodash.restparam@*, lodash.restparam@^3.0.0: +lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= From e50ea4b555f2e295d3e6eab21407482f279585d2 Mon Sep 17 00:00:00 2001 From: dharini Date: Wed, 11 Aug 2021 14:39:05 -0700 Subject: [PATCH 02/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/components/form/user/index.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/admin/app/components/form/user/index.hbs b/ui/admin/app/components/form/user/index.hbs index 39571b820..7ed797846 100644 --- a/ui/admin/app/components/form/user/index.hbs +++ b/ui/admin/app/components/form/user/index.hbs @@ -45,6 +45,7 @@ {{/if}} + {{#if (can 'save model' @model)}} Date: Wed, 11 Aug 2021 16:38:20 -0700 Subject: [PATCH 03/18] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20group=20capabiliti?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/factories/group.js | 8 ++++++ ui/admin/app/components/form/group/index.hbs | 15 ++++++----- .../scopes/scope/groups/group/-actions.hbs | 16 ++++++----- .../templates/scopes/scope/groups/index.hbs | 11 ++++++-- yarn.lock | 27 ++++--------------- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/addons/api/mirage/factories/group.js b/addons/api/mirage/factories/group.js index 79b28cc2e..ab3c7a777 100644 --- a/addons/api/mirage/factories/group.js +++ b/addons/api/mirage/factories/group.js @@ -1,7 +1,15 @@ import factory from '../generated/factories/group'; import { trait } from 'ember-cli-mirage'; +import permissions from '../helpers/permissions'; export default factory.extend({ + authorized_actions: () => + permissions.authorizedActionsFor('account') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], id: (i) => `group-${i}`, /** diff --git a/ui/admin/app/components/form/group/index.hbs b/ui/admin/app/components/form/group/index.hbs index a0c3230ef..7ed797846 100644 --- a/ui/admin/app/components/form/group/index.hbs +++ b/ui/admin/app/components/form/group/index.hbs @@ -46,11 +46,12 @@ {{/if}} - - + {{#if (can 'save model' @model)}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs index c1a11742e..4a8b822fa 100644 --- a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs @@ -7,11 +7,13 @@ {{t 'resources.group.actions.add-members'}} - - {{t 'resources.group.actions.delete'}} - + {{#if (can 'delete model' @model)}} + + {{t 'resources.group.actions.delete'}} + + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/groups/index.hbs b/ui/admin/app/templates/scopes/scope/groups/index.hbs index 64abb45ad..cb59fde2e 100644 --- a/ui/admin/app/templates/scopes/scope/groups/index.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/index.hbs @@ -35,9 +35,16 @@ {{#each @model as |group|}} - + {{#if (can 'read model' group)}} + + {{group.displayName}} + + {{else}} {{group.displayName}} - + {{/if}}

{{group.description}}

diff --git a/yarn.lock b/yarn.lock index e32eb765e..796961516 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7682,7 +7682,7 @@ debug@^3.0.0, debug@^3.0.1, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -12399,7 +12399,7 @@ import-lazy@^4.0.0: resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-4.0.0.tgz#e8eb627483a0a43da3c03f3e35548be5cb0cc153" integrity sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw== -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -14091,11 +14091,6 @@ lodash._baseflatten@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -14104,16 +14099,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*, lodash._bindcallback@^3.0.0: +lodash._bindcallback@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - lodash._createassigner@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/lodash._createassigner/-/lodash._createassigner-3.1.1.tgz#838a5bae2fdaca63ac22dee8e19fa4e6d6970b11" @@ -14123,19 +14113,12 @@ lodash._createassigner@^3.0.0: lodash._isiterateecall "^3.0.0" lodash.restparam "^3.0.0" -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: +lodash._getnative@^3.0.0: version "3.9.1" resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= @@ -14353,7 +14336,7 @@ lodash.pick@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM= -lodash.restparam@*, lodash.restparam@^3.0.0: +lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= From dbc06a4e0adb5533e9ed3b2cde8074f84b59a74c Mon Sep 17 00:00:00 2001 From: dharini Date: Wed, 11 Aug 2021 17:33:54 -0700 Subject: [PATCH 04/18] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/tests/acceptance/groups-test.js | 101 ------------------ .../tests/acceptance/groups/delete-test.js | 85 +++++++++++++++ ui/admin/tests/acceptance/groups/read-test.js | 60 +++++++++++ .../tests/acceptance/groups/update-test.js | 100 +++++++++++++++++ 4 files changed, 245 insertions(+), 101 deletions(-) create mode 100644 ui/admin/tests/acceptance/groups/delete-test.js create mode 100644 ui/admin/tests/acceptance/groups/read-test.js create mode 100644 ui/admin/tests/acceptance/groups/update-test.js diff --git a/ui/admin/tests/acceptance/groups-test.js b/ui/admin/tests/acceptance/groups-test.js index 1dfb81a7c..38b95d60d 100644 --- a/ui/admin/tests/acceptance/groups-test.js +++ b/ui/admin/tests/acceptance/groups-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { visit, currentURL, click, fillIn, 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 { Response } from 'miragejs'; import { authenticateSession, @@ -44,20 +43,6 @@ module('Acceptance | groups', function (hooks) { urls.newGroup = `${urls.groups}/new`; }); - test('visiting groups', async function (assert) { - assert.expect(1); - await visit(urls.groups); - await a11yAudit(); - assert.equal(currentURL(), urls.groups); - }); - - test('visiting a group', async function (assert) { - assert.expect(1); - await visit(urls.newGroup); - await a11yAudit(); - assert.equal(currentURL(), urls.newGroup); - }); - test('can create new group', async function (assert) { assert.expect(1); const groupsCount = this.server.db.groups.length; @@ -112,90 +97,4 @@ module('Acceptance | groups', function (hooks) { 'Displays field-level errors.' ); }); - - test('can save changes to an existing group', async function (assert) { - assert.expect(2); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated admin group'); - await click('.rose-form-actions [type="submit"]'); - assert.equal(currentURL(), urls.group); - assert.equal(this.server.db.groups[0].name, 'Updated admin group'); - }); - - test('can cancel changes to an existing group', async function (assert) { - assert.expect(1); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'Updated admin group'); - await click('.rose-form-actions [type="button"]'); - assert.notEqual(find('[name="name"]').value, 'Updated admin group'); - }); - - test('can delete a group', async function (assert) { - assert.expect(1); - const groupsCount = this.server.db.groups.length; - await visit(urls.group); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(this.server.db.groups.length, groupsCount - 1); - }); - - test('saving an existing group with invalid fields displays error messages', async function (assert) { - assert.expect(2); - this.server.patch('/groups/:id', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid.', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(urls.group); - await click('form [type="button"]', 'Activate edit mode'); - await fillIn('[name="name"]', 'random string'); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.', - 'Displays primary error message.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.', - 'Displays field-level errors.' - ); - }); - - test('errors are displayed when delete project fails', async function (assert) { - assert.expect(1); - this.server.del('/groups/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(urls.group); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'Oops.', - 'Displays primary error message.' - ); - }); }); diff --git a/ui/admin/tests/acceptance/groups/delete-test.js b/ui/admin/tests/acceptance/groups/delete-test.js new file mode 100644 index 000000000..3d5fc8a09 --- /dev/null +++ b/ui/admin/tests/acceptance/groups/delete-test.js @@ -0,0 +1,85 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | groups', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + + test('can delete a group', async function (assert) { + assert.expect(1); + const groupsCount = this.server.db.groups.length; + await visit(urls.group); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(this.server.db.groups.length, groupsCount - 1); + }); + + test('cannot delete a group without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'delete'); + await visit(urls.group); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('errors are displayed when delete project fails', async function (assert) { + assert.expect(1); + this.server.del('/groups/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.group); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/groups/read-test.js b/ui/admin/tests/acceptance/groups/read-test.js new file mode 100644 index 000000000..384289df5 --- /dev/null +++ b/ui/admin/tests/acceptance/groups/read-test.js @@ -0,0 +1,60 @@ +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 | groups', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + + test('visiting a group', async function (assert) { + assert.expect(1); + await visit(urls.newGroup); + await a11yAudit(); + assert.equal(currentURL(), urls.newGroup); + }); + + test('cannot navigate to a group form without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'read'); + await visit(urls.group); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); +}); diff --git a/ui/admin/tests/acceptance/groups/update-test.js b/ui/admin/tests/acceptance/groups/update-test.js new file mode 100644 index 000000000..9f96aff06 --- /dev/null +++ b/ui/admin/tests/acceptance/groups/update-test.js @@ -0,0 +1,100 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | groups', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + group: null, + }; + const urls = { + orgScope: null, + groups: null, + group: null, + newGroup: null, + }; + + hooks.beforeEach(function () { + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.group = this.server.create('group', { + scope: instances.scopes.org, + }); + urls.groups = `/scopes/${instances.scopes.org.id}/groups`; + urls.group = `${urls.groups}/${instances.group.id}`; + urls.newGroup = `${urls.groups}/new`; + }); + test('can save changes to an existing group', async function (assert) { + assert.expect(2); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated admin group'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), urls.group); + assert.equal(this.server.db.groups[0].name, 'Updated admin group'); + }); + + test('can cancel changes to an existing group', async function (assert) { + assert.expect(1); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'Updated admin group'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(find('[name="name"]').value, 'Updated admin group'); + }); + + test('saving an existing group with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.patch('/groups/:id', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.group); + await click('form [type="button"]', 'Activate edit mode'); + await fillIn('[name="name"]', 'random string'); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.', + 'Displays primary error message.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.', + 'Displays field-level errors.' + ); + }); +}); From 84bb6403400586215a490faaa0167ca24c9ea651 Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 12 Aug 2021 08:29:28 -0700 Subject: [PATCH 05/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs index 4a8b822fa..253b39ab0 100644 --- a/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/group/-actions.hbs @@ -6,8 +6,8 @@ {{t 'resources.group.actions.add-members'}} - {{#if (can 'delete model' @model)}} + Date: Thu, 12 Aug 2021 11:22:20 -0700 Subject: [PATCH 06/18] update name --- addons/api/mirage/factories/group.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/api/mirage/factories/group.js b/addons/api/mirage/factories/group.js index ab3c7a777..1f7256543 100644 --- a/addons/api/mirage/factories/group.js +++ b/addons/api/mirage/factories/group.js @@ -4,7 +4,7 @@ import permissions from '../helpers/permissions'; export default factory.extend({ authorized_actions: () => - permissions.authorizedActionsFor('account') || [ + permissions.authorizedActionsFor('group') || [ 'no-op', 'read', 'update', From ee390a6fea992b436fe3f4d1c8333a98b285490e Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 12 Aug 2021 11:23:02 -0700 Subject: [PATCH 07/18] update name --- addons/api/mirage/factories/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/api/mirage/factories/user.js b/addons/api/mirage/factories/user.js index 00c6e8639..b8463506d 100644 --- a/addons/api/mirage/factories/user.js +++ b/addons/api/mirage/factories/user.js @@ -3,7 +3,7 @@ import permissions from '../helpers/permissions'; export default factory.extend({ authorized_actions: () => - permissions.authorizedActionsFor('account') || [ + permissions.authorizedActionsFor('user') || [ 'no-op', 'read', 'update', From 3fa6332ab47e73aae73022cf7b5df4640ccfa0da Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 12 Aug 2021 13:29:33 -0700 Subject: [PATCH 08/18] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/tests/acceptance/groups/update-test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ui/admin/tests/acceptance/groups/update-test.js b/ui/admin/tests/acceptance/groups/update-test.js index 9f96aff06..5fc463b9f 100644 --- a/ui/admin/tests/acceptance/groups/update-test.js +++ b/ui/admin/tests/acceptance/groups/update-test.js @@ -42,6 +42,7 @@ module('Acceptance | groups', function (hooks) { urls.group = `${urls.groups}/${instances.group.id}`; urls.newGroup = `${urls.groups}/new`; }); + test('can save changes to an existing group', async function (assert) { assert.expect(2); await visit(urls.group); @@ -52,6 +53,14 @@ module('Acceptance | groups', function (hooks) { assert.equal(this.server.db.groups[0].name, 'Updated admin group'); }); + test('cannot make changes an existing group without proper authorization', async function (assert) { + assert.expect(1); + instances.group.authorized_actions = + instances.group.authorized_actions.filter((item) => item !== 'update'); + await visit(urls.group); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); + test('can cancel changes to an existing group', async function (assert) { assert.expect(1); await visit(urls.group); From a1f428550deeab4bb4dcc03e8ac5cd2200619968 Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 12 Aug 2021 13:47:07 -0700 Subject: [PATCH 09/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/tests/acceptance/groups/update-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/groups/update-test.js b/ui/admin/tests/acceptance/groups/update-test.js index 5fc463b9f..f86d2f1c7 100644 --- a/ui/admin/tests/acceptance/groups/update-test.js +++ b/ui/admin/tests/acceptance/groups/update-test.js @@ -53,7 +53,7 @@ module('Acceptance | groups', function (hooks) { assert.equal(this.server.db.groups[0].name, 'Updated admin group'); }); - test('cannot make changes an existing group without proper authorization', async function (assert) { + test('cannot make changes to an existing group without proper authorization', async function (assert) { assert.expect(1); instances.group.authorized_actions = instances.group.authorized_actions.filter((item) => item !== 'update'); From 9abb540d7fbe935f16379bf021538f8126327cb4 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 16 Aug 2021 16:12:55 -0400 Subject: [PATCH 10/18] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20credential=20libra?= =?UTF-8?q?ry=20read/update/delete=20capabilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mirage/factories/credential-library.js | 9 ++ .../form/credential-library/index.hbs | 15 +- .../credential-library/-actions.hbs | 26 ++-- .../credential-libraries/index.hbs | 14 +- .../tests/acceptance/accounts/update-test.js | 10 +- .../acceptance/credential-libraries-test.js | 138 +++++++++++++++++ .../credential-library/delete-test.js | 131 ++++++++++++++++ .../credential-library/read-test.js | 80 ++++++++++ ...dential-library-test.js => update-test.js} | 145 ++---------------- 9 files changed, 413 insertions(+), 155 deletions(-) create mode 100644 ui/admin/tests/acceptance/credential-libraries-test.js create mode 100644 ui/admin/tests/acceptance/credential-library/delete-test.js create mode 100644 ui/admin/tests/acceptance/credential-library/read-test.js rename ui/admin/tests/acceptance/credential-library/{credential-library-test.js => update-test.js} (56%) diff --git a/addons/api/mirage/factories/credential-library.js b/addons/api/mirage/factories/credential-library.js index 06d8c4f6c..621ae6410 100644 --- a/addons/api/mirage/factories/credential-library.js +++ b/addons/api/mirage/factories/credential-library.js @@ -1,5 +1,6 @@ import factory from '../generated/factories/credential-library'; import { random, system } from 'faker'; +import permissions from '../helpers/permissions'; const types = ['vault']; @@ -7,6 +8,14 @@ export default factory.extend({ id: (i) => `credential-library-id-${i}`, type: (i) => types[i % types.length], + authorized_actions: () => + permissions.authorizedActionsFor('credential-library') || [ + 'no-op', + 'read', + 'update', + 'delete', + ], + attributes() { switch (this.type) { case 'vault': diff --git a/ui/admin/app/components/form/credential-library/index.hbs b/ui/admin/app/components/form/credential-library/index.hbs index 3e3add0ee..29d016e7c 100644 --- a/ui/admin/app/components/form/credential-library/index.hbs +++ b/ui/admin/app/components/form/credential-library/index.hbs @@ -118,10 +118,13 @@ {{/if}} - + {{#if (can 'save model' @model)}} + + {{/if}} + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs index 759b187d5..4399f847b 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs @@ -1,13 +1,15 @@ - - - {{t 'resources.credential-library.actions.delete'}} - - \ No newline at end of file + + {{t 'resources.credential-library.actions.delete'}} + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs index e97d52411..2bb3101c2 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs @@ -12,12 +12,16 @@ {{#each @model as |credentialLibrary|}} - + {{#if (can 'read model' credentialLibrary)}} + + {{credentialLibrary.displayName}} + + {{else}} {{credentialLibrary.displayName}} - + {{/if}}

{{credentialLibrary.description}}

diff --git a/ui/admin/tests/acceptance/accounts/update-test.js b/ui/admin/tests/acceptance/accounts/update-test.js index ecce31da0..163b7ac9e 100644 --- a/ui/admin/tests/acceptance/accounts/update-test.js +++ b/ui/admin/tests/acceptance/accounts/update-test.js @@ -59,7 +59,7 @@ module('Acceptance | accounts | update', function (hooks) { } }); - test('can update an account and save changes', async function (assert) { + test('can update resource and save changes', async function (assert) { assert.expect(1); await visit(urls.account); await click('form [type="button"]', 'Activate edit mode'); @@ -68,6 +68,14 @@ module('Acceptance | accounts | update', function (hooks) { assert.equal(this.server.db.accounts[0].name, 'update name'); }); + test('cannot update resource without proper authorization', async function (assert) { + assert.expect(1); + instances.account.authorized_actions = + instances.account.authorized_actions.filter((item) => item !== 'update'); + await visit(urls.account); + assert.notOk(find('form [type="button"]')); + }); + test('can update an account and cancel changes', async function (assert) { assert.expect(1); await visit(urls.account); diff --git a/ui/admin/tests/acceptance/credential-libraries-test.js b/ui/admin/tests/acceptance/credential-libraries-test.js new file mode 100644 index 000000000..d4dcce482 --- /dev/null +++ b/ui/admin/tests/acceptance/credential-libraries-test.js @@ -0,0 +1,138 @@ +import { module, test } from 'qunit'; +import { visit, click, fillIn, 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 } from 'ember-simple-auth/test-support'; +import { Response } from 'miragejs'; + +module('Acceptance | credential-libraries', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getCredentialLibraryCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: 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' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // Generate route URLs for resources + urls.globalScope = `/scopes/global/scopes`; + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; + urls.projectScope = `/scopes/${instances.scopes.project.id}`; + urls.credentialStores = `${urls.projectScope}/credential-stores`; + urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + // Generate resource counter + getCredentialLibraryCount = () => + this.server.schema.credentialLibraries.all().models.length; + authenticateSession({}); + }); + + test('visiting credential libraries', async function (assert) { + assert.expect(2); + await visit(urls.credentialLibraries); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibraries); + await visit(urls.credentialLibrary); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibrary); + }); + + test('visiting an unknown credential library displays 404 message', async function (assert) { + assert.expect(1); + await visit(urls.unknownCredentialLibrary); + await a11yAudit(); + console.debug(find('.rose-message-subtitle')); + assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); + }); + + test('can create a credential library', async function (assert) { + assert.expect(1); + const count = getCredentialLibraryCount(); + await visit(urls.newCredentialLibrary); + await fillIn('[name="name"]', 'random string'); + await click('[type="submit"]'); + assert.equal(getCredentialLibraryCount(), count + 1); + }); + + test('can cancel create a new credential library', async function (assert) { + assert.expect(2); + const count = getCredentialLibraryCount(); + await visit(urls.newCredentialLibrary); + await fillIn('[name="name"]', 'random string'); + await click('.rose-form-actions [type="button"]'); + assert.equal(currentURL(), urls.credentialLibraries); + assert.equal(getCredentialLibraryCount(), count); + }); + + test('saving a new credential library with invalid fields displays error messasges', async function (assert) { + assert.expect(2); + this.server.post('/credential-libraries', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.newCredentialLibrary); + await click('[type="submit"]'); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'The request was invalid.' + ); + assert.ok( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.' + ); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/delete-test.js b/ui/admin/tests/acceptance/credential-library/delete-test.js new file mode 100644 index 000000000..e539d00e9 --- /dev/null +++ b/ui/admin/tests/acceptance/credential-library/delete-test.js @@ -0,0 +1,131 @@ +import { module, test } from 'qunit'; +import { visit, click, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { authenticateSession } from 'ember-simple-auth/test-support'; +import { Response } from 'miragejs'; +import { resolve, reject } from 'rsvp'; +import sinon from 'sinon'; + +module('Acceptance | credential-libraries | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getCredentialLibraryCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: 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' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // Generate route URLs for resources + urls.globalScope = `/scopes/global/scopes`; + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; + urls.projectScope = `/scopes/${instances.scopes.project.id}`; + urls.credentialStores = `${urls.projectScope}/credential-stores`; + urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + // Generate resource counter + getCredentialLibraryCount = () => + this.server.schema.credentialLibraries.all().models.length; + authenticateSession({}); + }); + + test('can delete resource', async function (assert) { + assert.expect(1); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + }); + + test('cannot delete resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'delete' + ); + await visit(urls.credentialLibrary); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('can accept delete credential library via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(resolve()); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot cancel delete credential library via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(reject()); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('deleting a credential library which errors displays error messages', async function (assert) { + assert.expect(1); + this.server.del('/credential-libraries/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/read-test.js b/ui/admin/tests/acceptance/credential-library/read-test.js new file mode 100644 index 000000000..6e94637da --- /dev/null +++ b/ui/admin/tests/acceptance/credential-library/read-test.js @@ -0,0 +1,80 @@ +import { module, test } from 'qunit'; +import { visit, click, 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 } from 'ember-simple-auth/test-support'; + +module('Acceptance | credential-libraries | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + unknownCredentialLibrary: 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' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + credentialStore: instances.credentialStore, + }); + // Generate route URLs for resources + urls.globalScope = `/scopes/global/scopes`; + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; + urls.projectScope = `/scopes/${instances.scopes.project.id}`; + urls.credentialStores = `${urls.projectScope}/credential-stores`; + urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; + urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; + authenticateSession({}); + }); + + test('can navigate to resource', async function (assert) { + assert.expect(1); + await visit(urls.credentialLibraries); + await click('main tbody .rose-table-header-cell a'); + await a11yAudit(); + assert.equal(currentURL(), urls.credentialLibrary); + }); + + test('cannot navigate to resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'read' + ); + await visit(urls.credentialLibraries); + assert.notOk(find('main tbody .rose-table-header-cell a')); + }); +}); diff --git a/ui/admin/tests/acceptance/credential-library/credential-library-test.js b/ui/admin/tests/acceptance/credential-library/update-test.js similarity index 56% rename from ui/admin/tests/acceptance/credential-library/credential-library-test.js rename to ui/admin/tests/acceptance/credential-library/update-test.js index c2b71f8f1..7958ccc6f 100644 --- a/ui/admin/tests/acceptance/credential-library/credential-library-test.js +++ b/ui/admin/tests/acceptance/credential-library/update-test.js @@ -2,18 +2,13 @@ import { module, test } from 'qunit'; import { visit, click, fillIn, 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 } from 'ember-simple-auth/test-support'; import { Response } from 'miragejs'; -import { resolve, reject } from 'rsvp'; -import sinon from 'sinon'; -module('Acceptance | credential-library', function (hooks) { +module('Acceptance | credential-libraries | update', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - let getCredentialLibraryCount; - const instances = { scopes: { global: null, @@ -50,6 +45,7 @@ module('Acceptance | credential-library', function (hooks) { }); instances.credentialLibrary = this.server.create('credential-library', { scope: instances.scopes.project, + credentialStore: instances.credentialStore, }); // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; @@ -61,83 +57,10 @@ module('Acceptance | credential-library', function (hooks) { urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; urls.newCredentialLibrary = `${urls.credentialLibraries}/new`; urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`; - // Generate resource counter - getCredentialLibraryCount = () => - this.server.schema.credentialLibraries.all().models.length; authenticateSession({}); }); - test('visiting credential libraries', async function (assert) { - assert.expect(2); - await visit(urls.credentialLibraries); - await a11yAudit(); - assert.equal(currentURL(), urls.credentialLibraries); - await visit(urls.credentialLibrary); - await a11yAudit(); - assert.equal(currentURL(), urls.credentialLibrary); - }); - - test('visiting an unknown credential library displays 404 message', async function (assert) { - assert.expect(1); - await visit(urls.unknownCredentialLibrary); - await a11yAudit(); - console.debug(find('.rose-message-subtitle')); - assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); - }); - - test('can create a credential library', async function (assert) { - assert.expect(1); - const count = getCredentialLibraryCount(); - await visit(urls.newCredentialLibrary); - await fillIn('[name="name"]', 'random string'); - await click('[type="submit"]'); - assert.equal(getCredentialLibraryCount(), count + 1); - }); - - test('can cancel create a new credential library', async function (assert) { - assert.expect(2); - const count = getCredentialLibraryCount(); - await visit(urls.newCredentialLibrary); - await fillIn('[name="name"]', 'random string'); - await click('.rose-form-actions [type="button"]'); - assert.equal(currentURL(), urls.credentialLibraries); - assert.equal(getCredentialLibraryCount(), count); - }); - - test('saving a new credential library with invalid fields displays error messasges', async function (assert) { - assert.expect(2); - this.server.post('/credential-libraries', () => { - return new Response( - 400, - {}, - { - status: 400, - code: 'invalid_argument', - message: 'The request was invalid', - details: { - request_fields: [ - { - name: 'name', - description: 'Name is required.', - }, - ], - }, - } - ); - }); - await visit(urls.newCredentialLibrary); - await click('[type="submit"]'); - assert.ok( - find('[role="alert"]').textContent.trim(), - 'The request was invalid.' - ); - assert.ok( - find('.rose-form-error-message').textContent.trim(), - 'Name is required.' - ); - }); - - test('can save changes to existing credential library', async function (assert) { + test('can update resource and save changes', async function (assert) { assert.expect(3); assert.notEqual(instances.credentialLibrary.name, 'random string'); await visit(urls.credentialLibrary); @@ -151,7 +74,17 @@ module('Acceptance | credential-library', function (hooks) { ); }); - test('can cancel changes to existing credential library', async function (assert) { + test('cannot update resource without proper authorization', async function (assert) { + assert.expect(1); + instances.credentialLibrary.authorized_actions = + instances.credentialLibrary.authorized_actions.filter( + (item) => item !== 'update' + ); + await visit(urls.credentialLibrary); + assert.notOk(find('form [type="button"]')); + }); + + test('can update a credential library and cancel changes', async function (assert) { assert.expect(2); await visit(urls.credentialLibrary); await click('form [type="button"]', 'Activate edit mode'); @@ -245,54 +178,4 @@ module('Acceptance | credential-library', function (hooks) { ); } }); - - test('can delete credential library', async function (assert) { - assert.expect(1); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count - 1); - }); - - test('can accept delete credential library via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(resolve()); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count - 1); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('cannot cancel delete credential library via dialog', async function (assert) { - assert.expect(2); - const confirmService = this.owner.lookup('service:confirm'); - confirmService.enabled = true; - confirmService.confirm = sinon.fake.returns(reject()); - const count = getCredentialLibraryCount(); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.equal(getCredentialLibraryCount(), count); - assert.ok(confirmService.confirm.calledOnce); - }); - - test('deleting a credential library which errors displays error messages', async function (assert) { - assert.expect(1); - this.server.del('/credential-libraries/:id', () => { - return new Response( - 490, - {}, - { - status: 490, - code: 'error', - message: 'Oops.', - } - ); - }); - await visit(urls.credentialLibrary); - await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); - }); }); From 455b1a29b030cd894c2345db1da8e1524fe9bae3 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:06:34 -0700 Subject: [PATCH 11/18] Update delete-test.js --- ui/admin/tests/acceptance/groups/delete-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/groups/delete-test.js b/ui/admin/tests/acceptance/groups/delete-test.js index 3d5fc8a09..c1dec7fdb 100644 --- a/ui/admin/tests/acceptance/groups/delete-test.js +++ b/ui/admin/tests/acceptance/groups/delete-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | groups', function (hooks) { +module('Acceptance | groups | delete', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From 2cca6fe005af011a7e34dd042a14c21c6c005fa5 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:06:45 -0700 Subject: [PATCH 12/18] Update read-test.js --- ui/admin/tests/acceptance/groups/read-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/groups/read-test.js b/ui/admin/tests/acceptance/groups/read-test.js index 384289df5..535ea1175 100644 --- a/ui/admin/tests/acceptance/groups/read-test.js +++ b/ui/admin/tests/acceptance/groups/read-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | groups', function (hooks) { +module('Acceptance | groups | read', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From b0bd9b680806c812ea528ddaa96eb29d4d92fb2d Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:07:00 -0700 Subject: [PATCH 13/18] Update update-test.js --- ui/admin/tests/acceptance/groups/update-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/groups/update-test.js b/ui/admin/tests/acceptance/groups/update-test.js index f86d2f1c7..6d39cefbe 100644 --- a/ui/admin/tests/acceptance/groups/update-test.js +++ b/ui/admin/tests/acceptance/groups/update-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | groups', function (hooks) { +module('Acceptance | groups | update', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From a39752d1c9e60f02c3a57b7f4ce403f8bec15997 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:08:07 -0700 Subject: [PATCH 14/18] Update delete-test.js --- ui/admin/tests/acceptance/users/delete-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/users/delete-test.js b/ui/admin/tests/acceptance/users/delete-test.js index 45933206a..14b5371fc 100644 --- a/ui/admin/tests/acceptance/users/delete-test.js +++ b/ui/admin/tests/acceptance/users/delete-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | users', function (hooks) { +module('Acceptance | users | delete', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From 5284514a05158de64eaaac467f6aa1ad9e40df60 Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:08:19 -0700 Subject: [PATCH 15/18] Update read-test.js --- ui/admin/tests/acceptance/users/read-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/users/read-test.js b/ui/admin/tests/acceptance/users/read-test.js index 551cf96f6..93304220e 100644 --- a/ui/admin/tests/acceptance/users/read-test.js +++ b/ui/admin/tests/acceptance/users/read-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | users', function (hooks) { +module('Acceptance | users | read', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From 14d96a4a8aa3b9cb96738e8171e399d6c00943ec Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Mon, 16 Aug 2021 17:08:31 -0700 Subject: [PATCH 16/18] Update update-test.js --- ui/admin/tests/acceptance/users/update-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/users/update-test.js b/ui/admin/tests/acceptance/users/update-test.js index eade03c6b..3e0a4b18b 100644 --- a/ui/admin/tests/acceptance/users/update-test.js +++ b/ui/admin/tests/acceptance/users/update-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | users', function (hooks) { +module('Acceptance | users | update', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); From c2ffe19d442f9c8e9070114ae7a14e30d6b712e0 Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 16 Aug 2021 17:10:18 -0700 Subject: [PATCH 17/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/jsconfig.json | 1 + ui/admin/tests/acceptance/users/read-test.js | 1 + .../tests/acceptance/users/update-test.js | 20 +++++++++++++++++-- ui/desktop/jsconfig.json | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 ui/admin/jsconfig.json create mode 100644 ui/desktop/jsconfig.json diff --git a/ui/admin/jsconfig.json b/ui/admin/jsconfig.json new file mode 100644 index 000000000..f408cac8c --- /dev/null +++ b/ui/admin/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file diff --git a/ui/admin/tests/acceptance/users/read-test.js b/ui/admin/tests/acceptance/users/read-test.js index 551cf96f6..cd896bdc9 100644 --- a/ui/admin/tests/acceptance/users/read-test.js +++ b/ui/admin/tests/acceptance/users/read-test.js @@ -24,6 +24,7 @@ module('Acceptance | users', function (hooks) { }, user: null, }; + hooks.beforeEach(function () { orgScope = this.server.create( 'scope', diff --git a/ui/admin/tests/acceptance/users/update-test.js b/ui/admin/tests/acceptance/users/update-test.js index eade03c6b..3a5cba152 100644 --- a/ui/admin/tests/acceptance/users/update-test.js +++ b/ui/admin/tests/acceptance/users/update-test.js @@ -18,6 +18,14 @@ module('Acceptance | users', function (hooks) { let usersURL; let userURL; + const instances = { + scopes: { + global: null, + org: null, + }, + user: null, + }; + hooks.beforeEach(function () { orgScope = this.server.create( 'scope', @@ -27,12 +35,12 @@ module('Acceptance | users', function (hooks) { 'withChildren' ); - const user = this.server.create('user', { + instances.user = this.server.create('user', { scope: orgScope, }); usersURL = `/scopes/${orgScope.id}/users`; - userURL = `${usersURL}/${user.id}`; + userURL = `${usersURL}/${instances.user.id}`; authenticateSession({}); }); @@ -55,6 +63,14 @@ module('Acceptance | users', function (hooks) { assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); }); + test('cannot make changes to an existing user without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'update'); + await visit(userURL); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); + test('saving an existing user with invalid fields displays error messages', async function (assert) { assert.expect(2); this.server.patch('/users/:id', () => { diff --git a/ui/desktop/jsconfig.json b/ui/desktop/jsconfig.json new file mode 100644 index 000000000..f408cac8c --- /dev/null +++ b/ui/desktop/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file From a1c4d00eedc7fc20ca5f5cc62d910f568f775231 Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 16 Aug 2021 17:18:35 -0700 Subject: [PATCH 18/18] add test --- ui/admin/tests/acceptance/users/update-test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ui/admin/tests/acceptance/users/update-test.js b/ui/admin/tests/acceptance/users/update-test.js index 3a5cba152..b37a5bec2 100644 --- a/ui/admin/tests/acceptance/users/update-test.js +++ b/ui/admin/tests/acceptance/users/update-test.js @@ -54,6 +54,14 @@ module('Acceptance | users', function (hooks) { assert.equal(this.server.db.users[0].name, 'Updated user name'); }); + test('cannot make changes to an existing user without proper authorization', async function (assert) { + assert.expect(1); + instances.user.authorized_actions = + instances.user.authorized_actions.filter((item) => item !== 'update'); + await visit(userURL); + assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); + }); + test('can cancel changes to an existing user', async function (assert) { assert.expect(1); await visit(userURL); @@ -63,14 +71,6 @@ module('Acceptance | users', function (hooks) { assert.notEqual(find('[name="name"]').value, 'Unsaved user name'); }); - test('cannot make changes to an existing user without proper authorization', async function (assert) { - assert.expect(1); - instances.user.authorized_actions = - instances.user.authorized_actions.filter((item) => item !== 'update'); - await visit(userURL); - assert.notOk(find('.rose-layout-page-actions .rose-button-secondary')); - }); - test('saving an existing user with invalid fields displays error messages', async function (assert) { assert.expect(2); this.server.patch('/users/:id', () => {