From fc4dab606e46decbb240127e561f826099462449 Mon Sep 17 00:00:00 2001 From: dharini Date: Sun, 29 Aug 2021 22:57:16 -0700 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20roles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/abilities/collection.js | 3 +- addons/api/addon/models/base.js | 5 ++ addons/api/mirage/factories/scope.js | 6 ++ addons/core/translations/en-us.yaml | 2 + ui/admin/app/routes/scopes/scope/roles.js | 8 +- .../app/routes/scopes/scope/roles/index.js | 9 +- ui/admin/app/templates/scopes/scope.hbs | 10 ++- .../templates/scopes/scope/roles/index.hbs | 37 ++++++-- .../{roles-test.js => roles/create-test.js} | 42 ++++++++-- ui/admin/tests/acceptance/roles/list-test.js | 84 +++++++++++++++++++ 10 files changed, 183 insertions(+), 23 deletions(-) rename ui/admin/tests/acceptance/{roles-test.js => roles/create-test.js} (73%) create mode 100644 ui/admin/tests/acceptance/roles/list-test.js diff --git a/addons/api/addon/abilities/collection.js b/addons/api/addon/abilities/collection.js index ad52afd18..92f0e4342 100644 --- a/addons/api/addon/abilities/collection.js +++ b/addons/api/addon/abilities/collection.js @@ -29,7 +29,8 @@ export default class CollectionAbility extends Ability { * @return {boolean} */ hasAuthorizedCollectionAction(action) { - const { authorized_collection_actions } = this.model; + const authorized_collection_actions = + (this.model || {}).authorized_collection_actions || {}; const collection = this.collection || {}; return authorized_collection_actions[collection]?.includes(action); } diff --git a/addons/api/addon/models/base.js b/addons/api/addon/models/base.js index f99e0351a..7fd41ec64 100644 --- a/addons/api/addon/models/base.js +++ b/addons/api/addon/models/base.js @@ -42,6 +42,11 @@ export default class BaseModel extends Model { }) authorized_actions; + @attr({ + readOnly: true, + }) + authorized_collection_actions; + set scopeModel(model) { if (model) { const json = model.serialize(); diff --git a/addons/api/mirage/factories/scope.js b/addons/api/mirage/factories/scope.js index fe41f3866..0121b9542 100644 --- a/addons/api/mirage/factories/scope.js +++ b/addons/api/mirage/factories/scope.js @@ -4,6 +4,12 @@ import { trait } from 'ember-cli-mirage'; export default factory.extend({ type: 'global', + authorized_collection_actions: () => { + return { + roles: ['create', 'list'], + }; + }, + /** * Generates realistic-ish IDs while still being deterministic. */ diff --git a/addons/core/translations/en-us.yaml b/addons/core/translations/en-us.yaml index 5370c7e75..8f98f633c 100644 --- a/addons/core/translations/en-us.yaml +++ b/addons/core/translations/en-us.yaml @@ -32,6 +32,8 @@ titles: descriptions: empty-set: There are no items to display yet. You may be able to add items or try back later. origin-initialization: To get started, please enter your origin URL + create-but-not-list: You do not have permission to list {resource}, but you can create new instances. + neither-list-nor-create: You do not have permission to list or create {resource}. questions: delete-confirm: Are you sure you want to delete this resource? remove-confirm: Are you sure you want to remove this association? diff --git a/ui/admin/app/routes/scopes/scope/roles.js b/ui/admin/app/routes/scopes/scope/roles.js index 88d05373b..cbc1dfcc5 100644 --- a/ui/admin/app/routes/scopes/scope/roles.js +++ b/ui/admin/app/routes/scopes/scope/roles.js @@ -11,6 +11,7 @@ export default class ScopesScopeRolesRoute extends Route { @service intl; @service notify; @service session; + @service can; // =methods @@ -26,8 +27,11 @@ export default class ScopesScopeRolesRoute extends Route { * @return {Promise{[RoleModel]}} */ async model() { - const { id: scope_id } = this.modelFor('scopes.scope'); - return this.store.query('role', { scope_id }); + const scope = this.modelFor('scopes.scope'); + const { id: scope_id } = scope; + if (this.can.can('list collection', scope, { collection: 'roles' })) { + return this.store.query('role', { scope_id }); + } } // =actions diff --git a/ui/admin/app/routes/scopes/scope/roles/index.js b/ui/admin/app/routes/scopes/scope/roles/index.js index f2a8d7af1..6020b0c6f 100644 --- a/ui/admin/app/routes/scopes/scope/roles/index.js +++ b/ui/admin/app/routes/scopes/scope/roles/index.js @@ -1,3 +1,10 @@ import Route from '@ember/routing/route'; +export default class ScopesScopeUsersIndexRoute extends Route { + // =methods -export default class ScopesScopeRolesIndexRoute extends Route {} + setupController(controller) { + const scope = this.modelFor('scopes.scope'); + super.setupController(...arguments); + controller.setProperties({ scope }); + } +} diff --git a/ui/admin/app/templates/scopes/scope.hbs b/ui/admin/app/templates/scopes/scope.hbs index 65e456c51..f2b01f11b 100644 --- a/ui/admin/app/templates/scopes/scope.hbs +++ b/ui/admin/app/templates/scopes/scope.hbs @@ -102,10 +102,12 @@ {{t 'resources.group.title_plural'}} - - - {{t 'resources.role.title_plural'}} - + {{#if (can 'navigate collection' @model collection='roles')}} + + + {{t 'resources.role.title_plural'}} + + {{/if}} {{t 'resources.auth-method.title_plural'}} diff --git a/ui/admin/app/templates/scopes/scope/roles/index.hbs b/ui/admin/app/templates/scopes/scope/roles/index.hbs index d69351c8e..ac7664ece 100644 --- a/ui/admin/app/templates/scopes/scope/roles/index.hbs +++ b/ui/admin/app/templates/scopes/scope/roles/index.hbs @@ -15,10 +15,12 @@ - {{#if @model}} - {{t - 'titles.new' - }} + {{#if (can 'create collection' this.scope collection='users')}} + {{#if @model}} + {{t + 'titles.new' + }} + {{/if}} {{/if}} @@ -68,12 +70,29 @@ as |message| > - {{t 'resources.role.description'}} + {{#if (can 'list collection' this.scope collection='roles')}} + {{! can list (at least): show default welcome message}} + {{t 'resources.roles.description'}} + {{else if (can 'create collection' this.scope collection='roles')}} + {{! can create (only): show create-but-not-list welcome message}} + {{t + 'descriptions.create-but-not-list' + resource=(t 'resources.role.title_plural') + }} + {{else}} + {{! can neither list nor create }} + {{t + 'descriptions.neither-list-nor-create' + resource=(t 'resources.role.title_plural') + }} + {{/if}} - - - {{t 'titles.new'}} - + {{#if (can 'create collection' this.scope collection='roles')}} + + + {{t 'titles.new'}} + + {{/if}} diff --git a/ui/admin/tests/acceptance/roles-test.js b/ui/admin/tests/acceptance/roles/create-test.js similarity index 73% rename from ui/admin/tests/acceptance/roles-test.js rename to ui/admin/tests/acceptance/roles/create-test.js index 77b971f46..a0364c8b0 100644 --- a/ui/admin/tests/acceptance/roles-test.js +++ b/ui/admin/tests/acceptance/roles/create-test.js @@ -11,10 +11,13 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | roles', function (hooks) { +module('Acceptance | roles | create', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); + let orgURL; + let orgScope; + const instances = { scopes: { global: null, @@ -27,10 +30,20 @@ module('Acceptance | roles', function (hooks) { orgScope: null, roles: null, role: null, - newRole: null, + newRoleURL: null, }; hooks.beforeEach(function () { + orgScope = this.server.create( + 'scope', + { + type: 'org', + scope: { id: 'global', type: 'global' }, + }, + 'withChildren' + ); + + orgURL = `/scopes/${orgScope.id}`; authenticateSession({}); instances.scopes.global = this.server.create('scope', { id: 'global' }); instances.scopes.org = this.server.create('scope', { @@ -53,22 +66,39 @@ module('Acceptance | roles', function (hooks) { ); urls.roles = `/scopes/${instances.scopes.org.id}/roles`; urls.role = `${urls.roles}/${instances.role.id}`; - urls.newRole = `${urls.roles}/new`; + urls.newRoleURL = `${urls.roles}/new`; }); test('can create new role', async function (assert) { assert.expect(1); const rolesCount = this.server.db.roles.length; - await visit(urls.newRole); + await visit(urls.newRoleURL); await fillIn('[name="name"]', 'role name'); await click('[type="submit"]'); assert.equal(this.server.db.roles.length, rolesCount + 1); }); + test('can navigate to new roles route with proper authorization', async function (assert) { + assert.expect(2); + await visit(orgURL); + assert.ok(orgScope.authorized_collection_actions.roles.includes('create')); + assert.ok(find(`[href="${orgURL}/roles"]`)); + }); + + test('cannot navigate to new roles route without proper authorization', async function (assert) { + assert.expect(2); + orgScope.authorized_collection_actions.roles = []; + await visit(orgURL); + assert.notOk( + orgScope.authorized_collection_actions.roles.includes('create') + ); + assert.notOk(find(`[href="${orgURL}/roles"]`)); + }); + test('can cancel new role creation', async function (assert) { assert.expect(2); const rolesCount = this.server.db.roles.length; - await visit(urls.newRole); + await visit(urls.newRoleURL); await fillIn('[name="name"]', 'role name'); await click('.rose-form-actions [type="button"]'); assert.equal(currentURL(), urls.roles); @@ -96,7 +126,7 @@ module('Acceptance | roles', function (hooks) { } ); }); - await visit(urls.newRole); + await visit(urls.newRoleURL); await fillIn('[name="name"]', 'new target'); await click('form [type="submit"]'); await a11yAudit(); diff --git a/ui/admin/tests/acceptance/roles/list-test.js b/ui/admin/tests/acceptance/roles/list-test.js new file mode 100644 index 000000000..78e7d22fa --- /dev/null +++ b/ui/admin/tests/acceptance/roles/list-test.js @@ -0,0 +1,84 @@ +import { module, test } from 'qunit'; +import { visit, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | roles | list', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + let orgURL; + + const instances = { + scopes: { + global: null, + org: null, + }, + }; + + const urls = { + scopes: { + org: null, + }, + roles: null, + orgScope: null, + }; + + hooks.beforeEach(function () { + instances.scopes.global = this.server.create('scope', { id: 'global' }); + urls.orgScope = this.server.create( + 'scope', + { + type: 'org', + scope: { id: 'global', type: 'global' }, + }, + 'withChildren' + ); + instances.org = this.server.create( + 'scope', + { + type: 'org', + scope: { id: 'global', type: 'global' }, + }, + 'withChildren' + ); + instances.role = this.server.create('role', { + scope: instances.org, + }); + orgURL = `/scopes/${urls.orgScope.id}`; + + urls.roles = `/scopes/${urls.orgScope.id}/roles`; + authenticateSession({}); + }); + + test('can navigate to roles with proper authorization', async function (assert) { + assert.expect(2); + await visit(orgURL); + assert.ok( + urls.orgScope.authorized_collection_actions.roles.includes('list') + ); + assert.ok(find(`[href="${urls.roles}"]`)); + }); + + test('User cannot navigate to index without either list or create actions', async function (assert) { + assert.expect(2); + urls.orgScope.authorized_collection_actions.roles = []; + await visit(orgURL); + assert.notOk( + urls.orgScope.authorized_collection_actions.roles.includes('list') + ); + assert.notOk(find(`[href="${urls.roles}"]`)); + }); + + test('User can navigate to index with only create action', async function (assert) { + assert.expect(1); + urls.orgScope.authorized_collection_actions.roles = ['create']; + await visit(orgURL); + assert.ok(find(`[href="${urls.roles}"]`)); + }); +}); From 77b1ca477d6893513e3ad4ec51fe5a5763024356 Mon Sep 17 00:00:00 2001 From: dharini Date: Tue, 31 Aug 2021 08:17:25 -0700 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/acceptance/roles/create-test.js | 37 ++++++++++--------- ui/admin/tests/acceptance/roles/list-test.js | 27 +++++--------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/ui/admin/tests/acceptance/roles/create-test.js b/ui/admin/tests/acceptance/roles/create-test.js index a0364c8b0..c2a86e46c 100644 --- a/ui/admin/tests/acceptance/roles/create-test.js +++ b/ui/admin/tests/acceptance/roles/create-test.js @@ -16,7 +16,6 @@ module('Acceptance | roles | create', function (hooks) { setupMirage(hooks); let orgURL; - let orgScope; const instances = { scopes: { @@ -25,16 +24,17 @@ module('Acceptance | roles | create', function (hooks) { project: null, }, role: null, + orgScope: null, }; const urls = { - orgScope: null, roles: null, role: null, newRoleURL: null, }; hooks.beforeEach(function () { - orgScope = this.server.create( + authenticateSession({}); + instances.orgScope = this.server.create( 'scope', { type: 'org', @@ -43,30 +43,29 @@ module('Acceptance | roles | create', function (hooks) { 'withChildren' ); - orgURL = `/scopes/${orgScope.id}`; - 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.scopes.global = this.server.create('scope', { id: 'global' }); + // instances.scopes.org = this.server.create('scope', { + // type: 'org', + // scope: { id: 'global', type: 'global' }, + // }); // The project scope is not yet used for role tests (though it will be // in the future). This is created simply to test the grant scope loading // mechanism. instances.scopes.project = this.server.create('scope', { type: 'project', - scope: { id: instances.scopes.org.id, type: instances.scopes.org.type }, + scope: { id: instances.orgScope.id, type: instances.orgScope.type }, }); instances.role = this.server.create( 'role', { - scope: instances.scopes.org, + scope: instances.orgScope, }, 'withPrincipals' ); - urls.roles = `/scopes/${instances.scopes.org.id}/roles`; + urls.roles = `/scopes/${instances.orgScope.id}/roles`; urls.role = `${urls.roles}/${instances.role.id}`; urls.newRoleURL = `${urls.roles}/new`; + orgURL = `/scopes/${instances.orgScope.id}`; }); test('can create new role', async function (assert) { @@ -81,18 +80,20 @@ module('Acceptance | roles | create', function (hooks) { test('can navigate to new roles route with proper authorization', async function (assert) { assert.expect(2); await visit(orgURL); - assert.ok(orgScope.authorized_collection_actions.roles.includes('create')); - assert.ok(find(`[href="${orgURL}/roles"]`)); + assert.ok( + instances.orgScope.authorized_collection_actions.roles.includes('create') + ); + assert.ok(find(`[href="${urls.roles}"]`)); }); test('cannot navigate to new roles route without proper authorization', async function (assert) { assert.expect(2); - orgScope.authorized_collection_actions.roles = []; + instances.orgScope.authorized_collection_actions.roles = []; await visit(orgURL); assert.notOk( - orgScope.authorized_collection_actions.roles.includes('create') + instances.orgScope.authorized_collection_actions.roles.includes('create') ); - assert.notOk(find(`[href="${orgURL}/roles"]`)); + assert.notOk(find(`[href="${urls.roles}"]`)); }); test('can cancel new role creation', async function (assert) { diff --git a/ui/admin/tests/acceptance/roles/list-test.js b/ui/admin/tests/acceptance/roles/list-test.js index 78e7d22fa..e6e13cfb7 100644 --- a/ui/admin/tests/acceptance/roles/list-test.js +++ b/ui/admin/tests/acceptance/roles/list-test.js @@ -19,6 +19,7 @@ module('Acceptance | roles | list', function (hooks) { global: null, org: null, }, + orgScope: null, }; const urls = { @@ -26,20 +27,10 @@ module('Acceptance | roles | list', function (hooks) { org: null, }, roles: null, - orgScope: null, }; hooks.beforeEach(function () { - instances.scopes.global = this.server.create('scope', { id: 'global' }); - urls.orgScope = this.server.create( - 'scope', - { - type: 'org', - scope: { id: 'global', type: 'global' }, - }, - 'withChildren' - ); - instances.org = this.server.create( + instances.orgScope = this.server.create( 'scope', { type: 'org', @@ -48,11 +39,11 @@ module('Acceptance | roles | list', function (hooks) { 'withChildren' ); instances.role = this.server.create('role', { - scope: instances.org, + scope: instances.orgScope, }); - orgURL = `/scopes/${urls.orgScope.id}`; + orgURL = `/scopes/${instances.orgScope.id}`; - urls.roles = `/scopes/${urls.orgScope.id}/roles`; + urls.roles = `/scopes/${instances.orgScope.id}/roles`; authenticateSession({}); }); @@ -60,24 +51,24 @@ module('Acceptance | roles | list', function (hooks) { assert.expect(2); await visit(orgURL); assert.ok( - urls.orgScope.authorized_collection_actions.roles.includes('list') + instances.orgScope.authorized_collection_actions.roles.includes('list') ); assert.ok(find(`[href="${urls.roles}"]`)); }); test('User cannot navigate to index without either list or create actions', async function (assert) { assert.expect(2); - urls.orgScope.authorized_collection_actions.roles = []; + instances.orgScope.authorized_collection_actions.roles = []; await visit(orgURL); assert.notOk( - urls.orgScope.authorized_collection_actions.roles.includes('list') + instances.orgScope.authorized_collection_actions.roles.includes('list') ); assert.notOk(find(`[href="${urls.roles}"]`)); }); test('User can navigate to index with only create action', async function (assert) { assert.expect(1); - urls.orgScope.authorized_collection_actions.roles = ['create']; + instances.orgScope.authorized_collection_actions.roles = ['create']; await visit(orgURL); assert.ok(find(`[href="${urls.roles}"]`)); }); From 4f74f8578ec62c996d5b0a9564d762afb8a45c43 Mon Sep 17 00:00:00 2001 From: dharini Date: Tue, 31 Aug 2021 08:55:36 -0700 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20resource=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/routes/scopes/scope/roles/index.js | 2 +- ui/admin/app/templates/scopes/scope/roles/index.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/roles/index.js b/ui/admin/app/routes/scopes/scope/roles/index.js index 6020b0c6f..56c143beb 100644 --- a/ui/admin/app/routes/scopes/scope/roles/index.js +++ b/ui/admin/app/routes/scopes/scope/roles/index.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -export default class ScopesScopeUsersIndexRoute extends Route { +export default class ScopesScopeRolesIndexRoute extends Route { // =methods setupController(controller) { diff --git a/ui/admin/app/templates/scopes/scope/roles/index.hbs b/ui/admin/app/templates/scopes/scope/roles/index.hbs index ac7664ece..9962addc5 100644 --- a/ui/admin/app/templates/scopes/scope/roles/index.hbs +++ b/ui/admin/app/templates/scopes/scope/roles/index.hbs @@ -15,7 +15,7 @@ - {{#if (can 'create collection' this.scope collection='users')}} + {{#if (can 'create collection' this.scope collection='roles')}} {{#if @model}} {{t 'titles.new' From 0ab5ff837074bcfff61e5f1134815e73bfee4117 Mon Sep 17 00:00:00 2001 From: dharini Date: Wed, 1 Sep 2021 14:17:00 -0700 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20org=20to=20urls?= =?UTF-8?q?,=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/acceptance/roles/create-test.js | 24 +++++++------------ ui/admin/tests/acceptance/roles/list-test.js | 10 ++++---- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ui/admin/tests/acceptance/roles/create-test.js b/ui/admin/tests/acceptance/roles/create-test.js index c2a86e46c..f9d5e7778 100644 --- a/ui/admin/tests/acceptance/roles/create-test.js +++ b/ui/admin/tests/acceptance/roles/create-test.js @@ -15,8 +15,6 @@ module('Acceptance | roles | create', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - let orgURL; - const instances = { scopes: { global: null, @@ -29,7 +27,8 @@ module('Acceptance | roles | create', function (hooks) { const urls = { roles: null, role: null, - newRoleURL: null, + newRole: null, + orgScope: null, }; hooks.beforeEach(function () { @@ -43,11 +42,6 @@ module('Acceptance | roles | create', function (hooks) { 'withChildren' ); - // instances.scopes.global = this.server.create('scope', { id: 'global' }); - // instances.scopes.org = this.server.create('scope', { - // type: 'org', - // scope: { id: 'global', type: 'global' }, - // }); // The project scope is not yet used for role tests (though it will be // in the future). This is created simply to test the grant scope loading // mechanism. @@ -64,14 +58,14 @@ module('Acceptance | roles | create', function (hooks) { ); urls.roles = `/scopes/${instances.orgScope.id}/roles`; urls.role = `${urls.roles}/${instances.role.id}`; - urls.newRoleURL = `${urls.roles}/new`; - orgURL = `/scopes/${instances.orgScope.id}`; + urls.newRole = `${urls.roles}/new`; + urls.orgScope = `/scopes/${instances.orgScope.id}`; }); test('can create new role', async function (assert) { assert.expect(1); const rolesCount = this.server.db.roles.length; - await visit(urls.newRoleURL); + await visit(urls.newRole); await fillIn('[name="name"]', 'role name'); await click('[type="submit"]'); assert.equal(this.server.db.roles.length, rolesCount + 1); @@ -79,7 +73,7 @@ module('Acceptance | roles | create', function (hooks) { test('can navigate to new roles route with proper authorization', async function (assert) { assert.expect(2); - await visit(orgURL); + await visit(urls.orgScope); assert.ok( instances.orgScope.authorized_collection_actions.roles.includes('create') ); @@ -89,7 +83,7 @@ module('Acceptance | roles | create', function (hooks) { test('cannot navigate to new roles route without proper authorization', async function (assert) { assert.expect(2); instances.orgScope.authorized_collection_actions.roles = []; - await visit(orgURL); + await visit(urls.orgScope); assert.notOk( instances.orgScope.authorized_collection_actions.roles.includes('create') ); @@ -99,7 +93,7 @@ module('Acceptance | roles | create', function (hooks) { test('can cancel new role creation', async function (assert) { assert.expect(2); const rolesCount = this.server.db.roles.length; - await visit(urls.newRoleURL); + await visit(urls.newRole); await fillIn('[name="name"]', 'role name'); await click('.rose-form-actions [type="button"]'); assert.equal(currentURL(), urls.roles); @@ -127,7 +121,7 @@ module('Acceptance | roles | create', function (hooks) { } ); }); - await visit(urls.newRoleURL); + await visit(urls.newRole); await fillIn('[name="name"]', 'new target'); await click('form [type="submit"]'); await a11yAudit(); diff --git a/ui/admin/tests/acceptance/roles/list-test.js b/ui/admin/tests/acceptance/roles/list-test.js index e6e13cfb7..c1b1ed8a5 100644 --- a/ui/admin/tests/acceptance/roles/list-test.js +++ b/ui/admin/tests/acceptance/roles/list-test.js @@ -12,7 +12,6 @@ import { module('Acceptance | roles | list', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - let orgURL; const instances = { scopes: { @@ -27,6 +26,7 @@ module('Acceptance | roles | list', function (hooks) { org: null, }, roles: null, + orgScope: null, }; hooks.beforeEach(function () { @@ -41,7 +41,7 @@ module('Acceptance | roles | list', function (hooks) { instances.role = this.server.create('role', { scope: instances.orgScope, }); - orgURL = `/scopes/${instances.orgScope.id}`; + urls.orgScope = `/scopes/${instances.orgScope.id}`; urls.roles = `/scopes/${instances.orgScope.id}/roles`; authenticateSession({}); @@ -49,7 +49,7 @@ module('Acceptance | roles | list', function (hooks) { test('can navigate to roles with proper authorization', async function (assert) { assert.expect(2); - await visit(orgURL); + await visit(urls.orgScope); assert.ok( instances.orgScope.authorized_collection_actions.roles.includes('list') ); @@ -59,7 +59,7 @@ module('Acceptance | roles | list', function (hooks) { test('User cannot navigate to index without either list or create actions', async function (assert) { assert.expect(2); instances.orgScope.authorized_collection_actions.roles = []; - await visit(orgURL); + await visit(urls.orgScope); assert.notOk( instances.orgScope.authorized_collection_actions.roles.includes('list') ); @@ -69,7 +69,7 @@ module('Acceptance | roles | list', function (hooks) { test('User can navigate to index with only create action', async function (assert) { assert.expect(1); instances.orgScope.authorized_collection_actions.roles = ['create']; - await visit(orgURL); + await visit(urls.orgScope); assert.ok(find(`[href="${urls.roles}"]`)); }); }); From 13794c7bf8c3fda081aff18445b6370ac5f7204e Mon Sep 17 00:00:00 2001 From: dharini Date: Wed, 1 Sep 2021 14:26:25 -0700 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/tests/acceptance/roles/create-test.js | 4 ++-- ui/admin/tests/acceptance/roles/list-test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/admin/tests/acceptance/roles/create-test.js b/ui/admin/tests/acceptance/roles/create-test.js index f9d5e7778..a0564f67d 100644 --- a/ui/admin/tests/acceptance/roles/create-test.js +++ b/ui/admin/tests/acceptance/roles/create-test.js @@ -71,7 +71,7 @@ module('Acceptance | roles | create', function (hooks) { assert.equal(this.server.db.roles.length, rolesCount + 1); }); - test('can navigate to new roles route with proper authorization', async function (assert) { + test('Users can navigate to new roles route with proper authorization', async function (assert) { assert.expect(2); await visit(urls.orgScope); assert.ok( @@ -80,7 +80,7 @@ module('Acceptance | roles | create', function (hooks) { assert.ok(find(`[href="${urls.roles}"]`)); }); - test('cannot navigate to new roles route without proper authorization', async function (assert) { + test('Users cannot navigate to new roles route without proper authorization', async function (assert) { assert.expect(2); instances.orgScope.authorized_collection_actions.roles = []; await visit(urls.orgScope); diff --git a/ui/admin/tests/acceptance/roles/list-test.js b/ui/admin/tests/acceptance/roles/list-test.js index c1b1ed8a5..ff170aeb7 100644 --- a/ui/admin/tests/acceptance/roles/list-test.js +++ b/ui/admin/tests/acceptance/roles/list-test.js @@ -47,7 +47,7 @@ module('Acceptance | roles | list', function (hooks) { authenticateSession({}); }); - test('can navigate to roles with proper authorization', async function (assert) { + test('Users can navigate to roles with proper authorization', async function (assert) { assert.expect(2); await visit(urls.orgScope); assert.ok( @@ -56,7 +56,7 @@ module('Acceptance | roles | list', function (hooks) { assert.ok(find(`[href="${urls.roles}"]`)); }); - test('User cannot navigate to index without either list or create actions', async function (assert) { + test('Users cannot navigate to index without either list or create actions', async function (assert) { assert.expect(2); instances.orgScope.authorized_collection_actions.roles = []; await visit(urls.orgScope); @@ -66,7 +66,7 @@ module('Acceptance | roles | list', function (hooks) { assert.notOk(find(`[href="${urls.roles}"]`)); }); - test('User can navigate to index with only create action', async function (assert) { + test('Users can navigate to index with only create action', async function (assert) { assert.expect(1); instances.orgScope.authorized_collection_actions.roles = ['create']; await visit(urls.orgScope);