From 19566d5e9d806d676d3e70ce6f23f8ffae1814b5 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 22 Jan 2024 17:51:13 +0100 Subject: [PATCH 1/4] serializers/crate-owner-invite: Fix `users` side-loading Previously, the `normalizeResponse()` implementation was throwing away the `users` array in the payload, because of a "missing id" issue (see https://github.com/rust-lang/crates.io/pull/3490). The root cause for that however was not that the `id` field in the `user` objects was missing (it actually exists), but that the `modelNameFromPayloadKey()` implementation was unconditionally returning `'crate-owner-invite'` even for `user` payloads. This change fixes the `modelNameFromPayloadKey()` implementation to be compatible with `user` payloads and removes the now obsolete `normalizeResponse()` implementation. --- app/serializers/crate-owner-invite.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/serializers/crate-owner-invite.js b/app/serializers/crate-owner-invite.js index 15ef3c9f259..867a98e5f2d 100644 --- a/app/serializers/crate-owner-invite.js +++ b/app/serializers/crate-owner-invite.js @@ -3,19 +3,12 @@ import ApplicationSerializer from './application'; export default class CrateOwnerInviteSerializer extends ApplicationSerializer { primaryKey = 'crate_id'; - modelNameFromPayloadKey() { + modelNameFromPayloadKey(payloadKey) { + if (payloadKey === 'users') return 'user'; return 'crate-owner-invite'; } payloadKeyFromModelName() { return 'crate_owner_invite'; } - - normalizeResponse(store, schema, payload, id, requestType) { - if (payload.users) { - delete payload.users; - } - - return super.normalizeResponse(store, schema, payload, id, requestType); - } } From 3f4c417893c3724eaf1cae6091ac92681d240d0f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 22 Jan 2024 17:52:05 +0100 Subject: [PATCH 2/4] models/crate-owner-invite: Add `inviter` and `invitee` relationships --- app/models/crate-owner-invite.js | 4 +++- app/serializers/crate-owner-invite.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/crate-owner-invite.js b/app/models/crate-owner-invite.js index 84f1167aee3..d181d340842 100644 --- a/app/models/crate-owner-invite.js +++ b/app/models/crate-owner-invite.js @@ -1,4 +1,4 @@ -import Model, { attr } from '@ember-data/model'; +import Model, { attr, belongsTo } from '@ember-data/model'; export default class CrateOwnerInvite extends Model { @attr invited_by_username; @@ -6,4 +6,6 @@ export default class CrateOwnerInvite extends Model { @attr crate_id; @attr('date') created_at; @attr accepted; + @belongsTo('user', { async: false, inverse: null }) invitee; + @belongsTo('user', { async: false, inverse: null }) inviter; } diff --git a/app/serializers/crate-owner-invite.js b/app/serializers/crate-owner-invite.js index 867a98e5f2d..2fbe11050d3 100644 --- a/app/serializers/crate-owner-invite.js +++ b/app/serializers/crate-owner-invite.js @@ -11,4 +11,11 @@ export default class CrateOwnerInviteSerializer extends ApplicationSerializer { payloadKeyFromModelName() { return 'crate_owner_invite'; } + + keyForRelationship(key) { + // Ember Data expects e.g. an `inviter` key in the payload, but the backend + // uses `inviter_id` instead. This method makes sure that Ember Data can + // find the correct relationship. + return `${key}_id`; + } } From 8952d18d6dd8e6b25b8de4ae73380b9b35fc8afd Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 22 Jan 2024 17:53:11 +0100 Subject: [PATCH 3/4] components/PendingOwnerInviteRow: Use `inviter.login` instead of `invited_by_username` field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `invited_by_username` isn't actually sent anymore by the v2 (aka. `private`) API and it had been showing an empty column for 14 months now... 😅 --- app/components/pending-owner-invite-row.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/pending-owner-invite-row.hbs b/app/components/pending-owner-invite-row.hbs index 67c8dad77e0..bad2d9e790b 100644 --- a/app/components/pending-owner-invite-row.hbs +++ b/app/components/pending-owner-invite-row.hbs @@ -19,8 +19,8 @@
Invited by: - - {{@invite.invited_by_username}} + + {{@invite.inviter.login}}
From 548e0b4104d5bb524cac6f1f2ee9869f90548c1b Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 22 Jan 2024 17:54:14 +0100 Subject: [PATCH 4/4] models/crate-owner-invite: Remove obsolete `invited_by_username` field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `invited_by_username` isn't actually sent anymore by the v2 (aka. `private`) API and it had been showing an empty column for 14 months now... 😅 --- app/models/crate-owner-invite.js | 1 - mirage/serializers/crate-owner-invitation.js | 3 --- tests/mirage/me/crate-owner-invitations/list-test.js | 2 -- tests/mirage/private/crate-owner-invitations/get-test.js | 3 --- 4 files changed, 9 deletions(-) diff --git a/app/models/crate-owner-invite.js b/app/models/crate-owner-invite.js index d181d340842..6a3972d47d9 100644 --- a/app/models/crate-owner-invite.js +++ b/app/models/crate-owner-invite.js @@ -1,7 +1,6 @@ import Model, { attr, belongsTo } from '@ember-data/model'; export default class CrateOwnerInvite extends Model { - @attr invited_by_username; @attr crate_name; @attr crate_id; @attr('date') created_at; diff --git a/mirage/serializers/crate-owner-invitation.js b/mirage/serializers/crate-owner-invitation.js index 85ec23bef00..984bdaed1d3 100644 --- a/mirage/serializers/crate-owner-invitation.js +++ b/mirage/serializers/crate-owner-invitation.js @@ -31,8 +31,5 @@ export default BaseSerializer.extend({ hash.invitee_id = Number(hash.invitee_id); hash.inviter_id = Number(hash.inviter_id); - - let inviter = this.schema.users.find(hash.inviter_id); - hash.invited_by_username = inviter.login; }, }); diff --git a/tests/mirage/me/crate-owner-invitations/list-test.js b/tests/mirage/me/crate-owner-invitations/list-test.js index 8ae83a10c8d..8991d78717d 100644 --- a/tests/mirage/me/crate-owner-invitations/list-test.js +++ b/tests/mirage/me/crate-owner-invitations/list-test.js @@ -52,7 +52,6 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) { crate_id: Number(nanomsg.id), crate_name: 'nanomsg', created_at: '2016-12-24T12:34:56Z', - invited_by_username: 'janed', invitee_id: Number(user.id), inviter_id: Number(inviter.id), }, @@ -60,7 +59,6 @@ module('Mirage | GET /api/v1/me/crate_owner_invitations', function (hooks) { crate_id: Number(ember.id), crate_name: 'ember-rs', created_at: '2020-12-31T12:34:56Z', - invited_by_username: 'wycats', invitee_id: Number(user.id), inviter_id: Number(inviter2.id), }, diff --git a/tests/mirage/private/crate-owner-invitations/get-test.js b/tests/mirage/private/crate-owner-invitations/get-test.js index 71b004f6ace..68dee52bd32 100644 --- a/tests/mirage/private/crate-owner-invitations/get-test.js +++ b/tests/mirage/private/crate-owner-invitations/get-test.js @@ -43,7 +43,6 @@ module('Mirage | GET /api/private/crate_owner_invitations', function (hooks) { crate_id: Number(nanomsg.id), crate_name: 'nanomsg', created_at: '2016-12-24T12:34:56Z', - invited_by_username: 'janed', invitee_id: Number(user.id), inviter_id: Number(inviter.id), }, @@ -51,7 +50,6 @@ module('Mirage | GET /api/private/crate_owner_invitations', function (hooks) { crate_id: Number(ember.id), crate_name: 'ember-rs', created_at: '2020-12-31T12:34:56Z', - invited_by_username: 'wycats', invitee_id: Number(user.id), inviter_id: Number(inviter2.id), }, @@ -159,7 +157,6 @@ module('Mirage | GET /api/private/crate_owner_invitations', function (hooks) { crate_id: Number(ember.id), crate_name: 'ember-rs', created_at: '2020-12-31T12:34:56Z', - invited_by_username: 'wycats', invitee_id: Number(user.id), inviter_id: Number(inviter2.id), },