Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRO-6591: parked fields overrides #4732

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

* Uploaded SVGs now permit `<use>` tags granted their `xlink:href` property is a local reference and begins with the `#` character. This improves SVG support while mitgating XSS vulnerabilities.
* Default properties of object fields present in a widget now populate correctly even if never focused in the editor.
* Ensure parked fields are not modified for parked pages when not configured in `_defaults`.

## 4.7.0 (2024-09-05)

Expand Down
15 changes: 15 additions & 0 deletions modules/@apostrophecms/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,21 @@ module.exports = {
},
handlers(self) {
return {
'@apostrophecms/page-type:beforeSave': {
handleParkedFieldsOverride(req, doc) {
if (!doc.parkedId) {
return;
}
const parked = self.parked.find(p => p.parkedId === doc.parkedId);
myovchev marked this conversation as resolved.
Show resolved Hide resolved
if (!parked) {
return;
}
const parkedFields = Object.keys(parked).filter(field => field !== '_defaults');
for (const parkedField of parkedFields) {
doc[parkedField] = parked[parkedField];
}
}
},
beforeSend: {
async addLevelAttributeToBody(req) {
// Add level as a data attribute on the body tag
Expand Down
2 changes: 1 addition & 1 deletion test/content-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('content-i18n', function() {
peoplePageFrCA = await apos.page.find(frCAReq, {
parkedId: 'people'
}).toObject();
assert(peoplePageFrCA.title === 'Altered');
assert(peoplePageFrCA.title === 'People');
});

let home;
Expand Down
6 changes: 4 additions & 2 deletions test/events2.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ describe('Promisified Events: @apostrophecms/doc-type:beforeInsert', function()
{
type: 'default-page',
findMeAgain: true,
title: 'Test',
slug: '/test',
visibility: 'public',
parkedId: 'test'
parkedId: 'test',
_defaults: {
title: 'Test'
}
}
]
}
Expand Down
75 changes: 75 additions & 0 deletions test/parked-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,81 @@ describe('Parked Pages', function() {
});
await validate(apos6, [ '/', '/archive', '/default1', '/default2', '/default3', '/default3/child1' ]);
});

it('field override on save is possible only when it is configured as default', async function () {
this.timeout(20000);
await t.destroy(apos6);
apos6 = await t.create({
root: module,
modules: {
'@apostrophecms/page': {
options: {
park: [
...park2,
{
parkedId: 'default3',
type: 'default-page',
title: 'Default 3',
slug: '/default3'
},
{
parkedId: 'default4',
type: 'default-page',
title: 'Default 4',
_defaults: {
slug: '/default4'
}
}
]
}
},
'default-page': {}
}
});
const manager = apos6.doc.getManager('default-page');
const req = apos.task.getReq({ mode: 'draft' });

// slug override not possible, slug is NOT configured in defaults
{
const page = await manager.find(req, {
parkedId: 'default3',
aposMode: 'draft'
}).toObject();
assert.strictEqual(page.slug, '/default3');
assert.deepStrictEqual(page.parked, [ 'parkedId', 'type', 'title', 'slug' ]);

page.slug = '/default3-overridden';
await manager.update(req, page);
const updated = await manager.find(req, {
parkedId: 'default3',
aposMode: 'draft'
}).toObject();

assert.strictEqual(updated.slug, '/default3');
}

// slug override is possible because slug is configured in defaults
{
const page = await manager.find(req, {
parkedId: 'default4',
aposMode: 'draft'
}).toObject();
assert.strictEqual(page.slug, '/default4');
assert.deepStrictEqual(page.parked, [ 'parkedId', 'type', 'title' ]);

page.slug = '/default4-overridden';
await manager.update(req, page);
const updated = await manager.find(req, {
parkedId: 'default4',
aposMode: 'draft'
}).toObject();

assert.strictEqual(updated.slug, '/default4-overridden');
}

await t.destroy(apos6);
apos6 = null;
});
});

async function validate(apos, expected) {
Expand Down
Loading