From e1c7360075c7d01b7de0f689d10af222cfdd0897 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 11 May 2022 21:05:31 +0100 Subject: [PATCH] Fixed errors in publish flow for users who don't have email permission no issue - roles that don't have email permissions also don't have permissions to read newsletters so we shouldn't attempt to fetch any during PublishOptions setup --- ghost/admin/app/utils/publish-options.js | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ghost/admin/app/utils/publish-options.js b/ghost/admin/app/utils/publish-options.js index e35898a77a..b9624efc9b 100644 --- a/ghost/admin/app/utils/publish-options.js +++ b/ghost/admin/app/utils/publish-options.js @@ -239,26 +239,30 @@ export default class PublishOptions { @task *fetchRequiredDataTask() { - // total # of members - used to enable/disable email - let countTotalMembers = Promise.resolve(); + const promises = []; - // only Admins/Owners have permission to browse members and get a count + // total # of members - used to enable/disable email + // 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) => { + promises.push(this.store.query('member', {limit: 1}).then((res) => { this.totalMemberCount = res.meta.pagination.total; - }); + })); } else { this.totalMemberCount = 1; } - // email limits - const checkSendingLimit = this._checkSendingLimit(); + // only perform limit checks and newsletter fetches if the + // current user is allowed to email, otherwise we can hit API + // permission errors + if (this.user.canEmail) { + // email limits + promises.push(this._checkSendingLimit()); + // newsletters + promises.push(this.store.query('newsletter', {status: 'active', limit: 'all', include: 'count.members'})); + } - // newsletters - const fetchNewsletters = this.store.query('newsletter', {status: 'active', limit: 'all', include: 'count.members'}); - - yield Promise.all([countTotalMembers, checkSendingLimit, fetchNewsletters]); + yield Promise.all(promises); } // saving ------------------------------------------------------------------