chore: 🤖 rename grants to grantStrings and clean up comments

This commit is contained in:
Randall Morey committed 2020-10-30 15:33:08 -04:00
1 parent efa851928a
commit 3016d855ae
7 files changed
+27 -19

No files matched your search

+2 -2
View File
@@ -6,8 +6,8 @@ export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
/**
* Grants is read-only _most_ under normal circumstances. But grants can
* be persisted via a dedicated call to `saveGrants()`.
* Host IDs are read-only under normal circumstances. But these can
* be persisted via a dedicated call to `addHosts()`.
*/
@fragmentArray('fragment-string', {
readOnly: true,
+6 -6
View File
@@ -18,24 +18,24 @@ export default class RoleModel extends GeneratedRoleModel {
principals;
/**
* Grants is read-only. But grants can be persisted via a dedicated
* call to `saveGrants(grants)`.
* Grant strings are read-only. But grants can be persisted via a dedicated
* call to `saveGrantStrings(grants)`.
*/
@array('string', { readOnly: true }) grant_strings;
// =methods
/**
* Saves the `grants` array on the role via the `set-grants` method.
* Saves grant strings on the role via the `set-grants` method.
* See serializer and adapter for more information.
* @param {[string]} grants
* @param {[string]} grantStrings
* @return {Promise}
*/
saveGrants(grants) {
saveGrantStrings(grantStrings) {
return this.save({
adapterOptions: {
method: 'set-grants',
grants
grantStrings
},
});
}
+6 -5
View File
@@ -15,9 +15,10 @@ export default class RoleSerializer extends ApplicationSerializer {
* @return {object}
*/
serialize(snapshot) {
const grants = get(snapshot, 'adapterOptions.grants');
const grantStrings = get(snapshot, 'adapterOptions.grantStrings');
let serialized = super.serialize(...arguments);
if (grants) serialized = this.serializeWithGrants(snapshot, grants);
if (grantStrings) serialized =
this.serializeWithGrantStrings(snapshot, grantStrings);
const principalIDs = snapshot?.adapterOptions?.principalIDs;
if (principalIDs)
serialized = this.serializewithPrincipals(snapshot, principalIDs);
@@ -27,13 +28,13 @@ export default class RoleSerializer extends ApplicationSerializer {
/**
* Returns a payload containing only the grants array.
* @param {Snapshot} snapshot
* @param {[string]} grants
* @param {[string]} grantStrings
* @return {object}
*/
serializeWithGrants(snapshot, grants) {
serializeWithGrantStrings(snapshot, grantStrings) {
return {
version: snapshot.attr('version'),
grant_strings: grants
grant_strings: grantStrings
};
}
+2 -2
View File
@@ -12,7 +12,7 @@ module('Unit | Model | role', function (hooks) {
assert.ok(model);
});
test('it has a `saveGrants` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has a `saveGrantStrings` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post('/v1/roles/123abc:set-grants', (schema, request) => {
const body = JSON.parse(request.requestBody);
@@ -40,7 +40,7 @@ module('Unit | Model | role', function (hooks) {
},
});
const model = store.peekRecord('role', '123abc');
await model.saveGrants(['foo', 'bar']);
await model.saveGrantStrings(['foo', 'bar']);
});
test('it has an `addPrincipals` method that targets a specific POST API endpoint and serialization', async function (assert) {
@@ -24,7 +24,7 @@ module('Unit | Serializer | role', function (hooks) {
});
});
test('it serializes only grants when `adapterOptions.grants` is set', function (assert) {
test('it serializes only grant strings when `adapterOptions.grantStrings` is set', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('role');
@@ -36,7 +36,7 @@ module('Unit | Serializer | role', function (hooks) {
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
grants: ['foo', 'bar'],
grantStrings: ['foo', 'bar'],
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
@@ -10,11 +10,17 @@ export default class FormRoleGrantsComponent extends Component {
*/
@tracked newGrantString = '';
/**
* @type {[object]}
*/
@computed('args.model.grant_strings.[]')
get grants() {
return this.args.model.grant_strings.map(value => ({ value }));
}
/**
* @type {[string]}
*/
@computed('grants.@each.value')
get grantStrings() {
return this.grants.map(obj => obj.value);
@@ -54,12 +54,13 @@ export default class ScopesScopeRolesRoleGrantsRoute extends Route {
/**
* Save an role in current scope.
* @param {RoleModel} role
* @param {[string]} grantStrings
*/
@action
@loading
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.save-success')
async save(role, grants) {
await role.saveGrants(grants);
async save(role, grantStrings) {
await role.saveGrantStrings(grantStrings);
}
}