Skip to content

Commit

Permalink
Improve the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
myovchev committed Sep 20, 2024
1 parent 58bc74d commit b0cfed2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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 `slug` is not modified for parked pages when not configured in `_defaults`.
* Ensure parked fields are not modified for parked pages when not configured in `_defaults`.

## 4.7.0 (2024-09-05)

Expand Down
7 changes: 4 additions & 3 deletions modules/@apostrophecms/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,16 +847,17 @@ module.exports = {
handlers(self) {
return {
'@apostrophecms/page-type:beforeSave': {
handleParkedSlugOverride(req, doc) {
handleParkedFieldsOverride(req, doc) {
if (!doc.parkedId) {
return;
}
const parked = self.parked.find(p => p.parkedId === doc.parkedId);
if (!parked) {
return;
}
if (parked.slug && !parked._defaults?.slug) {
doc.slug = parked.slug;
const parkedFields = Object.keys(parked).filter(field => field !== '_defaults');
for (const parkedField of parkedFields) {
doc[parkedField] = parked[parkedField];
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/parked-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('Parked Pages', function() {
await validate(apos6, [ '/', '/archive', '/default1', '/default2', '/default3', '/default3/child1' ]);
});

it('slug override on save is possible only when slug is configured as default', async function () {
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({
Expand Down

0 comments on commit b0cfed2

Please sign in to comment.