Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added content-gating module to members service
no-issue This should be used as the central place to manage permissions to members content
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters