mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
19d5448101
no issue Comped members were not able to view paid-member content because content gating was only looking for `member.status === 'paid'` which doesn't take into consideration members on a "complimentary" plan. - added front-end acceptance tests for member access to posts - updated content-gating check to take comped members into consideration
38 lines
784 B
JavaScript
38 lines
784 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' || member.status === 'comped' || member.comped)) {
|
|
return PERMIT_ACCESS;
|
|
}
|
|
|
|
return BLOCK_ACCESS;
|
|
}
|
|
|
|
module.exports = {
|
|
checkPostAccess,
|
|
PERMIT_ACCESS,
|
|
BLOCK_ACCESS
|
|
};
|