diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index a74e8fe30..bbb7d46d9 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -183,12 +183,10 @@ export default function() { // target this.get('/targets', function ({ targets }, { queryParams: { scope_id } }) { - return targets.where(target => target.scope?.id === scope_id); + return targets.where(target => target.scopeId === scope_id); }); - this.post('/targets', function ({ targets, scopes }) { + this.post('/targets', function ({ targets }) { const attrs = this.normalizedRequestAttrs(); - const scope = scopes.findBy(scope => scope.id === attrs.scopeId); - attrs.scope = { id: scope.id, type: scope.type }; return targets.create(attrs); }); this.get('/targets/:id'); diff --git a/ui/core/mirage/models/target.js b/ui/core/mirage/models/target.js index d33295663..8c2757e71 100644 --- a/ui/core/mirage/models/target.js +++ b/ui/core/mirage/models/target.js @@ -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(), hostSets: hasMany() }); diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 7d4c343f8..d08c2fb75 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -12,25 +12,20 @@ export default function(server) { type: 'org', scope: { id: globalScope.id, type: globalScope.type } }, 'withChildren')[0]; - const scope = { id: orgScope.id, type: orgScope.type }; + const scopePojo = { id: orgScope.id, type: orgScope.type }; // Auth - - // Auth methods exist both at the global scope and the org scope. - // For simplicity we don't scope our mock auth methods and just return the - // same items for request at all scopes. - server.createList('auth-method', 3, { scope }); + server.createList('auth-method', 3, { scope: scopePojo }); // Groups and Users - server.createList('group', 5, { scope }, 'withMembers'); + server.createList('group', 5, { scope: scopePojo }, 'withMembers'); // Role - server.createList('role', 5, { scope }, 'withPrincipals'); + server.createList('role', 5, { scope: scopePojo }, 'withPrincipals'); // Other resources - - server.db.scopes.where({type: 'project'}).forEach(({ id, type }) => { - const scope = { id, type }; - server.createList('host-catalog', 2, { scope }, 'withChildren'); + server.schema.scopes.where({type: 'project'}).models.forEach(scope => { + const scopePojo = { id: scope.id, type: scope.type }; + server.createList('host-catalog', 2, { scope: scopePojo }, 'withChildren'); server.createList('target', 2, { scope }, 'withRandomHostSets'); }); diff --git a/ui/core/mirage/serializers/target.js b/ui/core/mirage/serializers/target.js index c9c6935a0..8ced88cfc 100644 --- a/ui/core/mirage/serializers/target.js +++ b/ui/core/mirage/serializers/target.js @@ -10,6 +10,12 @@ 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; @@ -18,6 +24,10 @@ 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; }