diff --git a/ui/core/mirage/serializers/application.js b/ui/core/mirage/serializers/application.js index 1c3821b4b..7bfbc7cd7 100644 --- a/ui/core/mirage/serializers/application.js +++ b/ui/core/mirage/serializers/application.js @@ -32,6 +32,12 @@ export default RestSerializer.extend({ return underscore(attr); }, + keyForRelationshipId(relationshipName) { + return `${this._container.inflector.singularize( + underscore(relationshipName) + )}_id`; + }, + /** * Serialize items into a root key `items`. * @return {object} @@ -43,6 +49,22 @@ export default RestSerializer.extend({ return json; }, + /** + * Serialize scope into the payload, if set. + * @param {object} model + * @return {object} + */ + _hashForModel(model) { + const json = RestSerializer.prototype._hashForModel.apply(this, arguments); + if (model.scope) { + json.scope = { + id: model.scope.id, + type: model.scope.type + }; + } + return json; + }, + /** * Adds a root to the payload, since `root: false` doesn't appear to affect * the normalize method. diff --git a/ui/core/mirage/serializers/auth-method.js b/ui/core/mirage/serializers/auth-method.js index 3d0c37374..cabe9ee7b 100644 --- a/ui/core/mirage/serializers/auth-method.js +++ b/ui/core/mirage/serializers/auth-method.js @@ -1,22 +1,5 @@ import ApplicationSerializer from './application'; -import { underscore } from '@ember/string'; export default ApplicationSerializer.extend({ - 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; - } - + modelName: 'auth-method' }); diff --git a/ui/core/mirage/serializers/group.js b/ui/core/mirage/serializers/group.js index ca0f9b138..2854224f8 100644 --- a/ui/core/mirage/serializers/group.js +++ b/ui/core/mirage/serializers/group.js @@ -10,19 +10,9 @@ 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; } diff --git a/ui/core/mirage/serializers/host-catalog.js b/ui/core/mirage/serializers/host-catalog.js index 34277f96e..bab3f7aa0 100644 --- a/ui/core/mirage/serializers/host-catalog.js +++ b/ui/core/mirage/serializers/host-catalog.js @@ -1,22 +1,5 @@ import ApplicationSerializer from './application'; -import { underscore } from '@ember/string'; export default ApplicationSerializer.extend({ modelName: 'host-catalog', - - 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; - } - }); diff --git a/ui/core/mirage/serializers/host-set.js b/ui/core/mirage/serializers/host-set.js index 16d665375..bd680326e 100644 --- a/ui/core/mirage/serializers/host-set.js +++ b/ui/core/mirage/serializers/host-set.js @@ -10,20 +10,10 @@ 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.host_ids = model.hostIds; json.host_catalog_id = model.hostCatalogId; - json.scope = { - id: model.scope.id, - type: model.scope.type - }; return json; } diff --git a/ui/core/mirage/serializers/host.js b/ui/core/mirage/serializers/host.js index 4fb0353b4..ccd3994ca 100644 --- a/ui/core/mirage/serializers/host.js +++ b/ui/core/mirage/serializers/host.js @@ -1,22 +1,5 @@ import ApplicationSerializer from './application'; -import { underscore } from '@ember/string'; export default ApplicationSerializer.extend({ - modelName: 'host', - - 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; - } - + modelName: 'host' }); diff --git a/ui/core/mirage/serializers/role.js b/ui/core/mirage/serializers/role.js index 47623471d..159bdc56c 100644 --- a/ui/core/mirage/serializers/role.js +++ b/ui/core/mirage/serializers/role.js @@ -1,18 +1,10 @@ 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, @@ -24,12 +16,6 @@ export default ApplicationSerializer.extend({ type: 'group' })); json.principals = [ ...serializedUsers, ...serializedGroups ]; - - json.scope = { - id: model.scope.id, - type: model.scope.type - }; - return json; } }); diff --git a/ui/core/mirage/serializers/target.js b/ui/core/mirage/serializers/target.js index 8ced88cfc..c9c6935a0 100644 --- a/ui/core/mirage/serializers/target.js +++ b/ui/core/mirage/serializers/target.js @@ -10,12 +10,6 @@ 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); const { hostSets } = this.schema; @@ -24,10 +18,6 @@ export default ApplicationSerializer.extend({ const host_catalog_id = hostSet?.hostCatalog?.id; return { host_set_id, host_catalog_id }; }); - json.scope = { - id: model.scope.id, - type: model.scope.type - }; return json; } diff --git a/ui/core/mirage/serializers/user.js b/ui/core/mirage/serializers/user.js index 499b249eb..142cbf508 100644 --- a/ui/core/mirage/serializers/user.js +++ b/ui/core/mirage/serializers/user.js @@ -1,22 +1,5 @@ import ApplicationSerializer from './application'; -import { underscore } from '@ember/string'; export default ApplicationSerializer.extend({ - 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; - } - + modelName: 'user' });