refactor: 💡 implement new pathing for groups
This commit is contained in:
17 files changed
+75
-36
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import ApplicationAdapter from './application';
|
||||
|
||||
export default class GroupAdapter extends ApplicationAdapter {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Groups use the new, unprefixed pathing style.
|
||||
* @override
|
||||
*/
|
||||
hasScopePrefix = false;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,14 @@ import ApplicationSerializer from './application';
|
||||
|
||||
export default class GroupSerializer extends ApplicationSerializer {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Serialized the scope ID into the `scope_id` field.
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/group';
|
||||
@@ -93,13 +93,11 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
test('it can request records through the store from a specified scope', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
this.server.get('/v1/scopes/p_456/groups', () => {
|
||||
assert.ok(true, 'Scoped resource URL was requested.');
|
||||
this.server.get('/v1/groups', (_, { queryParams: { scope_id }}) => {
|
||||
assert.equal(scope_id, 'p_456', 'Scoped resource URL was requested.');
|
||||
return {items: []};
|
||||
});
|
||||
await store.findAll('group', {
|
||||
adapterOptions: { scopeID: 'p_456' }
|
||||
});
|
||||
await store.query('group', { scope_id: 'p_456' });
|
||||
});
|
||||
|
||||
test('it rewrites PUT to PATCH, but leaves others unchanged', function (assert) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Adapter | group', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let adapter = this.owner.lookup('adapter:group');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
@@ -43,7 +43,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has an `addMembers` method that groups a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:add-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:add-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['123_abc', 'foobar'],
|
||||
@@ -73,7 +73,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has a `removeMembers` method that groups a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:remove-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:remove-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['1', '3'],
|
||||
@@ -103,7 +103,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
|
||||
test('it has a `removeMember` method that deletes a single member set using `removeMembers` method', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/groups/123abc:remove-members', (schema, request) => {
|
||||
this.server.post('/v1/groups/123abc:remove-members', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['3'],
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class ScopesScopeGroupsRoute extends Route {
|
||||
* @return {Promise[GroupModel]}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findAll('group', { adapterOptions: { scopeID } });
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('group', { scope_id });
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -11,11 +11,7 @@ export default class ScopesScopeGroupsGroupRoute extends Route {
|
||||
* @return {groupModel}
|
||||
*/
|
||||
model({ group_id }) {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findRecord('group', group_id, {
|
||||
reload: true,
|
||||
adapterOptions: { scopeID },
|
||||
});
|
||||
return this.store.findRecord('group', group_id, { reload: true });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
|
||||
*/
|
||||
beforeModel() {
|
||||
this.store.unloadAll('user');
|
||||
this.store.unloadAll('group');
|
||||
//this.store.unloadAll('group');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
|
||||
return hash({
|
||||
role,
|
||||
users: this.store.findAll('user', options),
|
||||
groups: this.store.findAll('group', options)
|
||||
groups: this.store.query('group', { scope_id: scopeID })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
|
||||
const groups = role.principals
|
||||
.filterBy('type', 'group')
|
||||
.map(({ principal_id }) =>
|
||||
this.store.findRecord('group', principal_id, { adapterOptions })
|
||||
this.store.findRecord('group', principal_id)
|
||||
.then(model => ({
|
||||
type: 'group',
|
||||
model
|
||||
|
||||
@@ -107,12 +107,14 @@ export default function() {
|
||||
});
|
||||
|
||||
// IAM: Groups
|
||||
this.get('/scopes/:scope_id/groups');
|
||||
this.post('/scopes/:scope_id/groups');
|
||||
this.get('/scopes/:scope_id/groups/:id');
|
||||
this.patch('/scopes/:scope_id/groups/:id');
|
||||
this.del('/scopes/:scope_id/groups/:id');
|
||||
this.post('/scopes/:scope_id/groups/:idMethod', function ({ groups }, { params: { idMethod } }) {
|
||||
this.get('/groups', ({ groups }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return groups.where({ scopeId });
|
||||
});
|
||||
this.post('/groups');
|
||||
this.get('/groups/:id');
|
||||
this.patch('/groups/:id');
|
||||
this.del('/groups/:id');
|
||||
this.post('/groups/:idMethod', function ({ groups }, { params: { idMethod } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const id = idMethod.split(':')[0];
|
||||
const method = idMethod.split(':')[1];
|
||||
|
||||
@@ -11,7 +11,8 @@ export default factory.extend({
|
||||
withMembers: trait({
|
||||
afterCreate(group, server) {
|
||||
const scope = group.scope;
|
||||
const members = server.createList('user', 2, { scope });
|
||||
const scopePojo = { id: scope.id, type: scope.type };
|
||||
const members = server.createList('user', 2, { scope: scopePojo });
|
||||
group.update({ members });
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Model, hasMany } from 'ember-cli-mirage';
|
||||
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
|
||||
scope: belongsTo(),
|
||||
members: hasMany('user')
|
||||
|
||||
});
|
||||
@@ -19,7 +19,7 @@ export default function(server) {
|
||||
server.createList('auth-method', 3, { scope: orgScope });
|
||||
|
||||
// Groups and Users
|
||||
server.createList('group', 5, { scope: scopePojo }, 'withMembers');
|
||||
server.createList('group', 5, { scope: orgScope }, 'withMembers');
|
||||
// Role
|
||||
server.createList('role', 5, { scope: scopePojo }, 'withPrincipals');
|
||||
|
||||
|
||||
@@ -10,9 +10,19 @@ export default ApplicationSerializer.extend({
|
||||
)}_ids`;
|
||||
},
|
||||
|
||||
keyForRelationshipId(relationshipName) {
|
||||
return `${this._container.inflector.singularize(
|
||||
underscore(relationshipName)
|
||||
)}_id`;
|
||||
},
|
||||
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
json.member_ids = model.memberIds;
|
||||
json.scope = {
|
||||
id: model.scope.id,
|
||||
type: model.scope.type
|
||||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ module('Acceptance | breadcrumbs', function (hooks) {
|
||||
project = getProjectScope();
|
||||
user = this.server.create('user');
|
||||
role = this.server.create('role');
|
||||
group = this.server.create('group');
|
||||
group = this.server.create('group', { scope: orgScope });
|
||||
hostCatalog = this.server.create('host-catalog', {
|
||||
scope: {
|
||||
id: project.id,
|
||||
|
||||
@@ -30,10 +30,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
);
|
||||
|
||||
const group = this.server.create('group', {
|
||||
scope: {
|
||||
id: orgScope.id,
|
||||
type: orgScope.type,
|
||||
},
|
||||
scope: orgScope
|
||||
});
|
||||
|
||||
groupsURL = `/scopes/${orgScope.id}/groups`;
|
||||
@@ -78,7 +75,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
test('saving a new group with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/scopes/:scope_id/groups', () => {
|
||||
this.server.post('/groups', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -139,7 +136,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
test('saving an existing group with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.patch('/scopes/:scope_id/groups/:id', () => {
|
||||
this.server.patch('/groups/:id', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -175,7 +172,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
test('errors are displayed when save project fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.patch('/scopes/:scope_id/groups/:id', () => {
|
||||
this.server.patch('/groups/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
@@ -198,7 +195,7 @@ module('Acceptance | groups', function (hooks) {
|
||||
|
||||
test('errors are displayed when delete project fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.del('/scopes/:scope_id/groups/:id', () => {
|
||||
this.server.del('/groups/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
|
||||
Reference in new issue
Block a user