mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
63070673d2
closes https://github.com/TryGhost/Ghost/issues/12112 - perform a paid members list query with a limit of 1 when the modal is displayed if the post is set to members only, then use the pagination meta data to get a total number of members - display a spinner and disable the confirm button whilst the count query is in progress - does not display any counts for users with the Editor role as they do not have permission to list members
69 lines
2.0 KiB
JavaScript
69 lines
2.0 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default ModalComponent.extend({
|
|
session: service(),
|
|
store: service(),
|
|
|
|
errorMessage: null,
|
|
paidMemberCount: null,
|
|
|
|
// Allowed actions
|
|
confirm: () => {},
|
|
|
|
countPaidMembers: action(function () {
|
|
// TODO: remove editor conditional once editors can query member counts
|
|
if (this.model.paidOnly && !this.session.get('user.isEditor')) {
|
|
this.countPaidMembersTask.perform();
|
|
}
|
|
}),
|
|
|
|
countPaidMembersTask: task(function* () {
|
|
const result = yield this.store.query('member', {filter: 'subscribed:true', paid: true, limit: 1, page: 1});
|
|
this.set('paidMemberCount', result.meta.pagination.total);
|
|
}),
|
|
|
|
confirmAndCheckErrorTask: task(function* () {
|
|
try {
|
|
yield this.confirm();
|
|
this.closeModal();
|
|
return true;
|
|
} catch (e) {
|
|
// switch to "failed" state if email fails
|
|
if (e && e.name === 'EmailFailedError') {
|
|
this.set('errorMessage', e.message);
|
|
return;
|
|
}
|
|
|
|
// close modal and continue with normal error handling if it was
|
|
// a non-email-related error
|
|
this.closeModal();
|
|
if (e) {
|
|
throw e;
|
|
}
|
|
}
|
|
}),
|
|
|
|
retryEmailTask: task(function* () {
|
|
try {
|
|
yield this.model.retryEmailSend();
|
|
this.closeModal();
|
|
return true;
|
|
} catch (e) {
|
|
// update "failed" state if email fails again
|
|
if (e && e.name === 'EmailFailedError') {
|
|
this.set('errorMessage', e.message);
|
|
return;
|
|
}
|
|
|
|
// TODO: test a non-email failure - maybe this needs to go through
|
|
// the notifications service
|
|
if (e) {
|
|
throw e;
|
|
}
|
|
}
|
|
})
|
|
});
|