0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Added custom segment option for default post access setting

refs https://github.com/TryGhost/Team/issues/803

With multiple products we'll re-enable segmentation by product for posts, which also means need to add a new option to the default post access setting in Membership settings. This change -

- adds new `A segment` option to default post access dropdown behind the alpha flag for multiple products
- shows member segment select dropdown for `A segment` option
- handles update of `defaultContentVisibility` to allow setting custom filter
This commit is contained in:
Rishabh 2021-07-02 22:00:14 +05:30 committed by Rishabh Garg
parent 6feb14b839
commit 450ad78f61
3 changed files with 51 additions and 4 deletions

View file

@ -23,4 +23,16 @@
</div> </div>
</div> </div>
</PowerSelect> </PowerSelect>
{{#if this.hasVisibilityFilter}}
<div class="mt2">
<GhMembersSegmentSelect
@hideLabels={{true}}
@segment={{this.settings.defaultContentVisibility}}
@onChange={{action "setVisibility"}}
@renderInPlace={{true}}
@hideDefaultSegments={{true}}
@hideOptionsWhenAllSelected={{true}}
/>
</div>
{{/if}}
</div> </div>

View file

@ -4,9 +4,10 @@ import {inject as service} from '@ember/service';
export default class SettingsMembersDefaultPostAccess extends Component { export default class SettingsMembersDefaultPostAccess extends Component {
@service settings; @service settings;
@service feature;
get options() { get options() {
return [{ const defaultOptions = [{
name: 'Public', name: 'Public',
description: 'All site visitors to your site, no login required', description: 'All site visitors to your site, no login required',
value: 'public', value: 'public',
@ -25,20 +26,47 @@ export default class SettingsMembersDefaultPostAccess extends Component {
icon: 'members-paid', icon: 'members-paid',
icon_color: 'pink' icon_color: 'pink'
}]; }];
if (this.feature.get('multipleProducts')) {
defaultOptions.push({
name: 'A segment',
description: 'Members with any of the selected products',
value: 'filter',
icon: 'members-paid',
icon_color: 'yellow'
});
}
return defaultOptions;
}
get hasVisibilityFilter() {
return this.feature.get('multipleProducts') && !['public', 'members', 'paid'].includes(this.settings.get('defaultContentVisibility'));
} }
get selectedOption() { get selectedOption() {
if (this.settings.get('membersSignupAccess') === 'none') { if (this.settings.get('membersSignupAccess') === 'none') {
return this.options.find(o => o.value === 'public'); return this.options.find(o => o.value === 'public');
} }
if (!['public', 'members', 'paid'].includes(this.settings.get('defaultContentVisibility'))) {
return this.options.find(o => o.value === 'filter');
}
return this.options.find(o => o.value === this.settings.get('defaultContentVisibility')); return this.options.find(o => o.value === this.settings.get('defaultContentVisibility'));
} }
@action
setVisibility(segment) {
if (segment) {
this.settings.set('defaultContentVisibility', segment);
}
}
@action @action
setDefaultContentVisibility(option) { setDefaultContentVisibility(option) {
if (this.settings.get('membersSignupAccess') !== 'none') { if (this.settings.get('membersSignupAccess') !== 'none') {
if (option.value === 'filter') {
this.settings.set('defaultContentVisibility', '');
} else {
this.settings.set('defaultContentVisibility', option.value); this.settings.set('defaultContentVisibility', option.value);
} }
} }
}
} }

View file

@ -316,6 +316,13 @@ export default class MembersAccessController extends Controller {
@task({drop: true}) @task({drop: true})
*saveSettingsTask(options) { *saveSettingsTask(options) {
if (!this.settings.get('defaultContentVisibility')) {
const oldValue = this.settings.changedAttributes().defaultContentVisibility?.[0];
if (oldValue) {
this.settings.set('defaultContentVisibility', oldValue);
}
}
if (!this.feature.get('multipleProducts')) { if (!this.feature.get('multipleProducts')) {
yield this.validateStripePlans({updatePortalPreview: false}); yield this.validateStripePlans({updatePortalPreview: false});