2019-11-05 05:47:12 +03:00
|
|
|
// @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;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:13:48 +03:00
|
|
|
if (post.visibility === 'paid' && (member.status === 'paid' || member.status === 'comped' || member.comped)) {
|
2019-11-05 05:47:12 +03:00
|
|
|
return PERMIT_ACCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BLOCK_ACCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
checkPostAccess,
|
|
|
|
PERMIT_ACCESS,
|
|
|
|
BLOCK_ACCESS
|
|
|
|
};
|