Merge pull request #725 from hashicorp/group-create-list
Group create list
This commit is contained in:
7 files changed
+157
-26
No files matched your search
@@ -7,7 +7,7 @@ export default factory.extend({
|
||||
authorized_collection_actions: () => {
|
||||
return {
|
||||
users: ['create', 'list'],
|
||||
// groups: ['create', 'list'],
|
||||
groups: ['create', 'list'],
|
||||
// roles: ['create', 'list'],
|
||||
// 'auth-methods': ['create', 'list'],
|
||||
// sessopms: ['list'],
|
||||
|
||||
@@ -11,7 +11,7 @@ export default class ScopesScopeGroupsRoute extends Route {
|
||||
@service intl;
|
||||
@service notify;
|
||||
@service session;
|
||||
|
||||
@service can;
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -26,8 +26,11 @@ export default class ScopesScopeGroupsRoute extends Route {
|
||||
* @return {Promise[GroupModel]}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('group', { scope_id });
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const { id: scope_id } = scope;
|
||||
if (this.can.can('list collection', scope, { collection: 'groups' })) {
|
||||
return this.store.query('group', { scope_id });
|
||||
}
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import Route from '@ember/routing/route';
|
||||
export default class ScopesScopeGroupsIndexRoute extends Route {
|
||||
// =methods
|
||||
|
||||
export default class ScopesScopeGroupsIndexRoute extends Route {}
|
||||
setupController(controller) {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
super.setupController(...arguments);
|
||||
controller.setProperties({ scope });
|
||||
}
|
||||
}
|
||||
@@ -100,10 +100,12 @@
|
||||
{{t 'resources.user.title_plural'}}
|
||||
</nav.link>
|
||||
{{/if}}
|
||||
<nav.link @route='scopes.scope.groups'>
|
||||
<Rose::Icon @name='flight-icons/folder-users-16' @size='medium' />
|
||||
{{t 'resources.group.title_plural'}}
|
||||
</nav.link>
|
||||
{{#if (can 'navigate collection' @model collection='groups')}}
|
||||
<nav.link @route='scopes.scope.groups'>
|
||||
<Rose::Icon @name='flight-icons/folder-users-16' @size='medium' />
|
||||
{{t 'resources.group.title_plural'}}
|
||||
</nav.link>
|
||||
{{/if}}
|
||||
<nav.link @route='scopes.scope.roles'>
|
||||
<Rose::Icon @name='flight-icons/identity-user-16' @size='medium' />
|
||||
{{t 'resources.role.title_plural'}}
|
||||
|
||||
@@ -13,10 +13,12 @@
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton @route='scopes.scope.groups.new' @style='primary'>{{t
|
||||
'titles.new'
|
||||
}}</Rose::LinkButton>
|
||||
{{#if (can 'create collection' this.scope collection='groups')}}
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton @route='scopes.scope.groups.new' @style='primary'>{{t
|
||||
'titles.new'
|
||||
}}</Rose::LinkButton>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
@@ -70,11 +72,29 @@
|
||||
>
|
||||
<message.description>
|
||||
{{t 'resources.group.description'}}
|
||||
{{#if (can 'list collection' this.scope collection='groups')}}
|
||||
{{! can list (at least): show default welcome message}}
|
||||
{{t 'resources.group.description'}}
|
||||
{{else if (can 'create collection' this.scope collection='groups')}}
|
||||
{{! can create (only): show create-but-not-list welcome message}}
|
||||
{{t
|
||||
'descriptions.create-but-not-list'
|
||||
resource=(t 'resources.group.title_plural')
|
||||
}}
|
||||
{{else}}
|
||||
{{! can neither list nor create }}
|
||||
{{t
|
||||
'descriptions.neither-list-nor-create'
|
||||
resource=(t 'resources.group.title_plural')
|
||||
}}
|
||||
{{/if}}
|
||||
</message.description>
|
||||
<message.link @route='scopes.scope.groups.new'>
|
||||
<Rose::Icon @name='flight-icons/plus-circle-16' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{#if (can 'create collection' this.scope collection='groups')}}
|
||||
<message.link @route='scopes.scope.groups.new'>
|
||||
<Rose::Icon @name='flight-icons/plus-circle-16' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{/if}}
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
|
||||
+32
-9
@@ -10,9 +10,10 @@ import {
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | groups', function (hooks) {
|
||||
module('Acceptance | groups | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
let orgURL;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -20,9 +21,9 @@ module('Acceptance | groups', function (hooks) {
|
||||
org: null,
|
||||
},
|
||||
group: null,
|
||||
orgScope: null,
|
||||
};
|
||||
const urls = {
|
||||
orgScope: null,
|
||||
groups: null,
|
||||
group: null,
|
||||
newGroup: null,
|
||||
@@ -30,17 +31,21 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
authenticateSession({});
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.orgScope = this.server.create(
|
||||
'scope',
|
||||
{
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
},
|
||||
'withChildren'
|
||||
);
|
||||
instances.group = this.server.create('group', {
|
||||
scope: instances.scopes.org,
|
||||
scope: instances.orgScope,
|
||||
});
|
||||
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
|
||||
urls.groups = `/scopes/${instances.orgScope.id}/groups`;
|
||||
urls.group = `${urls.groups}/${instances.group.id}`;
|
||||
urls.newGroup = `${urls.groups}/new`;
|
||||
orgURL = `/scopes/${instances.orgScope.id}`;
|
||||
});
|
||||
|
||||
test('can create new group', async function (assert) {
|
||||
@@ -52,6 +57,24 @@ module('Acceptance | groups', function (hooks) {
|
||||
assert.equal(this.server.db.groups.length, groupsCount + 1);
|
||||
});
|
||||
|
||||
test('can navigate to new groups route with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(orgURL);
|
||||
assert.ok(
|
||||
instances.orgScope.authorized_collection_actions.groups.includes('create')
|
||||
);
|
||||
assert.ok(find(`[href="${urls.groups}"]`));
|
||||
});
|
||||
|
||||
test('cannot navigate to new groups route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.orgScope.authorized_collection_actions.groups = [];
|
||||
await visit(orgURL);
|
||||
assert.notOk(
|
||||
instances.orgScope.authorized_collection_actions.groups.includes('create')
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.groups}"]`));
|
||||
});
|
||||
test('can cancel new group creation', async function (assert) {
|
||||
assert.expect(2);
|
||||
const groupsCount = this.server.db.groups.length;
|
||||
@@ -0,0 +1,76 @@
|
||||
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 | groups | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
let orgURL;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
orgScope: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
scopes: {
|
||||
org: null,
|
||||
},
|
||||
groups: 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.group = this.server.create('group', {
|
||||
scope: instances.orgScope,
|
||||
});
|
||||
orgURL = `/scopes/${instances.orgScope.id}`;
|
||||
|
||||
urls.groups = `/scopes/${instances.orgScope.id}/groups`;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('can navigate to groups with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(orgURL);
|
||||
assert.ok(
|
||||
instances.orgScope.authorized_collection_actions.groups.includes('list')
|
||||
);
|
||||
assert.ok(find(`[href="${urls.groups}"]`));
|
||||
});
|
||||
|
||||
test('User cannot navigate to index without either list or create actions', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.orgScope.authorized_collection_actions.groups = [];
|
||||
await visit(orgURL);
|
||||
assert.notOk(
|
||||
instances.orgScope.authorized_collection_actions.groups.includes('list')
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.groups}"]`));
|
||||
});
|
||||
|
||||
test('User can navigate to index with only create action', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.orgScope.authorized_collection_actions.groups = ['create'];
|
||||
await visit(orgURL);
|
||||
assert.ok(find(`[href="${urls.groups}"]`));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user