Merge branch 'main' into sessions
This commit is contained in:
8 files changed
+180
-10
No files matched your search
@@ -57,7 +57,7 @@ export default class BaseModel extends Model {
|
||||
|
||||
/**
|
||||
* Convenience for getting and setting the parent scope ID.
|
||||
* @type {string
|
||||
* @type {string}
|
||||
*/
|
||||
@computed('scope.scope_id')
|
||||
get scopeID() {
|
||||
|
||||
@@ -12,7 +12,7 @@ export default factory.extend({
|
||||
roles: ['create', 'list'],
|
||||
'auth-methods': ['create', 'list'],
|
||||
// targets: ['create', 'list'],
|
||||
// 'host-catalogs': ['create', 'list'],
|
||||
'host-catalogs': ['create', 'list'],
|
||||
// 'credential-stores': ['create', 'list'],
|
||||
};
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ export default class ScopesScopeHostCatalogsRoute extends Route {
|
||||
@service intl;
|
||||
@service notify;
|
||||
@service session;
|
||||
|
||||
@service can;
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -26,9 +26,14 @@ export default class ScopesScopeHostCatalogsRoute extends Route {
|
||||
* @return {Promise{[HostCatalogModel]}}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const { id: scope_id } = scope;
|
||||
if (
|
||||
this.can.can('list collection', scope, { collection: 'host-catalogs' })
|
||||
) {
|
||||
return this.store.query('host-catalog', { scope_id });
|
||||
}
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeHostCatalogsIndexRoute extends Route {}
|
||||
export default class ScopesScopeHostCatalogsIndexRoute extends Route {
|
||||
setupController(controller) {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
super.setupController(...arguments);
|
||||
controller.setProperties({ scope });
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,12 @@
|
||||
<Rose::Icon @name='flight-icons/crosshair-16' @size='medium' />
|
||||
{{t 'resources.target.title_plural'}}
|
||||
</nav.link>
|
||||
{{#if (can 'navigate collection' @model collection='host-catalogs')}}
|
||||
<nav.link @route='scopes.scope.host-catalogs'>
|
||||
<Rose::Icon @name='flight-icons/collections-16' @size='medium' />
|
||||
{{t 'resources.host-catalog.title_plural'}}
|
||||
</nav.link>
|
||||
{{/if}}
|
||||
{{#if (feature-flag 'credential-store')}}
|
||||
<nav.link @route='scopes.scope.credential-stores'>
|
||||
<Rose::Icon @name='flight-icons/key-16' @size='medium' />
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
{{#if (can 'create collection' this.scope collection='host-catalogs')}}
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton
|
||||
@route='scopes.scope.host-catalogs.new'
|
||||
@@ -23,6 +24,7 @@
|
||||
{{t 'titles.new'}}
|
||||
</Rose::LinkButton>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
@@ -82,12 +84,35 @@
|
||||
as |message|
|
||||
>
|
||||
<message.description>
|
||||
{{#if
|
||||
(can 'list collection' this.scope collection='host-catalogs')
|
||||
}}
|
||||
{{! can list (at least): show default welcome message}}
|
||||
{{t 'resources.host-catalog.description'}}
|
||||
{{else if (can
|
||||
'create collection' this.scope collection='host-catalogs'
|
||||
)}}
|
||||
{{! can create (only): show create-but-not-list welcome message}}
|
||||
{{t
|
||||
'descriptions.create-but-not-list'
|
||||
resource=(t 'resources.host-catalog.title_plural')
|
||||
}}
|
||||
{{else}}
|
||||
{{! can neither list nor create }}
|
||||
{{t
|
||||
'descriptions.neither-list-nor-create'
|
||||
resource=(t 'resources.host-catalog.title_plural')
|
||||
}}
|
||||
{{/if}}
|
||||
</message.description>
|
||||
{{#if
|
||||
(can 'create collection' this.scope collection='host-catalogs')
|
||||
}}
|
||||
<message.link @route='scopes.scope.host-catalogs.new'>
|
||||
<Rose::Icon @name='flight-icons/plus-circle-16' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{/if}}
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
|
||||
+40
-5
@@ -10,7 +10,7 @@ import {
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | host-catalogs', function (hooks) {
|
||||
module('Acceptance | host-catalogs | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
@@ -22,6 +22,7 @@ module('Acceptance | host-catalogs', function (hooks) {
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
orgScope: null,
|
||||
};
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
@@ -35,6 +36,14 @@ module('Acceptance | host-catalogs', function (hooks) {
|
||||
hooks.beforeEach(function () {
|
||||
// Generate resources
|
||||
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.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
@@ -46,21 +55,23 @@ module('Acceptance | host-catalogs', function (hooks) {
|
||||
instances.hostCatalog = this.server.create('host-catalog', {
|
||||
scope: instances.scopes.project,
|
||||
});
|
||||
|
||||
// Generate route URLs for resources
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.orgScope.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.hostCatalogs = `${urls.projectScope}/host-catalogs`;
|
||||
|
||||
urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`;
|
||||
urls.unknownHostCatalog = `${urls.hostCatalogs}/foo`;
|
||||
urls.newHostCatalog = `${urls.hostCatalogs}/new`;
|
||||
// Generate resource couner
|
||||
gethostCatalogCount = () =>
|
||||
this.server.schema.hostCatalogs.all().models.length;
|
||||
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('can create new host catalogs', async function (assert) {
|
||||
test('Users can create new host catalogs', async function (assert) {
|
||||
assert.expect(1);
|
||||
const count = gethostCatalogCount();
|
||||
await visit(urls.newHostCatalog);
|
||||
@@ -69,7 +80,7 @@ module('Acceptance | host-catalogs', function (hooks) {
|
||||
assert.equal(gethostCatalogCount(), count + 1);
|
||||
});
|
||||
|
||||
test('can cancel create new host catalogs', async function (assert) {
|
||||
test('Users can cancel create new host catalogs', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = gethostCatalogCount();
|
||||
await visit(urls.newHostCatalog);
|
||||
@@ -79,6 +90,30 @@ module('Acceptance | host-catalogs', function (hooks) {
|
||||
assert.equal(gethostCatalogCount(), count);
|
||||
});
|
||||
|
||||
test('Users can navigate to new host catalogs route with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.projectScope);
|
||||
assert.ok(
|
||||
instances.scopes.project.authorized_collection_actions[
|
||||
'host-catalogs'
|
||||
].includes('create')
|
||||
);
|
||||
assert.ok(find(`[href="${urls.hostCatalogs}"]`));
|
||||
});
|
||||
|
||||
test('Users cannot navigate to new host catalogs route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.scopes.project.authorized_collection_actions['host-catalogs'] =
|
||||
[];
|
||||
await visit(urls.projectScope);
|
||||
assert.notOk(
|
||||
instances.scopes.project.authorized_collection_actions[
|
||||
'host-catalogs'
|
||||
].includes('create')
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.hostCatalogs}"]`));
|
||||
});
|
||||
|
||||
test('saving a new host catalog with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/host-catalogs', () => {
|
||||
@@ -0,0 +1,97 @@
|
||||
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 | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
orgScope: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
scopes: {
|
||||
org: null,
|
||||
},
|
||||
projectScope: null,
|
||||
hostCatalogs: 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.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,
|
||||
});
|
||||
|
||||
urls.hostCatalogs = `/scopes/${instances.orgScope.id}/host-catalogs`;
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.orgScope.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.hostCatalogs = `${urls.projectScope}/host-catalogs`;
|
||||
|
||||
urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('Users can navigate to host catalogs with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.projectScope);
|
||||
assert.ok(
|
||||
instances.scopes.project.authorized_collection_actions[
|
||||
'host-catalogs'
|
||||
].includes('list')
|
||||
);
|
||||
assert.ok(find(`[href="${urls.hostCatalogs}"]`));
|
||||
});
|
||||
|
||||
test('User cannot navigate to index without either list or create actions', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.scopes.project.authorized_collection_actions['host-catalogs'] =
|
||||
[];
|
||||
await visit(urls.projectScope);
|
||||
assert.notOk(
|
||||
instances.scopes.project.authorized_collection_actions[
|
||||
'host-catalogs'
|
||||
].includes('list')
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.hostCatalogs}"]`));
|
||||
});
|
||||
|
||||
test('User can navigate to index with only create action', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.scopes.project.authorized_collection_actions['host-catalogs'] = [
|
||||
'create',
|
||||
];
|
||||
await visit(urls.projectScope);
|
||||
assert.ok(find(`[href="${urls.hostCatalogs}"]`));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user