feat: 🎸 add principals list tab
This commit is contained in:
16 files changed
+201
-4
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
export default class FragmentPrincipal extends Fragment {
|
||||
|
||||
// =attributes
|
||||
|
||||
@attr('string', {
|
||||
description: 'ID of the related scope'
|
||||
}) scope_id;
|
||||
|
||||
@attr('string', {
|
||||
description: 'ID of the related principal (user or group)'
|
||||
}) principal_id;
|
||||
|
||||
@attr('string', {
|
||||
description: 'Type of the related principal (user or group)'
|
||||
}) type;
|
||||
|
||||
}
|
||||
@@ -5,6 +5,15 @@ export default class RoleModel extends GeneratedRoleModel {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Principals are users and groups assigned to a role. They are represented
|
||||
* as references to User and Group instances. Since Ember Data relationships
|
||||
* are wanting, we do not model these as a polymorphic relationship as might
|
||||
* see obvious. Instead, the application layer is expected to load referenced
|
||||
* users and groups as needed.
|
||||
*/
|
||||
@fragmentArray('fragment-principal', {readOnly: true}) principals;
|
||||
|
||||
/**
|
||||
* Grants is read-only _most_ under normal circumstances. But grants can
|
||||
* be persisted via a dedicated call to `saveGrants()`.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import JSONSerializer from '@ember-data/serializer/json';
|
||||
|
||||
export default class FragmentPrincipalSerializer extends JSONSerializer {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Renames `id` to `principal_id` because fragments may not have IDs.
|
||||
* Otherwise normalizes as normal.
|
||||
* @param {ModelClass} typeClass
|
||||
* @param {object} resourceHash
|
||||
* @return {object}
|
||||
*/
|
||||
normalize(typeClass, { id: principal_id, ...obj }) {
|
||||
return super.normalize(typeClass, { principal_id, ...obj });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/models/fragment-principal';
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/serializers/fragment-principal';
|
||||
@@ -0,0 +1,13 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | fragment principal', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('fragment-principal', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import FragmentPrincipal from 'api/models/fragment-principal';
|
||||
|
||||
module('Unit | Serializer | fragment principal', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it normalizes `id` into `principal_id`', function(assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('fragment-principal');
|
||||
const normalized = serializer.normalize(FragmentPrincipal, {
|
||||
scope_id: '1',
|
||||
principal_id: '2',
|
||||
type: 'user'
|
||||
});
|
||||
assert.deepEqual(normalized, {
|
||||
data: {
|
||||
attributes: {
|
||||
scope_id: '1',
|
||||
principal_id: '2',
|
||||
type: 'user'
|
||||
},
|
||||
id: null,
|
||||
relationships: {},
|
||||
type: 'fragment-principal'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user