mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
6af2706f10
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
38 lines
735 B
JavaScript
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
|
|
};
|