Ghost/ghost/admin/app/models/invite.js
naz 238632402c 🐛 Fixed host limit error when resending a pending invite (#1881)
refs https://github.com/TryGhost/Team/issues/587
refs e30b9735fa

- It was not possible to invite a new Contributor to a site that has reached its limit
- This fix divides the resend invite action into two separate steps: 1. Deleting existing invite 2. Creating a new one for the same data
- It was hitting the limit because the permissions were correctly checking for "add" action being executed when the limit of invites/staff users was already used up. By removing existing invite we mimic the behavior the server would do for us anyway (2111992dd4/core/server/services/invites/invites.js (L18-L22))

Co-authored-by: Rish <zrishabhgarg@gmail.com>
2021-04-06 15:10:03 +12:00

36 lines
975 B
JavaScript

import Model, {attr, belongsTo} from '@ember-data/model';
import {inject as service} from '@ember/service';
export default Model.extend({
token: attr('string'),
email: attr('string'),
expires: attr('number'),
createdAtUTC: attr('moment-utc'),
createdBy: attr('number'),
updatedAtUTC: attr('moment-utc'),
updatedBy: attr('number'),
status: attr('string'),
role: belongsTo('role', {async: false}),
ajax: service(),
ghostPaths: service(),
resend() {
let inviteData = {
email: this.email,
role_id: this.role.id
};
let inviteUrl = this.get('ghostPaths.url').api('invites');
return this.ajax.del(`${inviteUrl}${this.get('id')}`)
.then(() => {
return this.ajax.post(inviteUrl, {
data: JSON.stringify({invites: [inviteData]}),
contentType: 'application/json'
});
});
}
});