mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Fixed error in setting page access to tiers
closes https://github.com/TryGhost/Ghost/issues/13704 closes https://github.com/TryGhost/Team/issues/1186 - updates page serializer to handle new `visibility_filter` property for filtering access on specific tier - this change was already added for `posts` but was missed on `pages`, so parsing filter on `visibility` filter was failing
This commit is contained in:
parent
b79870d48c
commit
1a9705b824
2 changed files with 40 additions and 0 deletions
|
@ -102,6 +102,13 @@ const forceStatusFilter = (frame) => {
|
|||
}
|
||||
};
|
||||
|
||||
const transformPageVisibilityFilters = (frame) => {
|
||||
if (frame.data.pages[0].visibility === 'filter' && frame.data.pages[0].visibility_filter) {
|
||||
frame.data.pages[0].visibility = frame.data.pages[0].visibility_filter;
|
||||
}
|
||||
delete frame.data.pages[0].visibility_filter;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
browse(apiConfig, frame) {
|
||||
debug('browse');
|
||||
|
@ -180,6 +187,7 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
transformPageVisibilityFilters(frame);
|
||||
handlePostsMeta(frame);
|
||||
defaultFormat(frame);
|
||||
defaultRelations(frame);
|
||||
|
|
|
@ -105,6 +105,38 @@ describe('Pages API', function () {
|
|||
model.get('type').should.eql('page');
|
||||
});
|
||||
|
||||
it('Can update a page with restricted access to specific tier', async function () {
|
||||
const page = {
|
||||
title: 'updated page',
|
||||
page: false
|
||||
};
|
||||
|
||||
const res = await request
|
||||
.get(localUtils.API.getApiQuery(`pages/${testUtils.DataGenerator.Content.posts[5].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200);
|
||||
|
||||
page.updated_at = res.body.pages[0].updated_at;
|
||||
page.visibility = 'filter';
|
||||
page.visibility_filter = 'product:default-product';
|
||||
|
||||
const res2 = await request.put(localUtils.API.getApiQuery('pages/' + testUtils.DataGenerator.Content.posts[5].id))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({pages: [page]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
|
||||
should.exist(res2.headers['x-cache-invalidate']);
|
||||
localUtils.API.checkResponse(res2.body.pages[0], 'page', ['visibility_filter']);
|
||||
|
||||
const model = await models.Post.findOne({
|
||||
id: res2.body.pages[0].id
|
||||
}, testUtils.context.internal);
|
||||
|
||||
model.get('type').should.eql('page');
|
||||
});
|
||||
|
||||
it('Cannot get page via posts endpoint', async function () {
|
||||
await request.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[5].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
|
|
Loading…
Add table
Reference in a new issue