diff --git a/addons/api/mirage/factories/scope.js b/addons/api/mirage/factories/scope.js
index bb43723c0..d67c66456 100644
--- a/addons/api/mirage/factories/scope.js
+++ b/addons/api/mirage/factories/scope.js
@@ -10,8 +10,10 @@ export default factory.extend({
sessions: ['list'],
groups: ['create', 'list'],
roles: ['create', 'list'],
+ targets: ['create', 'list'],
+ // 'auth-methods': ['create', 'list'],
+ // sessopms: ['list'],
'auth-methods': ['create', 'list'],
- // targets: ['create', 'list'],
'host-catalogs': ['create', 'list'],
// 'credential-stores': ['create', 'list'],
};
diff --git a/ui/admin/app/routes/scopes/scope/targets.js b/ui/admin/app/routes/scopes/scope/targets.js
index 40cd811bb..2adb5ca84 100644
--- a/ui/admin/app/routes/scopes/scope/targets.js
+++ b/ui/admin/app/routes/scopes/scope/targets.js
@@ -11,6 +11,7 @@ export default class ScopesScopeTargetsRoute extends Route {
@service intl;
@service notify;
@service session;
+ @service can;
// =methods
@@ -26,8 +27,11 @@ export default class ScopesScopeTargetsRoute extends Route {
* @return {Promise{[TargetModel]}}
*/
async model() {
- const { id: scope_id } = this.modelFor('scopes.scope');
- return this.store.query('target', { scope_id });
+ const scope = this.modelFor('scopes.scope');
+ const { id: scope_id } = scope;
+ if (this.can.can('list collection', scope, { collection: 'targets' })) {
+ return this.store.query('target', { scope_id });
+ }
}
// =actions
diff --git a/ui/admin/app/routes/scopes/scope/targets/index.js b/ui/admin/app/routes/scopes/scope/targets/index.js
index 2b4412f53..8e92f73d5 100644
--- a/ui/admin/app/routes/scopes/scope/targets/index.js
+++ b/ui/admin/app/routes/scopes/scope/targets/index.js
@@ -1,3 +1,10 @@
import Route from '@ember/routing/route';
+export default class ScopesScopeTargetsIndexRoute extends Route {
+ // =methods
-export default class ScopesScopeTargetsIndexRoute 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 2a1a045d7..60011d064 100644
--- a/ui/admin/app/templates/scopes/scope.hbs
+++ b/ui/admin/app/templates/scopes/scope.hbs
@@ -77,10 +77,12 @@
{{t 'resources.session.title_plural'}}
{{/if}}
-
-
- {{t 'resources.target.title_plural'}}
-
+ {{#if (can 'navigate collection' @model collection='targets')}}
+
+
+ {{t 'resources.target.title_plural'}}
+
+ {{/if}}
{{#if (can 'navigate collection' @model collection='host-catalogs')}}
diff --git a/ui/admin/app/templates/scopes/scope/targets/index.hbs b/ui/admin/app/templates/scopes/scope/targets/index.hbs
index 743de9fe2..bee49f086 100644
--- a/ui/admin/app/templates/scopes/scope/targets/index.hbs
+++ b/ui/admin/app/templates/scopes/scope/targets/index.hbs
@@ -15,13 +15,14 @@
- {{#if @model}}
-
- {{t 'titles.new'}}
-
+ {{#if (can 'create collection' this.scope collection='targets')}}
+ {{#if @model}}
+ {{t
+ 'titles.new'
+ }}
+ {{/if}}
{{/if}}
-
{{#if @model}}
@@ -79,12 +80,34 @@
as |message|
>
- {{t 'resources.target.description'}}
+
+ {{#if (can 'list collection' this.scope collection='targets')}}
+ {{! can list (at least): show default welcome message}}
+ {{t 'resources.target.description'}}
+ {{else if (can
+ 'create collection' this.scope collection='targets'
+ )}}
+ {{! can create (only): show create-but-not-list welcome message}}
+ {{t
+ 'descriptions.create-but-not-list'
+ resource=(t 'resources.target.title_plural')
+ }}
+ {{else}}
+ {{! can neither list nor create }}
+ {{t
+ 'descriptions.neither-list-nor-create'
+ resource=(t 'resources.target.title_plural')
+ }}
+
+ {{/if}}
-
-
- {{t 'titles.new'}}
-
+
+ {{#if (can 'create collection' this.scope collection='targets')}}
+
+
+ {{t 'titles.new'}}
+
+ {{/if}}
diff --git a/ui/admin/tests/acceptance/targets-test.js b/ui/admin/tests/acceptance/targets/create-test.js
similarity index 80%
rename from ui/admin/tests/acceptance/targets-test.js
rename to ui/admin/tests/acceptance/targets/create-test.js
index cf202c049..16215cb7a 100644
--- a/ui/admin/tests/acceptance/targets-test.js
+++ b/ui/admin/tests/acceptance/targets/create-test.js
@@ -10,7 +10,7 @@ import {
//invalidateSession,
} from 'ember-simple-auth/test-support';
-module('Acceptance | targets', function (hooks) {
+module('Acceptance | targets | create', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
@@ -33,7 +33,6 @@ module('Acceptance | targets', function (hooks) {
};
hooks.beforeEach(function () {
- // Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
@@ -68,6 +67,29 @@ module('Acceptance | targets', function (hooks) {
assert.equal(getTargetCount(), count + 1);
});
+ test('can navigate to new targets route with proper authorization', async function (assert) {
+ assert.expect(2);
+ await visit(urls.projectScope);
+ assert.ok(
+ instances.scopes.project.authorized_collection_actions.targets.includes(
+ 'create'
+ )
+ );
+ assert.ok(find(`[href="${urls.targets}"]`));
+ });
+
+ test('cannot navigate to new targets route without proper authorization', async function (assert) {
+ assert.expect(2);
+ instances.scopes.project.authorized_collection_actions.targets = [];
+ await visit(urls.projectScope);
+ assert.notOk(
+ instances.scopes.project.authorized_collection_actions.targets.includes(
+ 'create'
+ )
+ );
+ assert.notOk(find(`[href="${urls.targets}"]`));
+ });
+
test('can cancel create new targets', async function (assert) {
assert.expect(2);
const count = getTargetCount();
diff --git a/ui/admin/tests/acceptance/targets/list-test.js b/ui/admin/tests/acceptance/targets/list-test.js
new file mode 100644
index 000000000..19bd4ee64
--- /dev/null
+++ b/ui/admin/tests/acceptance/targets/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 | targets | list', function (hooks) {
+ setupApplicationTest(hooks);
+ setupMirage(hooks);
+
+ const instances = {
+ scopes: {
+ global: null,
+ org: null,
+ },
+ orgScope: null,
+ };
+
+ const urls = {
+ scopes: {
+ org: null,
+ project: null,
+ },
+ targets: null,
+ projectScope: null,
+ };
+
+ hooks.beforeEach(function () {
+ instances.scopes.global = this.server.create('scope', { id: 'global' });
+ instances.orgScope = this.server.create(
+ 'scope',
+ {
+ type: 'org',
+ scope: { id: 'global', type: 'global' },
+ },
+ 'withChildren'
+ );
+ instances.scopes.project = this.server.create('scope', {
+ type: 'project',
+ scope: { id: instances.orgScope.id, type: 'org' },
+ });
+ instances.target = this.server.create('target', {
+ scope: instances.scopes.project,
+ });
+ urls.projectScope = `/scopes/${instances.scopes.project.id}`;
+ urls.targets = `${urls.projectScope}/targets`;
+ authenticateSession({});
+ });
+
+ test('can navigate to targets with proper authorization', async function (assert) {
+ assert.expect(2);
+ await visit(urls.projectScope);
+ assert.ok(
+ instances.scopes.project.authorized_collection_actions.targets.includes(
+ 'list'
+ )
+ );
+ assert.ok(find(`[href="${urls.targets}"]`));
+ });
+
+ test('User cannot navigate to index without either list or create actions', async function (assert) {
+ assert.expect(2);
+ instances.scopes.project.authorized_collection_actions.targets = [];
+ await visit(urls.projectScope);
+ assert.notOk(
+ instances.scopes.project.authorized_collection_actions.targets.includes(
+ 'list'
+ )
+ );
+ assert.notOk(find(`[href="${urls.targets}"]`));
+ });
+
+ test('User can navigate to index with only create action', async function (assert) {
+ assert.expect(1);
+ instances.scopes.project.authorized_collection_actions.targets = ['create'];
+ await visit(urls.projectScope);
+ assert.ok(find(`[href="${urls.targets}"]`));
+ });
+});