Merge branch 'feature-user-collection-abilities' into feature-scope-capabilities
This commit is contained in:
10 files changed
+149
-18
No files matched your search
@@ -11,6 +11,7 @@ export default class ScopesScopeUsersRoute extends Route {
|
||||
@service intl;
|
||||
@service notify;
|
||||
@service session;
|
||||
@service can;
|
||||
|
||||
// =methods
|
||||
|
||||
@@ -26,8 +27,11 @@ export default class ScopesScopeUsersRoute extends Route {
|
||||
* @return {Promise{[UserModel]}}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('user', { scope_id });
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const { id: scope_id } = scope;
|
||||
if (this.can.can('list collection', scope, { collection: 'users' })) {
|
||||
return this.store.query('user', { scope_id });
|
||||
}
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeUsersIndexRoute extends Route {}
|
||||
export default class ScopesScopeUsersIndexRoute extends Route {
|
||||
// =methods
|
||||
|
||||
setupController(controller) {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
super.setupController(...arguments);
|
||||
controller.setProperties({ scope });
|
||||
}
|
||||
}
|
||||
@@ -94,10 +94,12 @@
|
||||
|
||||
{{#unless @model.isProject}}
|
||||
<Rose::Nav::Sidebar @title={{t 'titles.iam'}} as |nav|>
|
||||
<nav.link @route='scopes.scope.users'>
|
||||
<Rose::Icon @name='app-icons/users' @size='medium' />
|
||||
{{t 'resources.user.title_plural'}}
|
||||
</nav.link>
|
||||
{{#if (can 'navigate collection' @model collection='users')}}
|
||||
<nav.link @route='scopes.scope.users'>
|
||||
<Rose::Icon @name='app-icons/users' @size='medium' />
|
||||
{{t 'resources.user.title_plural'}}
|
||||
</nav.link>
|
||||
{{/if}}
|
||||
<nav.link @route='scopes.scope.groups'>
|
||||
<Rose::Icon @name='app-icons/group' @size='medium' />
|
||||
{{t 'resources.group.title_plural'}}
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton @route='scopes.scope.users.new' @style='primary'>{{t
|
||||
'titles.new'
|
||||
}}</Rose::LinkButton>
|
||||
{{#if (can 'create collection' this.scope collection='users')}}
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton @route='scopes.scope.users.new' @style='primary'>{{t
|
||||
'titles.new'
|
||||
}}</Rose::LinkButton>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
@@ -68,12 +70,29 @@
|
||||
as |message|
|
||||
>
|
||||
<message.description>
|
||||
{{t 'resources.user.description'}}
|
||||
{{#if (can 'list collection' this.scope collection='users')}}
|
||||
{{! can list (at least): show default welcome message}}
|
||||
{{t 'resources.user.description'}}
|
||||
{{else if (can 'create collection' this.scope collection='users')}}
|
||||
{{! can create (only): show create-but-not-list welcome message}}
|
||||
{{t
|
||||
'descriptions.create-but-not-list'
|
||||
resource=(t 'resources.user.title_plural')
|
||||
}}
|
||||
{{else}}
|
||||
{{! can neither list nor create }}
|
||||
{{t
|
||||
'descriptions.neither-list-nor-create'
|
||||
resource=(t 'resources.user.title_plural')
|
||||
}}
|
||||
{{/if}}
|
||||
</message.description>
|
||||
<message.link @route='scopes.scope.users.new'>
|
||||
<Rose::Icon @name='plus-circle-outline' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{#if (can 'create collection' this.scope collection='users')}}
|
||||
<message.link @route='scopes.scope.users.new'>
|
||||
<Rose::Icon @name='plus-circle-outline' />
|
||||
{{t 'titles.new'}}
|
||||
</message.link>
|
||||
{{/if}}
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
|
||||
+21
-1
@@ -10,23 +10,28 @@ import {
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | users', function (hooks) {
|
||||
module('Acceptance | users | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let globalScope;
|
||||
let orgScope;
|
||||
let orgURL;
|
||||
let usersURL;
|
||||
let newUserURL;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
globalScope = this.server.create('scope', { id: 'global' });
|
||||
orgScope = this.server.create(
|
||||
'scope',
|
||||
{
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
},
|
||||
'withChildren'
|
||||
);
|
||||
|
||||
orgURL = `/scopes/${orgScope.id}`;
|
||||
usersURL = `/scopes/${orgScope.id}/users`;
|
||||
newUserURL = `${usersURL}/new`;
|
||||
|
||||
@@ -42,6 +47,21 @@ module('Acceptance | users', function (hooks) {
|
||||
assert.equal(this.server.db.users.length, usersCount + 1);
|
||||
});
|
||||
|
||||
test('can navigate to new users route with proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(orgURL);
|
||||
assert.ok(orgScope.authorized_collection_actions.users.includes('create'));
|
||||
assert.ok(find(`[href="${orgURL}/users"]`));
|
||||
});
|
||||
|
||||
test('cannot navigate to new users route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
orgScope.authorized_collection_actions.users = [];
|
||||
await visit(orgURL);
|
||||
assert.notOk(orgScope.authorized_collection_actions.users.includes('create'));
|
||||
assert.notOk(find(`[href="${orgURL}/users"]`));
|
||||
});
|
||||
|
||||
test('can cancel creation of a new user', async function (assert) {
|
||||
assert.expect(2);
|
||||
const usersCount = this.server.db.users.length;
|
||||
@@ -0,0 +1,57 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, find } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | users | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let usersURL;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
}
|
||||
};
|
||||
|
||||
const urls = {
|
||||
scopes: {
|
||||
org: null
|
||||
},
|
||||
users: null
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.org = this.server.create(
|
||||
'scope',
|
||||
{
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
},
|
||||
'withChildren'
|
||||
);
|
||||
instances.user = this.server.create('user', {
|
||||
scope: instances.org,
|
||||
});
|
||||
urls.users = `/scopes/${instances.org.id}/users`;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('can navigate to users with proper authorization', async function (assert) {
|
||||
// TODO
|
||||
});
|
||||
|
||||
test('cannot navigate to users with proper authorization', async function (assert) {
|
||||
// TODO
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user