Skip to content

Commit

Permalink
Merge pull request #7982 from Turbo87/fix-inviter-column
Browse files Browse the repository at this point in the history
Fix "Invited by" column
  • Loading branch information
Turbo87 authored Jan 23, 2024
2 parents eb5eaf2 + 548e0b4 commit 50aa541
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/components/pending-owner-invite-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</div>
<div>
Invited by:
<LinkTo @route="user" @model={{@invite.invited_by_username}} data-test-inviter-link>
{{@invite.invited_by_username}}
<LinkTo @route="user" @model={{@invite.inviter.login}} data-test-inviter-link>
{{@invite.inviter.login}}
</LinkTo>
</div>
<div local-class="date-column" data-test-date>
Expand Down
5 changes: 3 additions & 2 deletions app/models/crate-owner-invite.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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;
@attr crate_name;
@attr crate_id;
@attr('date') created_at;
@attr accepted;
@belongsTo('user', { async: false, inverse: null }) invitee;
@belongsTo('user', { async: false, inverse: null }) inviter;
}
14 changes: 7 additions & 7 deletions app/serializers/crate-owner-invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ 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);
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`;
}
}
3 changes: 0 additions & 3 deletions mirage/serializers/crate-owner-invitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
});
2 changes: 0 additions & 2 deletions tests/mirage/me/crate-owner-invitations/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ 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),
},
{
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),
},
Expand Down
3 changes: 0 additions & 3 deletions tests/mirage/private/crate-owner-invitations/get-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ 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),
},
{
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),
},
Expand Down Expand Up @@ -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),
},
Expand Down

0 comments on commit 50aa541

Please sign in to comment.