mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
6c97db2c22
no-issue This should be used as the central place to manage permissions to members content
40 lines
835 B
JavaScript
40 lines
835 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;
|
|
}
|
|
|
|
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
|
|
};
|