From b454efe41f81c30514137d0268cbf86bee1c4c9e Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 2 Sep 2021 13:01:58 -0700 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20host=20sets=20capabil?= =?UTF-8?q?ities=20create/list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/factories/host-catalog.js | 5 + .../host-catalogs/host-catalog/host-sets.js | 16 +++- .../host-catalog/host-sets/index.js | 9 +- .../host-catalogs/host-catalog/-actions.hbs | 15 +-- .../host-catalog/-navigation.hbs | 11 ++- .../host-catalog/host-sets/index.hbs | 34 +++++-- .../create-test.js} | 14 ++- .../host-catalogs/host-sets/list-test.js | 95 +++++++++++++++++++ 8 files changed, 176 insertions(+), 23 deletions(-) rename ui/admin/tests/acceptance/host-catalogs/{host-sets-test.js => host-sets/create-test.js} (87%) create mode 100644 ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js diff --git a/addons/api/mirage/factories/host-catalog.js b/addons/api/mirage/factories/host-catalog.js index cd033f7f3..085e69ef0 100644 --- a/addons/api/mirage/factories/host-catalog.js +++ b/addons/api/mirage/factories/host-catalog.js @@ -10,6 +10,11 @@ export default factory.extend({ 'update', 'delete', ], + authorized_collection_actions: () => { + return { + 'host-sets': ['create', 'list'], + }; + }, withChildren: trait({ afterCreate(hostCatalog, server) { const { scope } = hostCatalog; diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js index beb0aa93a..db09586ed 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js @@ -10,7 +10,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou @service intl; @service notify; - + @service can; // =methods /** @@ -18,10 +18,16 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou * @return {Promise{[HostSetModel]}} */ model() { - const { id: host_catalog_id } = this.modelFor( - 'scopes.scope.host-catalogs.host-catalog' - ); - return this.store.query('host-set', { host_catalog_id }); + const scope = this.modelFor('scopes.scope.host-catalogs.host-catalog'); + + const { id: host_catalog_id } = scope; + if ( + this.can.can('list collection', scope, { + collection: 'host-sets', + }) + ) { + return this.store.query('host-set', { host_catalog_id }); + } } // =actions diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js index e62c9f95e..ad76516df 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js @@ -1,3 +1,10 @@ import Route from '@ember/routing/route'; +export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexRoute extends Route { + // =methods -export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexRoute extends Route {} + setupController(controller) { + const scope = this.modelFor('scopes.scope.host-catalogs.host-catalog'); + super.setupController(...arguments); + controller.setProperties({ scope }); + } +} diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs index bf5fe452e..ef151fb92 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs @@ -9,12 +9,15 @@ > {{t 'resources.host.actions.create'}} - - {{t 'resources.host-set.actions.create'}} - + {{#if (can 'create collection' @model collection='host-sets')}} + + + {{t 'resources.host-set.actions.create'}} + + {{/if}} {{#if (can 'delete model' @model)}} {{t 'resources.host.title_plural'}} - - {{t 'resources.host-set.title_plural'}} - + + {{#if (can 'navigate collection' @model collection='host-sets')}} + + + {{t 'resources.host-set.title_plural'}} + + {{/if}} + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs index 1b0a18cb8..e45630421 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs @@ -51,14 +51,34 @@ as |message| > - {{t 'resources.host-set.description'}} + + {{#if (can 'list collection' this.scope collection='host-sets')}} + {{! can list (at least): show default welcome message}} + {{t 'resources.host-set.description'}} + + {{else if (can 'create collection' this.scope collection='host-sets')}} + {{! can create (only): show create-but-not-list welcome message}} + {{t + 'descriptions.create-but-not-list' + resource=(t 'resources.host-set.title_plural') + }} + {{else}} + {{! can neither list nor create }} + {{t + 'descriptions.neither-list-nor-create' + resource=(t 'resources.host-set.title_plural') + }} + {{/if}} - - - {{t 'titles.new'}} - + + {{#if (can 'create collection' this.scope collection='host-sets')}} + + + {{t 'titles.new'}} + + {{/if}} diff --git a/ui/admin/tests/acceptance/host-catalogs/host-sets-test.js b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js similarity index 87% rename from ui/admin/tests/acceptance/host-catalogs/host-sets-test.js rename to ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js index 33465e7ce..5e31b9bb6 100644 --- a/ui/admin/tests/acceptance/host-catalogs/host-sets-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js @@ -10,7 +10,7 @@ import { //invalidateSession, } from 'ember-simple-auth/test-support'; -module('Acceptance | host-catalogs | host sets', function (hooks) { +module('Acceptance | host-catalogs | host sets | create', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); @@ -79,6 +79,18 @@ module('Acceptance | host-catalogs | host sets', function (hooks) { assert.equal(getHostSetCount(), count + 1); }); + test('Users cannot navigate to new credential library route without proper authorization', async function (assert) { + assert.expect(2); + instances.hostCatalog.authorized_collection_actions['host-sets'] = []; + await visit(urls.hostCatalog); + assert.notOk( + instances.hostCatalog.authorized_collection_actions['host-sets'].includes( + 'create' + ) + ); + assert.notOk(find(`[href="${urls.hostSets}"]`)); + }); + test('can cancel create new host', async function (assert) { assert.expect(2); const count = getHostSetCount(); diff --git a/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js b/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js new file mode 100644 index 000000000..bd38f95ad --- /dev/null +++ b/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js @@ -0,0 +1,95 @@ +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 | host-catalogs | host sets | list', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + hostCatalog: null, + host: null, + }, + }; + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + hostCatalogs: null, + hostCatalog: null, + hostSets: null, + hostSet: 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.hostCatalog = this.server.create('host-catalog', { + scope: instances.scopes.project, + }); + instances.hostSet = this.server.create('host-set', { + scope: instances.scopes.project, + hostCatalog: instances.hostCatalog, + }); + // 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.hostCatalogs = `${urls.projectScope}/host-catalogs`; + urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; + urls.hostSets = `${urls.hostCatalog}/host-sets`; + urls.hostSet = `${urls.hostSets}/${instances.hostSet.id}`; + authenticateSession({}); + }); + + test('Users can navigate to host-sets with proper authorization', async function (assert) { + assert.expect(2); + await visit(urls.hostCatalog); + assert.ok( + instances.hostCatalog.authorized_collection_actions['host-sets'].includes( + 'list' + ) + ); + assert.ok(find(`[href="${urls.hostSets}"]`)); + }); + + test('Users cannot navigate to index without either list or create actions', async function (assert) { + assert.expect(2); + instances.hostCatalog.authorized_collection_actions['host-sets'] = []; + await visit(urls.hostCatalog); + assert.notOk( + instances.hostCatalog.authorized_collection_actions['host-sets'].includes( + 'list' + ) + ); + assert.notOk(find(`[href="${urls.hostSets}"]`)); + }); + + test('Users can navigate to index with only create action', async function (assert) { + assert.expect(1); + instances.hostCatalog.authorized_collection_actions['host-sets'] = [ + 'create', + ]; + await visit(urls.hostCatalog); + assert.ok(find(`[href="${urls.hostSets}"]`)); + }); +}); From e2b0c3ad134f9f0e9e7e6d7e511fe825fa51deb5 Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 2 Sep 2021 13:17:19 -0700 Subject: [PATCH 2/5] =?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 --- .../tests/acceptance/host-catalogs/host-sets/create-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js index 5e31b9bb6..732b6db48 100644 --- a/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js @@ -79,7 +79,7 @@ module('Acceptance | host-catalogs | host sets | create', function (hooks) { assert.equal(getHostSetCount(), count + 1); }); - test('Users cannot navigate to new credential library route without proper authorization', async function (assert) { + test('Users cannot navigate to new host sets route without proper authorization', async function (assert) { assert.expect(2); instances.hostCatalog.authorized_collection_actions['host-sets'] = []; await visit(urls.hostCatalog); From 99e24500d31af32031ecabe18065ef020dcecba2 Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 2 Sep 2021 13:38:09 -0700 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20update=20const=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scopes/scope/host-catalogs/host-catalog/host-sets.js | 8 +++++--- .../scope/host-catalogs/host-catalog/host-sets/index.js | 7 ++++--- .../scope/host-catalogs/host-catalog/host-sets/index.hbs | 8 +++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js index db09586ed..36d341bc4 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets.js @@ -18,11 +18,13 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou * @return {Promise{[HostSetModel]}} */ model() { - const scope = this.modelFor('scopes.scope.host-catalogs.host-catalog'); + const hostCatalog = this.modelFor( + 'scopes.scope.host-catalogs.host-catalog' + ); - const { id: host_catalog_id } = scope; + const { id: host_catalog_id } = hostCatalog; if ( - this.can.can('list collection', scope, { + this.can.can('list collection', hostCatalog, { collection: 'host-sets', }) ) { diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js index ad76516df..1f49ad3af 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/host-catalog/host-sets/index.js @@ -1,10 +1,11 @@ import Route from '@ember/routing/route'; export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexRoute extends Route { // =methods - setupController(controller) { - const scope = this.modelFor('scopes.scope.host-catalogs.host-catalog'); + const hostCatalog = this.modelFor( + 'scopes.scope.host-catalogs.host-catalog' + ); super.setupController(...arguments); - controller.setProperties({ scope }); + controller.setProperties({ hostCatalog }); } } diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs index e45630421..c814c749e 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs @@ -52,11 +52,13 @@ > - {{#if (can 'list collection' this.scope collection='host-sets')}} + {{#if (can 'list collection' this.hostCatalog collection='host-sets')}} {{! can list (at least): show default welcome message}} {{t 'resources.host-set.description'}} - {{else if (can 'create collection' this.scope collection='host-sets')}} + {{else if (can + 'create collection' this.hostCatalog collection='host-sets' + )}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -71,7 +73,7 @@ {{/if}} - {{#if (can 'create collection' this.scope collection='host-sets')}} + {{#if (can 'create collection' this.hostCatalog collection='host-sets')}} From 4423c53cc4a79a7f350a2a91a068bc3981e13eeb Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 2 Sep 2021 15:58:45 -0700 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20test=20for=20ma?= =?UTF-8?q?nage=20catalog=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../host-catalogs/host-sets/create-test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js index 732b6db48..a7ede23ed 100644 --- a/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/host-sets/create-test.js @@ -70,7 +70,7 @@ module('Acceptance | host-catalogs | host sets | create', function (hooks) { authenticateSession({}); }); - test('can create new host', async function (assert) { + test('can create new host sets', async function (assert) { assert.expect(1); const count = getHostSetCount(); await visit(urls.newHostSet); @@ -79,6 +79,18 @@ module('Acceptance | host-catalogs | host sets | create', function (hooks) { assert.equal(getHostSetCount(), count + 1); }); + test('Users cannot create a new host set without proper authorization', async function (assert) { + assert.expect(2); + instances.hostCatalog.authorized_collection_actions['host-sets'] = []; + await visit(urls.hostCatalog); + assert.notOk( + instances.hostCatalog.authorized_collection_actions['host-sets'].includes( + 'create' + ) + ); + assert.notOk(find(`.rose-layout-page-actions [href="${urls.newHostSet}"]`)); + }); + test('Users cannot navigate to new host sets route without proper authorization', async function (assert) { assert.expect(2); instances.hostCatalog.authorized_collection_actions['host-sets'] = []; From 6babacd0bc3880b60b07d5ed8f66fb88ffe00daa Mon Sep 17 00:00:00 2001 From: dharini Date: Thu, 2 Sep 2021 16:16:19 -0700 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20verify=20manage=20opt?= =?UTF-8?q?ions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/acceptance/host-catalogs/host-sets/list-test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js b/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js index bd38f95ad..6e092398b 100644 --- a/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/host-sets/list-test.js @@ -30,6 +30,7 @@ module('Acceptance | host-catalogs | host sets | list', function (hooks) { hostCatalog: null, hostSets: null, hostSet: null, + newHostSet: null, }; hooks.beforeEach(function () { @@ -58,6 +59,7 @@ module('Acceptance | host-catalogs | host sets | list', function (hooks) { urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; urls.hostSets = `${urls.hostCatalog}/host-sets`; urls.hostSet = `${urls.hostSets}/${instances.hostSet.id}`; + urls.newHostSet = `${urls.hostSets}/new`; authenticateSession({}); }); @@ -85,11 +87,12 @@ module('Acceptance | host-catalogs | host sets | list', function (hooks) { }); test('Users can navigate to index with only create action', async function (assert) { - assert.expect(1); + assert.expect(2); instances.hostCatalog.authorized_collection_actions['host-sets'] = [ 'create', ]; await visit(urls.hostCatalog); assert.ok(find(`[href="${urls.hostSets}"]`)); + assert.ok(find(`.rose-layout-page-actions [href="${urls.newHostSet}"]`)); }); });