Merge branch 'main' into cred-lib-create-list

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2021-09-02 14:13:22 -07:00
commit 157dda4f8e
7 files changed
+164 -20

No files matched your search

+3 -1
View File
@@ -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'],
};
+6 -2
View File
@@ -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
@@ -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 });
}
}
+6 -4
View File
@@ -77,10 +77,12 @@
{{t 'resources.session.title_plural'}}
</nav.link>
{{/if}}
<nav.link @route='scopes.scope.targets'>
<Rose::Icon @name='flight-icons/crosshair-16' @size='medium' />
{{t 'resources.target.title_plural'}}
</nav.link>
{{#if (can 'navigate collection' @model collection='targets')}}
<nav.link @route='scopes.scope.targets'>
<Rose::Icon @name='flight-icons/crosshair-16' @size='medium' />
{{t 'resources.target.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='host-catalogs')}}
<nav.link @route='scopes.scope.host-catalogs'>
<Rose::Icon @name='flight-icons/collections-16' @size='medium' />
@@ -15,13 +15,14 @@
</page.header>
<page.actions>
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.targets.new' @style='primary'>
{{t 'titles.new'}}
</Rose::LinkButton>
{{#if (can 'create collection' this.scope collection='targets')}}
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.targets.new' @style='primary'>{{t
'titles.new'
}}</Rose::LinkButton>
{{/if}}
{{/if}}
</page.actions>
<page.body>
{{#if @model}}
@@ -79,12 +80,34 @@
as |message|
>
<message.description>
{{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}}
</message.description>
<message.link @route='scopes.scope.targets.new'>
<Rose::Icon @name='flight-icons/plus-circle-16' />
{{t 'titles.new'}}
</message.link>
{{#if (can 'create collection' this.scope collection='targets')}}
<message.link @route='scopes.scope.targets.new'>
<Rose::Icon @name='flight-icons/plus-circle-16' />
{{t 'titles.new'}}
</message.link>
{{/if}}
</Rose::Message>
</Rose::Layout::Centered>
@@ -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();
@@ -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}"]`));
});
});