From 758f5285fb5973cdab48da7a05ee5e0e773331cf Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 9 Jun 2020 12:19:25 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20access=20level=20filter=20t?= =?UTF-8?q?o=20posts=20and=20pages=20lists=20in=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - adds `visibility` query param to posts and pages controllers/routes that is tied to the `filter` query param used in API requests - adds dropdown for selecting post/page visibility to `` --- .../admin/app/components/gh-contentfilter.hbs | 18 +++++++++++ .../admin/app/components/gh-contentfilter.js | 2 ++ .../app/components/gh-post-settings-menu.hbs | 12 +++---- ghost/admin/app/controllers/posts-loading.js | 2 ++ ghost/admin/app/controllers/posts.js | 31 +++++++++++++++++-- ghost/admin/app/helpers/reset-query-params.js | 2 ++ ghost/admin/app/routes/posts.js | 4 ++- ghost/admin/app/templates/pages-loading.hbs | 3 ++ ghost/admin/app/templates/pages.hbs | 3 ++ ghost/admin/app/templates/posts-loading.hbs | 3 ++ ghost/admin/app/templates/posts.hbs | 3 ++ ghost/admin/tests/acceptance/content-test.js | 20 ++++++++++-- 12 files changed, 89 insertions(+), 14 deletions(-) diff --git a/ghost/admin/app/components/gh-contentfilter.hbs b/ghost/admin/app/components/gh-contentfilter.hbs index 7342f57af6..e490831426 100644 --- a/ghost/admin/app/components/gh-contentfilter.hbs +++ b/ghost/admin/app/components/gh-contentfilter.hbs @@ -17,6 +17,24 @@ {{/unless}} + {{#if this.feature.members}} +
+ + {{#if visibility.name}}{{visibility.name}}{{else}}Unknown visibility{{/if}} + +
+ {{/if}} + {{#unless @currentUser.isAuthorOrContributor}}
- - -
- {{/if}} + {{#if (and this.feature.members this.showVisibilityInput)}} +
+ + +
{{/if}} diff --git a/ghost/admin/app/controllers/posts-loading.js b/ghost/admin/app/controllers/posts-loading.js index 9da6036cf3..982e8f6203 100644 --- a/ghost/admin/app/controllers/posts-loading.js +++ b/ghost/admin/app/controllers/posts-loading.js @@ -11,6 +11,8 @@ export default Controller.extend({ availableTypes: readOnly('postsController.availableTypes'), selectedType: readOnly('postsController.selectedType'), + selectedVisibility: readOnly('postsController.selectedVisibility'), + availableVisibilities: readOnly('postsController.availableVisibilities'), availableTags: readOnly('postsController.availableTags'), selectedTag: readOnly('postsController.selectedTag'), availableAuthors: readOnly('postsController.availableAuthors'), diff --git a/ghost/admin/app/controllers/posts.js b/ghost/admin/app/controllers/posts.js index 9969416e0f..d3613111fc 100644 --- a/ghost/admin/app/controllers/posts.js +++ b/ghost/admin/app/controllers/posts.js @@ -22,6 +22,20 @@ const TYPES = [{ value: 'featured' }]; +const VISIBILITIES = [{ + name: 'All access', + value: null +}, { + name: 'Public', + value: 'public' +}, { + name: 'Members-only', + value: 'members' +}, { + name: 'Paid members-only', + value: 'paid' +}]; + const ORDERS = [{ name: 'Newest', value: null @@ -38,27 +52,29 @@ export default Controller.extend({ store: service(), // default values for these are set in `init` and defined in `helpers/reset-query-params` - queryParams: ['type', 'author', 'tag', 'order'], + queryParams: ['type', 'access', 'author', 'tag', 'order'], _hasLoadedTags: false, _hasLoadedAuthors: false, availableTypes: null, + availableVisibilities: null, availableOrders: null, init() { this._super(...arguments); this.availableTypes = TYPES; this.availableOrders = ORDERS; + this.availableVisibilities = VISIBILITIES; this.setProperties(DEFAULT_QUERY_PARAMS.posts); }, postsInfinityModel: alias('model'), showingAll: computed('type', 'author', 'tag', function () { - let {type, author, tag} = this.getProperties(['type', 'author', 'tag']); + let {type, author, tag, visibility} = this.getProperties(['type', 'visibility', 'author', 'tag']); - return !type && !author && !tag; + return !type && !visibility && !author && !tag; }), selectedType: computed('type', function () { @@ -66,6 +82,11 @@ export default Controller.extend({ return types.findBy('value', this.get('type')) || {value: '!unknown'}; }), + selectedVisibility: computed('visibility', function () { + let visibilities = this.get('availableVisibilities'); + return visibilities.findBy('value', this.get('visibility')) || {value: '!unknown'}; + }), + selectedOrder: computed('order', function () { let orders = this.get('availableOrders'); return orders.findBy('value', this.get('order')) || {value: '!unknown'}; @@ -117,6 +138,10 @@ export default Controller.extend({ this.set('type', get(type, 'value')); }, + changeVisibility(visibility) { + this.set('visibility', get(visibility, 'value')); + }, + changeAuthor(author) { this.set('author', get(author, 'slug')); }, diff --git a/ghost/admin/app/helpers/reset-query-params.js b/ghost/admin/app/helpers/reset-query-params.js index ed7d977e99..903c2d735d 100644 --- a/ghost/admin/app/helpers/reset-query-params.js +++ b/ghost/admin/app/helpers/reset-query-params.js @@ -3,12 +3,14 @@ import {helper} from '@ember/component/helper'; export const DEFAULT_QUERY_PARAMS = { posts: { type: null, + visibility: null, author: null, tag: null, order: null }, pages: { type: null, + visibility: null, author: null, tag: null, order: null diff --git a/ghost/admin/app/routes/posts.js b/ghost/admin/app/routes/posts.js index 6bf36641ff..d30d86fa00 100644 --- a/ghost/admin/app/routes/posts.js +++ b/ghost/admin/app/routes/posts.js @@ -9,6 +9,8 @@ export default AuthenticatedRoute.extend({ queryParams: { type: {refreshModel: true}, + visibility: {refreshModel: true}, + access: {refreshModel: true}, author: {refreshModel: true}, tag: {refreshModel: true}, order: {refreshModel: true} @@ -38,7 +40,7 @@ export default AuthenticatedRoute.extend({ model(params) { return this.session.user.then((user) => { let queryParams = {}; - let filterParams = {tag: params.tag}; + let filterParams = {tag: params.tag, visibility: params.visibility}; let paginationParams = { perPageParam: 'limit', totalPagesParam: 'meta.pagination.pages' diff --git a/ghost/admin/app/templates/pages-loading.hbs b/ghost/admin/app/templates/pages-loading.hbs index 7fb330780b..2dc1546cfc 100644 --- a/ghost/admin/app/templates/pages-loading.hbs +++ b/ghost/admin/app/templates/pages-loading.hbs @@ -7,6 +7,9 @@ @selectedType={{this.selectedType}} @availableTypes={{this.availableTypes}} @onTypeChange={{action (mut k)}} + @selectedVisibility={{this.selectedVisibility}} + @availableVisibilities={{this.availableVisibilities}} + @onVisibilityChange={{action (mut k)}} @selectedAuthor={{this.selectedAuthor}} @availableAuthors={{this.availableAuthors}} @onAuthorChange={{action (mut k)}} diff --git a/ghost/admin/app/templates/pages.hbs b/ghost/admin/app/templates/pages.hbs index 825914d33f..84ef649414 100644 --- a/ghost/admin/app/templates/pages.hbs +++ b/ghost/admin/app/templates/pages.hbs @@ -8,6 +8,9 @@ @selectedType={{this.selectedType}} @availableTypes={{this.availableTypes}} @onTypeChange={{action "changeType"}} + @selectedVisibility={{this.selectedVisibility}} + @availableVisibilities={{this.availableVisibilities}} + @onVisibilityChange={{action "changeVisibility"}} @selectedAuthor={{this.selectedAuthor}} @availableAuthors={{this.availableAuthors}} @onAuthorChange={{action "changeAuthor"}} diff --git a/ghost/admin/app/templates/posts-loading.hbs b/ghost/admin/app/templates/posts-loading.hbs index 4eb2e3a0dc..3c6664b7d3 100644 --- a/ghost/admin/app/templates/posts-loading.hbs +++ b/ghost/admin/app/templates/posts-loading.hbs @@ -7,6 +7,9 @@ @selectedType={{this.selectedType}} @availableTypes={{this.availableTypes}} @onTypeChange={{action (mut k)}} + @selectedVisibility={{this.selectedVisibility}} + @availableVisibilities={{this.availableVisibilities}} + @onVisibilityChange={{action (mut k)}} @selectedAuthor={{this.selectedAuthor}} @availableAuthors={{this.availableAuthors}} @onAuthorChange={{action (mut k)}} diff --git a/ghost/admin/app/templates/posts.hbs b/ghost/admin/app/templates/posts.hbs index cf634d8c06..fd17a7ac77 100644 --- a/ghost/admin/app/templates/posts.hbs +++ b/ghost/admin/app/templates/posts.hbs @@ -8,6 +8,9 @@ @selectedType={{this.selectedType}} @availableTypes={{this.availableTypes}} @onTypeChange={{action "changeType"}} + @selectedVisibility={{this.selectedVisibility}} + @availableVisibilities={{this.availableVisibilities}} + @onVisibilityChange={{action "changeVisibility"}} @selectedAuthor={{this.selectedAuthor}} @availableAuthors={{this.availableAuthors}} @onAuthorChange={{action "changeAuthor"}} diff --git a/ghost/admin/tests/acceptance/content-test.js b/ghost/admin/tests/acceptance/content-test.js index ce4d299e70..a7936e55c0 100644 --- a/ghost/admin/tests/acceptance/content-test.js +++ b/ghost/admin/tests/acceptance/content-test.js @@ -1,6 +1,6 @@ import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support'; import {beforeEach, describe, it} from 'mocha'; -import {click, currentURL, fillIn, find, findAll, visit} from '@ember/test-helpers'; +import {click, currentURL, fillIn, find, findAll, settled, visit} from '@ember/test-helpers'; import {clickTrigger, selectChoose} from 'ember-power-select/test-support/helpers'; import {expect} from 'chai'; import {setupApplicationTest} from 'ember-mocha'; @@ -86,8 +86,22 @@ describe('Acceptance: Content', function () { // API request is correct [lastRequest] = this.server.pretender.handledRequests.slice(-1); - expect(lastRequest.queryParams.filter, '"editor" request status filter').to.have.string('status:[draft,scheduled,published]'); - expect(lastRequest.queryParams.filter, '"editor" request filter param').to.have.string(`authors:${editor.slug}`); + expect(lastRequest.queryParams.filter, '"editor" request status filter') + .to.have.string('status:[draft,scheduled,published]'); + expect(lastRequest.queryParams.filter, '"editor" request filter param') + .to.have.string(`authors:${editor.slug}`); + + // Post status is only visible when members is enabled + expect(find('[data-test-visibility-select]'), 'access dropdown before members enabled').to.not.exist; + let featureService = this.owner.lookup('service:feature'); + featureService.set('members', true); + await settled(); + expect(find('[data-test-visibility-select]'), 'access dropdown after members enabled').to.exist; + + await selectChoose('[data-test-visibility-select]', 'Paid members-only'); + [lastRequest] = this.server.pretender.handledRequests.slice(-1); + expect(lastRequest.queryParams.filter, '"visibility" request filter param') + .to.have.string('visibility:paid+status:[draft,scheduled,published]'); // Displays editor post // TODO: implement "filter" param support and fix mirage post->author association