mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Refactored members content gating check
no-issue
This commit is contained in:
parent
6c97db2c22
commit
15ffae211d
2 changed files with 6 additions and 58 deletions
|
@ -1,37 +1,11 @@
|
|||
const _ = require('lodash');
|
||||
const membersService = require('../../../../../../services/members');
|
||||
const labs = require('../../../../../../services/labs');
|
||||
|
||||
// Checks if request should hide members only content
|
||||
function hideMembersOnlyContent({visibility}, frame) {
|
||||
const PERMIT_CONTENT = false;
|
||||
const BLOCK_CONTENT = true;
|
||||
|
||||
if (visibility === 'public') {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
const requestFromMember = frame.original.context.member;
|
||||
|
||||
if (!requestFromMember) {
|
||||
return BLOCK_CONTENT;
|
||||
} else if (visibility === 'members') {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
const memberHasPlan = !!(_.get(frame, 'original.context.member.stripe.subscriptions', [])).length;
|
||||
|
||||
if (visibility === 'paid' && memberHasPlan) {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
return BLOCK_CONTENT;
|
||||
}
|
||||
|
||||
const forPost = (attrs, frame) => {
|
||||
if (labs.isSet('members')) {
|
||||
const hideFormatsData = hideMembersOnlyContent(attrs, frame);
|
||||
const memberHasAccess = membersService.contentGating.checkPostAccess(attrs, frame.original.context.member);
|
||||
|
||||
if (hideFormatsData) {
|
||||
if (!memberHasAccess) {
|
||||
['plaintext', 'html'].forEach((field) => {
|
||||
attrs[field] = '';
|
||||
});
|
||||
|
|
|
@ -1,37 +1,11 @@
|
|||
const _ = require('lodash');
|
||||
const membersService = require('../../../../../../services/members');
|
||||
const labs = require('../../../../../../services/labs');
|
||||
|
||||
// Checks if request should hide members only content
|
||||
function hideMembersOnlyContent({visibility}, frame) {
|
||||
const PERMIT_CONTENT = false;
|
||||
const BLOCK_CONTENT = true;
|
||||
|
||||
if (visibility === 'public') {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
const requestFromMember = frame.original.context.member;
|
||||
|
||||
if (!requestFromMember) {
|
||||
return BLOCK_CONTENT;
|
||||
} else if (visibility === 'members') {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
const memberHasPlan = !!(_.get(frame, 'original.context.member.stripe.subscriptions', [])).length;
|
||||
|
||||
if (visibility === 'paid' && memberHasPlan) {
|
||||
return PERMIT_CONTENT;
|
||||
}
|
||||
|
||||
return BLOCK_CONTENT;
|
||||
}
|
||||
|
||||
const forPost = (attrs, frame) => {
|
||||
if (labs.isSet('members')) {
|
||||
const hideFormatsData = hideMembersOnlyContent(attrs, frame);
|
||||
const memberHasAccess = membersService.contentGating.checkPostAccess(attrs, frame.original.context.member);
|
||||
|
||||
if (hideFormatsData) {
|
||||
if (!memberHasAccess) {
|
||||
['plaintext', 'html'].forEach((field) => {
|
||||
attrs[field] = '';
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue