mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Improved handling of missing member counts in publish flow
no issue Only Admins/Owners can browse members to get member counts but Editors/Authors are allowed to send email. This means we need to account for the count figures being missing. - added guard to the total member count fetch in `PublishOptions` - guard needed because the failed API request would abort setup - when the current user isn't an admin, set the total member count to 1 to avoid email options being disabled - added guard in the `{{members-count-fetcher}}` resource so we're not triggering API errors and the count is kept as `null` so it's handled automatically if passed to `{{gh-pluralize}}` - updated `<GhMembersRecipientSelect>` to not show counts (or the surrounding `()`) when the count is `null`
This commit is contained in:
parent
02ccf5fe1a
commit
6c079daafa
3 changed files with 25 additions and 5 deletions
ghost/admin/app
|
@ -2,7 +2,9 @@
|
|||
<p>
|
||||
Free subscribers
|
||||
{{#let (members-count-fetcher query=(hash filter=(concat @newsletter.recipientFilter "+status:free"))) as |countFetcher|}}
|
||||
<span class="gh-publishmenu-emailcount" data-test-email-count="free-members">({{countFetcher.count}})</span>
|
||||
{{#if (not (is-empty countFetcher.count))}}
|
||||
<span class="gh-publishmenu-emailcount" data-test-email-count="free-members">({{countFetcher.count}})</span>
|
||||
{{/if}}
|
||||
{{/let}}
|
||||
</p>
|
||||
<div class="for-switch small {{if @disabled "disabled"}}">
|
||||
|
@ -26,7 +28,9 @@
|
|||
<p>
|
||||
Paid subscribers
|
||||
{{#let (members-count-fetcher query=(hash filter=(concat @newsletter.recipientFilter "+status:-free"))) as |countFetcher|}}
|
||||
<span class="gh-publishmenu-emailcount" data-test-email-count="paid-members">({{countFetcher.count}})</span>
|
||||
{{#if (not (is-empty countFetcher.count))}}
|
||||
<span class="gh-publishmenu-emailcount" data-test-email-count="paid-members">({{countFetcher.count}})</span>
|
||||
{{/if}}
|
||||
{{/let}}
|
||||
</p>
|
||||
<div class="for-switch small {{if @disabled "disabled"}}">
|
||||
|
|
|
@ -5,6 +5,7 @@ import {tracked} from '@glimmer/tracking';
|
|||
|
||||
export default class MembersCount extends Resource {
|
||||
@service membersCountCache;
|
||||
@service session;
|
||||
|
||||
@tracked count = null;
|
||||
|
||||
|
@ -33,6 +34,13 @@ export default class MembersCount extends Resource {
|
|||
|
||||
@task
|
||||
*fetchMembersTask({query} = {}) {
|
||||
// Only Admins/Owners have access to the /members/ endpoint to fetch a count.
|
||||
// For other roles simply leave it as `null` so templates can react accordingly
|
||||
if (!this.session.user.isAdmin) {
|
||||
this.count = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const count = yield this.membersCountCache.count(query);
|
||||
this.count = count;
|
||||
}
|
||||
|
|
|
@ -240,9 +240,17 @@ export default class PublishOptions {
|
|||
@task
|
||||
*fetchRequiredDataTask() {
|
||||
// total # of members - used to enable/disable email
|
||||
const countTotalMembers = this.store.query('member', {limit: 1}).then((res) => {
|
||||
this.totalMemberCount = res.meta.pagination.total;
|
||||
});
|
||||
let countTotalMembers = Promise.resolve();
|
||||
|
||||
// only Admins/Owners have permission to browse members and get a count
|
||||
// for Editors/Authors set member count to 1 so email isn't disabled for not having any members
|
||||
if (this.user.isAdmin) {
|
||||
countTotalMembers = this.store.query('member', {limit: 1}).then((res) => {
|
||||
this.totalMemberCount = res.meta.pagination.total;
|
||||
});
|
||||
} else {
|
||||
this.totalMemberCount = 1;
|
||||
}
|
||||
|
||||
// email limits
|
||||
const checkSendingLimit = this._checkSendingLimit();
|
||||
|
|
Loading…
Add table
Reference in a new issue