2020-07-23 20:30:07 +03:00
|
|
|
const config = require('../../../shared/config');
|
2020-08-27 03:52:36 +03:00
|
|
|
const models = require('../../models');
|
2020-07-23 20:30:07 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
|
|
|
|
// Get total members direct from DB
|
|
|
|
async function getTotalMembers() {
|
2020-08-27 03:52:36 +03:00
|
|
|
return models.Member.count('id');
|
2020-07-23 20:30:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = async () => {
|
|
|
|
const membersHostLimit = config.get('host_settings:limits:members');
|
|
|
|
if (membersHostLimit) {
|
|
|
|
const allowedMembersLimit = membersHostLimit.max;
|
|
|
|
const hostUpgradeLink = config.get('host_settings:limits').upgrade_url;
|
|
|
|
|
|
|
|
const totalMembers = await getTotalMembers();
|
|
|
|
|
|
|
|
if (totalMembers > allowedMembersLimit) {
|
|
|
|
throw new errors.HostLimitError({
|
2020-07-23 20:30:55 +03:00
|
|
|
message: `Your current plan allows you to have up to ${allowedMembersLimit} members, but you currently have ${totalMembers} members`,
|
2020-07-23 20:30:07 +03:00
|
|
|
help: hostUpgradeLink,
|
|
|
|
errorDetails: {
|
|
|
|
limit: allowedMembersLimit,
|
|
|
|
total: totalMembers
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|