mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added content-gating module to members service
no-issue This should be used as the central place to manage permissions to members content
This commit is contained in:
parent
0689ae9657
commit
6c97db2c22
2 changed files with 41 additions and 0 deletions
39
core/server/services/members/content-gating.js
Normal file
39
core/server/services/members/content-gating.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
// @ts-check
|
||||
/** @typedef { boolean } AccessFlag */
|
||||
|
||||
const PERMIT_ACCESS = true;
|
||||
const BLOCK_ACCESS = false;
|
||||
|
||||
/**
|
||||
* @param {object} post - A post object to check access to
|
||||
* @param {object} member - The member whos access should be checked
|
||||
*
|
||||
* @returns {AccessFlag}
|
||||
*/
|
||||
function checkPostAccess(post, member) {
|
||||
if (post.visibility === 'public') {
|
||||
return PERMIT_ACCESS;
|
||||
}
|
||||
|
||||
if (!member) {
|
||||
return BLOCK_ACCESS;
|
||||
}
|
||||
|
||||
if (post.visibility === 'members') {
|
||||
return PERMIT_ACCESS;
|
||||
}
|
||||
|
||||
const memberHasPlan = member.stripe && member.stripe.subscriptions && member.stripe.subscriptions.length;
|
||||
|
||||
if (post.visibility === 'paid' && memberHasPlan) {
|
||||
return PERMIT_ACCESS;
|
||||
}
|
||||
|
||||
return BLOCK_ACCESS;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkPostAccess,
|
||||
PERMIT_ACCESS,
|
||||
BLOCK_ACCESS
|
||||
};
|
|
@ -28,6 +28,8 @@ const membersService = {
|
|||
return !!settings && settings.isPaid && settings.paymentProcessors.length !== 0;
|
||||
},
|
||||
|
||||
contentGating: require('./content-gating'),
|
||||
|
||||
get api() {
|
||||
if (!membersApi) {
|
||||
membersApi = createMembersApiInstance();
|
||||
|
|
Loading…
Reference in a new issue