Ghost/core/server/services/members/content-gating.js
Fabien 'egg' O'Carroll 6af2706f10
Updated Admin API and Mega to use status flag (#12579)
no-issue

* Removed support for paid param from v3 & canary API
* Updated active subscription checks to use status flag
* Updated MEGA to use status filter over paid flag
* Removed support for paid option at model level
* Installed @tryghost/members-api@1.0.0-rc.0
* Updated members fixtures
2021-02-02 16:12:51 +00:00

38 lines
735 B
JavaScript

// @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;
}
if (post.visibility === 'paid' && member.status === 'paid') {
return PERMIT_ACCESS;
}
return BLOCK_ACCESS;
}
module.exports = {
checkPostAccess,
PERMIT_ACCESS,
BLOCK_ACCESS
};