Merge pull request #165 from hashicorp/refactor-role-pathing
Refactor role pathing
This commit is contained in:
55 files changed
+412
-173
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import ApplicationAdapter from './application';
|
||||
|
||||
export default class AuthMethodAdapter extends ApplicationAdapter {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Auth methods use the new, unprefixed pathing style.
|
||||
* @override
|
||||
*/
|
||||
hasScopePrefix = false;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import ApplicationAdapter from './application';
|
||||
|
||||
export default class RoleAdapter extends ApplicationAdapter {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Roles use the new, unprefixed pathing style.
|
||||
* @override
|
||||
*/
|
||||
hasScopePrefix = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import ApplicationAdapter from './application';
|
||||
|
||||
export default class UserAdapter extends ApplicationAdapter {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Users use the new, unprefixed pathing style.
|
||||
* @override
|
||||
*/
|
||||
hasScopePrefix = false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default class AuthMethodSerializer extends ApplicationSerializer {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Serialized the scope ID into the `scope_id` field.
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,14 @@ import { get } from '@ember/object';
|
||||
|
||||
export default class RoleSerializer extends ApplicationSerializer {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Serialized the scope ID into the `scope_id` field.
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default class UserSerializer extends ApplicationSerializer {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Serialized the scope ID into the `scope_id` field.
|
||||
* @type {boolean}
|
||||
*/
|
||||
serializeScopeID = true;
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/auth-method';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/group';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/role';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/adapters/user';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/auth-method';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/user';
|
||||
@@ -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 | auth method', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let adapter = this.owner.lookup('adapter:auth-method');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Adapter | role', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let adapter = this.owner.lookup('adapter:role');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Adapter | user', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let adapter = this.owner.lookup('adapter:user');
|
||||
assert.ok(adapter);
|
||||
});
|
||||
});
|
||||
@@ -97,17 +97,17 @@ module('Unit | Model | base', function (hooks) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const model = store.createRecord('user', { scopeID: 'o_123' });
|
||||
this.server.post('/v1/scopes/o_123/users', () => {
|
||||
this.server.post('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.patch('/v1/scopes/o_123/users', () => {
|
||||
this.server.patch('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.delete('/v1/scopes/o_123/users', () => {
|
||||
this.server.delete('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
@@ -120,17 +120,17 @@ module('Unit | Model | base', function (hooks) {
|
||||
const customScopeID = 'global';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post('/v1/scopes/global/users', () => {
|
||||
this.server.post('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
this.server.patch('/v1/scopes/global/users', () => {
|
||||
this.server.patch('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
this.server.delete('/v1/scopes/global/users', () => {
|
||||
this.server.delete('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
@@ -143,7 +143,7 @@ module('Unit | Model | base', function (hooks) {
|
||||
const method = 'my-custom-method';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post(`/v1/scopes/o_123/users:${method}`, () => {
|
||||
this.server.post(`/v1/users:${method}`, () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
return {};
|
||||
});
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -14,7 +14,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has a `saveGrants` method that targets a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/roles/123abc:set-grants', (schema, request) => {
|
||||
this.server.post('/v1/roles/123abc:set-grants', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
grant_strings: ['grant1', 'grant2'],
|
||||
@@ -44,7 +44,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has an `addPrincipals` method that targets a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/roles/123abc:add-principals', (schema, request) => {
|
||||
this.server.post('/v1/roles/123abc:add-principals', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['123_abc', 'foobar'],
|
||||
@@ -77,7 +77,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has a `removePrincipals` method that targets a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/roles/123abc:remove-principals', (schema, request) => {
|
||||
this.server.post('/v1/roles/123abc:remove-principals', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['1', '3'],
|
||||
@@ -110,7 +110,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has a `removePrincipal` method that deletes a single principal using `removePrincipals` method', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/scopes/o_1/roles/123abc:remove-principals', (schema, request) => {
|
||||
this.server.post('/v1/roles/123abc:remove-principals', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['3'],
|
||||
|
||||
@@ -25,7 +25,8 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
const serializedRecord = record.serialize();
|
||||
assert.deepEqual(serializedRecord, {
|
||||
name: 'User',
|
||||
description: 'Description'
|
||||
description: 'Description',
|
||||
scope_id: 'global'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,6 +34,7 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('user');
|
||||
serializer.serializeScopeID = false;
|
||||
const record = store.createRecord('user', {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Serializer | auth method', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let serializer = store.serializerFor('auth-method');
|
||||
|
||||
assert.ok(serializer);
|
||||
});
|
||||
|
||||
test('it serializes records', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let record = store.createRecord('auth-method', {});
|
||||
|
||||
let serializedRecord = record.serialize();
|
||||
|
||||
assert.ok(serializedRecord);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Serializer | user', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let serializer = store.serializerFor('user');
|
||||
|
||||
assert.ok(serializer);
|
||||
});
|
||||
|
||||
test('it serializes records', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let record = store.createRecord('user', {});
|
||||
|
||||
let serializedRecord = record.serialize();
|
||||
|
||||
assert.ok(serializedRecord);
|
||||
});
|
||||
});
|
||||
@@ -23,8 +23,8 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
|
||||
* @return {Promise[AuthMethodModel]}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scopeID} = this.modelFor('scopes.scope');
|
||||
return this.store.findAll('auth-method', { adapterOptions: { scopeID } });
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('auth-method', { scope_id });
|
||||
}
|
||||
|
||||
// =actions
|
||||
@@ -48,11 +48,12 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
|
||||
const { isNew } = authMethod;
|
||||
try {
|
||||
await authMethod.save();
|
||||
await this
|
||||
.transitionTo('scopes.scope.auth-methods.auth-method', authMethod);
|
||||
this.refresh();
|
||||
this.notify.success(
|
||||
this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success')
|
||||
);
|
||||
this.transitionTo('scopes.scope.auth-methods.auth-method', authMethod);
|
||||
} catch (error) {
|
||||
//TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
@@ -67,9 +68,9 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
|
||||
async delete(authMethod) {
|
||||
try {
|
||||
await authMethod.destroyRecord();
|
||||
await this.transitionTo('scopes.scope.auth-methods');
|
||||
this.refresh();
|
||||
this.notify.success(this.intl.t('notify.delete-success'));
|
||||
this.transitionTo('scopes.scope.auth-methods');
|
||||
} catch (error) {
|
||||
//TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
|
||||
@@ -9,8 +9,7 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
|
||||
* @param {string} params.auth_method_id
|
||||
* @return {authMethodModel}
|
||||
*/
|
||||
async model({ auth_method_id}) {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findRecord('auth-method', auth_method_id, { adapterOptions: { scopeID }});
|
||||
async model({ auth_method_id }) {
|
||||
return this.store.findRecord('auth-method', auth_method_id);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeAuthMethodsNewRoute extends Route {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -9,6 +10,10 @@ export default class ScopesScopeAuthMethodsNewRoute extends Route {
|
||||
*/
|
||||
model() {
|
||||
const scopeModel = this.modelFor('scopes.scope');
|
||||
return this.store.createRecord('auth-method', { type: 'password', scopeModel });
|
||||
return this.store.createRecord('auth-method', {
|
||||
scopeModel,
|
||||
type: 'password'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,11 +15,11 @@ export default class ScopesScopeAuthenticateRoute extends Route {
|
||||
* @return {Promise} `{scope, scopes, authMethods}`
|
||||
*/
|
||||
model() {
|
||||
const adapterOptions = { scopeID: this.modelFor('scopes.scope').id };
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return hash({
|
||||
scope: this.modelFor('scopes.scope'),
|
||||
scopes: this.modelFor('scopes'),
|
||||
authMethods: this.store.findAll('auth-method', { adapterOptions }),
|
||||
authMethods: this.store.query('auth-method', { scope_id }),
|
||||
|
||||
// for integration testing:
|
||||
// authMethods: A([{
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,10 +24,11 @@ export default class ScopesScopeGroupsGroupAddMembersRoute extends Route {
|
||||
* @return {Promise{GroupModel, [UserModel]}}
|
||||
*/
|
||||
model() {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
const group = this.modelFor('scopes.scope.groups.group');
|
||||
const { scopeID: scope_id } = group;
|
||||
return hash({
|
||||
group: this.modelFor('scopes.scope.groups.group'),
|
||||
users: this.store.findAll('user', { adapterOptions: { scopeID } })
|
||||
users: this.store.query('user', { scope_id })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class ScopesScopeRolesRoute extends Route {
|
||||
* @return {Promise{[RoleModel]}}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findAll('role', { adapterOptions: { scopeID } });
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('role', { scope_id });
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -12,27 +12,17 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Empty out any previously loaded users and groups.
|
||||
* (collectively, principals).
|
||||
*/
|
||||
beforeModel() {
|
||||
this.store.unloadAll('user');
|
||||
this.store.unloadAll('group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current role, all users, and all groups
|
||||
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
|
||||
*/
|
||||
model() {
|
||||
const role = this.modelFor('scopes.scope.roles.role');
|
||||
const { scopeID } = role;
|
||||
const options = { adapterOptions: { scopeID } };
|
||||
const { scopeID: scope_id } = role;
|
||||
return hash({
|
||||
role,
|
||||
users: this.store.findAll('user', options),
|
||||
groups: this.store.findAll('group', options)
|
||||
users: this.store.query('user', { scope_id }),
|
||||
groups: this.store.query('group', { scope_id })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,8 +23,8 @@ export default class ScopesScopeUsersRoute extends Route {
|
||||
* @return {Promise{[UserModel]}}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findAll('user', { adapterOptions: { scopeID } });
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('user', { scope_id });
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -10,9 +10,6 @@ export default class ScopesScopeUsersUserRoute extends Route {
|
||||
* @return {UserModel}
|
||||
*/
|
||||
async model({ user_id }) {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findRecord('user', user_id, {
|
||||
adapterOptions: { scopeID },
|
||||
});
|
||||
return this.store.findRecord('user', user_id);
|
||||
}
|
||||
}
|
||||
+56
-48
@@ -41,30 +41,70 @@ export default function() {
|
||||
|
||||
// Auth & IAM resources
|
||||
|
||||
this.get('/scopes/:scope_id/auth-methods');
|
||||
this.post('/scopes/:scope_id/auth-methods');
|
||||
this.get('/scopes/:scope_id/auth-methods/:id');
|
||||
this.patch('/scopes/:scope_id/auth-methods/:id');
|
||||
this.del('/scopes/:scope_id/auth-methods/:id');
|
||||
this.get('/auth-methods', ({ authMethods }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return authMethods.where({ scopeId });
|
||||
});
|
||||
this.post('/auth-methods');
|
||||
this.get('/auth-methods/:id');
|
||||
this.patch('/auth-methods/:id');
|
||||
this.del('/auth-methods/:id');
|
||||
|
||||
// Authenticate/deauthenticate routes
|
||||
this.post('/scopes/:scope_id/auth-methods/:id_method', authHandler);
|
||||
this.post('/scopes/:id_method', deauthHandler);
|
||||
|
||||
// IAM : Users
|
||||
this.get('/scopes/:scope_id/users');
|
||||
this.post('/scopes/:scope_id/users');
|
||||
this.get('/scopes/:scope_id/users/:id');
|
||||
this.patch('/scopes/:scope_id/users/:id');
|
||||
this.del('/scopes/:scope_id/users/:id');
|
||||
this.get('/users', ({ users }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return users.where({ scopeId });
|
||||
});
|
||||
this.post('/users');
|
||||
this.get('/users/:id');
|
||||
this.patch('/users/:id');
|
||||
this.del('/users/:id');
|
||||
|
||||
// IAM: Groups
|
||||
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];
|
||||
const group = groups.find(id);
|
||||
const updatedAttrs = {
|
||||
version: attrs.version,
|
||||
memberIds: group.memberIds
|
||||
};
|
||||
// If adding members, push them into the array
|
||||
if (method === 'add-members') {
|
||||
attrs.memberIds.forEach(id => {
|
||||
if (!updatedAttrs.memberIds.includes(id)) {
|
||||
updatedAttrs.memberIds.push(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
// If deleting members, filter them out of the array
|
||||
if (method === 'remove-members') {
|
||||
updatedAttrs.memberIds = updatedAttrs.memberIds.filter(id => {
|
||||
return !attrs.memberIds.includes(id);
|
||||
});
|
||||
}
|
||||
return group.update(updatedAttrs);
|
||||
});
|
||||
|
||||
// IAM: Roles
|
||||
this.get('/scopes/:scope_id/roles');
|
||||
this.post('/scopes/:scope_id/roles');
|
||||
this.get('/scopes/:scope_id/roles/:id');
|
||||
this.patch('/scopes/:scope_id/roles/:id');
|
||||
this.del('/scopes/:scope_id/roles/:id');
|
||||
this.post('/scopes/:scope_id/roles/:idMethod', function ({ roles, users, groups }, { params: { idMethod } }) {
|
||||
this.get('/roles', ({ roles }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return roles.where({ scopeId });
|
||||
});
|
||||
this.post('/roles');
|
||||
this.get('/roles/:id');
|
||||
this.patch('/roles/:id');
|
||||
this.del('/roles/:id');
|
||||
this.post('/roles/:idMethod', function ({ roles, users, groups }, { params: { idMethod } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const id = idMethod.split(':')[0];
|
||||
const method = idMethod.split(':')[1];
|
||||
@@ -104,38 +144,6 @@ export default function() {
|
||||
return role.update(updatedAttrs);
|
||||
});
|
||||
|
||||
// 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 } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const id = idMethod.split(':')[0];
|
||||
const method = idMethod.split(':')[1];
|
||||
const group = groups.find(id);
|
||||
const updatedAttrs = {
|
||||
version: attrs.version,
|
||||
memberIds: group.memberIds
|
||||
};
|
||||
// If adding members, push them into the array
|
||||
if (method === 'add-members') {
|
||||
attrs.memberIds.forEach(id => {
|
||||
if (!updatedAttrs.memberIds.includes(id)) {
|
||||
updatedAttrs.memberIds.push(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
// If deleting members, filter them out of the array
|
||||
if (method === 'remove-members') {
|
||||
updatedAttrs.memberIds = updatedAttrs.memberIds.filter(id => {
|
||||
return !attrs.memberIds.includes(id);
|
||||
});
|
||||
}
|
||||
return group.update(updatedAttrs);
|
||||
});
|
||||
|
||||
// Other resources
|
||||
// host-catalog
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@ export default factory.extend({
|
||||
*/
|
||||
withPrincipals: trait({
|
||||
afterCreate(role, server) {
|
||||
const users = server.createList('user', 2);
|
||||
const groups = server.createList('group', 2);
|
||||
const { scope } = role;
|
||||
const users = server.createList('user', 2, { scope });
|
||||
const groups = server.createList('group', 2, { scope });
|
||||
role.update({ users, groups });
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Model, belongsTo } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
|
||||
scope: belongsTo()
|
||||
|
||||
});
|
||||
@@ -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')
|
||||
|
||||
});
|
||||
@@ -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(),
|
||||
users: hasMany(),
|
||||
groups: hasMany()
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Model, belongsTo } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
|
||||
scope: belongsTo()
|
||||
|
||||
});
|
||||
@@ -12,15 +12,15 @@ export default function(server) {
|
||||
type: 'org',
|
||||
scope: { id: globalScope.id, type: globalScope.type }
|
||||
}, 'withChildren')[0];
|
||||
const scopePojo = { id: orgScope.id, type: orgScope.type };
|
||||
|
||||
// Auth
|
||||
server.createList('auth-method', 3, { scope: scopePojo });
|
||||
server.createList('auth-method', 3, { scope: globalScope });
|
||||
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');
|
||||
server.createList('role', 5, { scope: orgScope }, 'withPrincipals');
|
||||
|
||||
// Other resources
|
||||
server.schema.scopes.where({type: 'project'}).models.forEach(scope => {
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { underscore } from '@ember/string';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'auth-method'
|
||||
modelName: 'auth-method',
|
||||
|
||||
keyForRelationshipId(relationshipName) {
|
||||
return `${this._container.inflector.singularize(
|
||||
underscore(relationshipName)
|
||||
)}_id`;
|
||||
},
|
||||
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
json.scope = {
|
||||
id: model.scope.id,
|
||||
type: model.scope.type
|
||||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'org'
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'project'
|
||||
});
|
||||
@@ -1,24 +1,35 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { underscore } from '@ember/string';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'role',
|
||||
|
||||
keyForRelationshipId(relationshipName) {
|
||||
return `${this._container.inflector.singularize(
|
||||
underscore(relationshipName)
|
||||
)}_id`;
|
||||
},
|
||||
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
|
||||
|
||||
const serializedUsers = model.users.models.map(user => ({
|
||||
scope_id: model.scope.id,
|
||||
id: user.id,
|
||||
type: 'user'
|
||||
}));
|
||||
|
||||
const serializedGroups = model.groups.models.map(group => ({
|
||||
scope_id: model.scope.id,
|
||||
id: group.id,
|
||||
type: 'group'
|
||||
}));
|
||||
|
||||
json.principals = [ ...serializedUsers, ...serializedGroups ];
|
||||
|
||||
json.scope = {
|
||||
id: model.scope.id,
|
||||
type: model.scope.type
|
||||
};
|
||||
|
||||
return json;
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,22 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { underscore } from '@ember/string';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'user'
|
||||
modelName: 'user',
|
||||
|
||||
keyForRelationshipId(relationshipName) {
|
||||
return `${this._container.inflector.singularize(
|
||||
underscore(relationshipName)
|
||||
)}_id`;
|
||||
},
|
||||
|
||||
_hashForModel(model) {
|
||||
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
|
||||
json.scope = {
|
||||
id: model.scope.id,
|
||||
type: model.scope.type
|
||||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
});
|
||||
@@ -21,7 +21,9 @@ module('Acceptance | authentication', function (hooks) {
|
||||
let scopesURL;
|
||||
let orgScopeURL;
|
||||
let scope;
|
||||
let globalAuthMethod;
|
||||
let authMethod;
|
||||
let globalAuthMethodID;
|
||||
let authMethodID;
|
||||
let globalAuthenticateURL;
|
||||
let authenticateURL;
|
||||
@@ -43,14 +45,16 @@ module('Acceptance | authentication', function (hooks) {
|
||||
'withChildren'
|
||||
);
|
||||
scope = { id: orgScope.id, type: orgScope.type };
|
||||
authMethod = this.server.create('auth-method', { scope });
|
||||
globalAuthMethod = this.server.create('auth-method', { scope: globalScope });
|
||||
authMethod = this.server.create('auth-method', { scope: orgScope });
|
||||
orgScopeID = orgScope.id;
|
||||
globalAuthMethodID = globalAuthMethod.id;
|
||||
authMethodID = authMethod.id;
|
||||
scopesURL = `/scopes`;
|
||||
orgScopeURL = `/scopes/${orgScopeID}`;
|
||||
globalAuthenticateURL = `/scopes/global/authenticate`;
|
||||
authenticateURL = `/scopes/${orgScopeID}/authenticate`;
|
||||
authMethodGlobalAuthenticateURL = `/scopes/global/authenticate/${authMethodID}`;
|
||||
authMethodGlobalAuthenticateURL = `/scopes/global/authenticate/${globalAuthMethodID}`;
|
||||
authMethodAuthenticateURL = `/scopes/${orgScopeID}/authenticate/${authMethodID}`;
|
||||
orgsURL = `/scopes/global/orgs`;
|
||||
projectsURL = `/scopes/${orgScopeID}/projects`;
|
||||
@@ -74,18 +78,8 @@ module('Acceptance | authentication', function (hooks) {
|
||||
|
||||
test('visiting auth method when the scope cannot be loaded is still allowed', async function (assert) {
|
||||
assert.expect(1);
|
||||
orgScope.destroy();
|
||||
this.server.get('/scopes', ({ scopes }, { queryParams: { scope_id } }) => {
|
||||
// Default parent scope is global
|
||||
if (!scope_id) scope_id = 'global';
|
||||
const results = scopes.where(scope => {
|
||||
return scope.scope ? scope.scope.id === scope_id : false
|
||||
});
|
||||
if (!results.length) {
|
||||
return new Response(404);
|
||||
} else {
|
||||
return results;
|
||||
}
|
||||
this.server.get('/scopes', () => {
|
||||
return new Response(404);
|
||||
});
|
||||
await visit(authMethodAuthenticateURL);
|
||||
await a11yAudit();
|
||||
|
||||
@@ -42,9 +42,9 @@ module('Acceptance | breadcrumbs', function (hooks) {
|
||||
this.server.schema.scopes.where({ type: 'project' }).models[0];
|
||||
|
||||
project = getProjectScope();
|
||||
user = this.server.create('user');
|
||||
role = this.server.create('role');
|
||||
group = this.server.create('group');
|
||||
user = this.server.create('user', { scope: orgScope });
|
||||
role = this.server.create('role', { scope: orgScope });
|
||||
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,
|
||||
{},
|
||||
|
||||
@@ -30,10 +30,7 @@ module('Acceptance | roles', function (hooks) {
|
||||
);
|
||||
|
||||
const role = this.server.create('role', {
|
||||
scope: {
|
||||
id: orgScope.id,
|
||||
type: orgScope.type,
|
||||
},
|
||||
scope: orgScope
|
||||
});
|
||||
|
||||
rolesURL = `/scopes/${orgScope.id}/roles`;
|
||||
@@ -78,7 +75,7 @@ module('Acceptance | roles', function (hooks) {
|
||||
|
||||
test('saving a new role with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/scopes/:scope_id/roles', () => {
|
||||
this.server.post('/roles', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -139,7 +136,7 @@ module('Acceptance | roles', function (hooks) {
|
||||
|
||||
test('saving an existing role with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.patch('/scopes/:scope_id/roles/:id', () => {
|
||||
this.server.patch('/roles/:id', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -175,7 +172,7 @@ module('Acceptance | roles', function (hooks) {
|
||||
|
||||
test('errors are displayed when save project fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.patch('/scopes/:scope_id/roles/:id', () => {
|
||||
this.server.patch('/roles/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
@@ -198,7 +195,7 @@ module('Acceptance | roles', function (hooks) {
|
||||
|
||||
test('errors are displayed when delete project fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.del('/scopes/:scope_id/roles/:id', () => {
|
||||
this.server.del('/roles/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
|
||||
@@ -30,10 +30,7 @@ module('Acceptance | users', function (hooks) {
|
||||
);
|
||||
|
||||
const user = this.server.create('user', {
|
||||
scope: {
|
||||
id: orgScope.id,
|
||||
type: orgScope.type,
|
||||
},
|
||||
scope: orgScope
|
||||
});
|
||||
|
||||
usersURL = `/scopes/${orgScope.id}/users`;
|
||||
@@ -78,7 +75,7 @@ module('Acceptance | users', function (hooks) {
|
||||
|
||||
test('saving a new user with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('scopes/:scope_id/users', () => {
|
||||
this.server.post('/users', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -139,7 +136,7 @@ module('Acceptance | users', function (hooks) {
|
||||
|
||||
test('saving an existing user with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.patch('/scopes/:scope_id/users/:id', () => {
|
||||
this.server.patch('/users/:id', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
@@ -175,7 +172,7 @@ module('Acceptance | users', function (hooks) {
|
||||
|
||||
test('errors are displayed when saving user fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.patch('/scopes/:scope_id/users/:id', () => {
|
||||
this.server.patch('/users/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
@@ -198,7 +195,7 @@ module('Acceptance | users', function (hooks) {
|
||||
|
||||
test('errors are displayed when user deletion fails', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.del('/scopes/:scope_id/users/:id', () => {
|
||||
this.server.del('/users/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
|
||||
Reference in new issue
Block a user