Ghost/ghost/admin/app/components/gh-psm-visibility-input.js
Rishabh Garg 7c5b14d050 Updated specific tier visibility handling for posts/pages (#2233)
refs TryGhost/Team#1071

Specific tier visibility for a post was previously stored in `visibility` column directly, which had a limitation of 50 charts. Going forward, for the specific tiers visibility of post/page, we use `tiers` array in API that contains list of tiers with access for post. This change -

- replaces `filter` type to `tiers` for visibility
- adds new visibility filter segment component in post settings menu which stores array of tiers instead of nql string for visibility
- updates serializer and model for post/page
- updates tests
2022-02-01 12:24:06 +05:30

42 lines
1.1 KiB
JavaScript

import Component from '@ember/component';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
const VISIBILITIES = [
{label: 'Public', name: 'public'},
{label: 'Members only', name: 'members'},
{label: 'Paid-members only', name: 'paid'}
];
export default Component.extend({
settings: service(),
feature: service(),
// public attrs
post: null,
selectedVisibility: computed('post.visibility', function () {
return this.get('post.visibility') || this.settings.get('defaultContentVisibility');
}),
init() {
this._super(...arguments);
this.availableVisibilities = [...VISIBILITIES];
if (this.feature.get('multipleProducts')) {
this.availableVisibilities.push(
{label: 'Specific tier(s)', name: 'tiers'}
);
}
},
actions: {
updateVisibility(newVisibility) {
this.post.set('visibility', newVisibility);
if (newVisibility !== 'tiers') {
this.post.set('tiers', []);
}
}
}
});