Merge pull request #738 from hashicorp/hosts-create-lists
feat: host sets capabilities create/list
This commit is contained in:
8 files changed
+196
-23
No files matched your search
@@ -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;
|
||||
|
||||
@@ -10,7 +10,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou
|
||||
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
@service can;
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -18,10 +18,18 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou
|
||||
* @return {Promise{[HostSetModel]}}
|
||||
*/
|
||||
model() {
|
||||
const { id: host_catalog_id } = this.modelFor(
|
||||
const hostCatalog = this.modelFor(
|
||||
'scopes.scope.host-catalogs.host-catalog'
|
||||
);
|
||||
return this.store.query('host-set', { host_catalog_id });
|
||||
|
||||
const { id: host_catalog_id } = hostCatalog;
|
||||
if (
|
||||
this.can.can('list collection', hostCatalog, {
|
||||
collection: 'host-sets',
|
||||
})
|
||||
) {
|
||||
return this.store.query('host-set', { host_catalog_id });
|
||||
}
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexRoute extends Route {}
|
||||
export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexRoute extends Route {
|
||||
// =methods
|
||||
setupController(controller) {
|
||||
const hostCatalog = this.modelFor(
|
||||
'scopes.scope.host-catalogs.host-catalog'
|
||||
);
|
||||
super.setupController(...arguments);
|
||||
controller.setProperties({ hostCatalog });
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,15 @@
|
||||
>
|
||||
{{t 'resources.host.actions.create'}}
|
||||
</dropdown.link>
|
||||
<dropdown.link
|
||||
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
|
||||
@model={{@model}}
|
||||
>
|
||||
{{t 'resources.host-set.actions.create'}}
|
||||
</dropdown.link>
|
||||
{{#if (can 'create collection' @model collection='host-sets')}}
|
||||
|
||||
<dropdown.link
|
||||
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
|
||||
@model={{@model}}
|
||||
>
|
||||
{{t 'resources.host-set.actions.create'}}
|
||||
</dropdown.link>
|
||||
{{/if}}
|
||||
{{#if (can 'delete model' @model)}}
|
||||
<dropdown.separator />
|
||||
<dropdown.button
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
<nav.link @route='scopes.scope.host-catalogs.host-catalog.hosts'>
|
||||
{{t 'resources.host.title_plural'}}
|
||||
</nav.link>
|
||||
<nav.link @route='scopes.scope.host-catalogs.host-catalog.host-sets'>
|
||||
{{t 'resources.host-set.title_plural'}}
|
||||
</nav.link>
|
||||
|
||||
{{#if (can 'navigate collection' @model collection='host-sets')}}
|
||||
|
||||
<nav.link @route='scopes.scope.host-catalogs.host-catalog.host-sets'>
|
||||
{{t 'resources.host-set.title_plural'}}
|
||||
</nav.link>
|
||||
{{/if}}
|
||||
|
||||
</Rose::Nav::Tabs>
|
||||
@@ -51,14 +51,36 @@
|
||||
as |message|
|
||||
>
|
||||
<message.description>
|
||||
{{t 'resources.host-set.description'}}
|
||||
|
||||
{{#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.hostCatalog 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}}
|
||||
</message.description>
|
||||
<message.link
|
||||
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
|
||||
>
|
||||
<Rose::Icon @name='flight-icons/plus-circle-16' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
|
||||
{{#if (can 'create collection' this.hostCatalog collection='host-sets')}}
|
||||
<message.link
|
||||
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
|
||||
>
|
||||
<Rose::Icon @name='flight-icons/plus-circle-16' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{/if}}
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
|
||||
+26
-2
@@ -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);
|
||||
|
||||
@@ -70,7 +70,7 @@ module('Acceptance | host-catalogs | host sets', 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,30 @@ module('Acceptance | host-catalogs | host sets', 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'] = [];
|
||||
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();
|
||||
@@ -0,0 +1,98 @@
|
||||
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,
|
||||
newHostSet: 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}`;
|
||||
urls.newHostSet = `${urls.hostSets}/new`;
|
||||
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(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}"]`));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user