Skip to content

Fix blocks without image_scales and CLI export of protected fields - #111

Merged
ericof merged 3 commits into
mainfrom
issues-109-110
Sep 25, 2026
Merged

ericof merged 3 commits into
mainfrom
issues-109-110

Conversation

@ericof

@ericof ericof commented Sep 23, 2026

Copy link
Copy Markdown
Member

Summary

Two bug fixes found while exporting data for the new plone.org.br.

#109: blocks without image_scales

_fix_image_paths in plone.exportimport.utils.content.blocks assumed every image entry in a grid block had image_scales. Export and import broke when the key was missing or null, when a field had an empty scales list, or when the image data had no scales key. These entries are now left unchanged.

#110: CLI export silently dropping protected fields

plone-exporter wrapped the export in api.env.adopt_roles(["Manager"]). Under adopt_roles, a permission check succeeds only if the permission is granted to one of the adopted roles, and the user's own check is bypassed. The command line tools already run as the unrestricted system user (set up in get_app), so this override could only narrow permissions.

Fields whose read permission is granted only to other roles were silently left out of the export. This happened with the header settings behavior of sc.voltolighttheme, whose view permission is granted to Anonymous and Authenticated on the Plone Site root.

Changes:

  • exporter_cli and importer_cli now run inside hooks.site(site), without adopt_roles.
  • get_site is annotated as returning PloneSite, since it exits when the site is not found.

Tests

  • New unit tests for _fix_image_paths and parse_blocks.
  • New plone.exportimport.testing:testing profile, loaded by the test layer:
    • a DummyContent type with fields protected by custom read and write permissions;
    • the same fields as a plone.exportimport.testing.dummy_settings behavior, enabled on the Plone Site;
    • a rolemap that mirrors sc.voltolighttheme (view: Anonymous/Authenticated; edit: Manager/Site Administrator).
  • New tests/cli tests that run the real exporter_cli and importer_cli, patching only the Zope startup, on the functional layer (the importer commits). The exporter tests fail without the fix.

Closes #109
Closes #110

Grid block images exported without image_scales (missing or null),
with an empty scales list, or without a scales key no longer break
export and import.

Closes #109
Under adopt_roles(["Manager"]), a permission check only succeeds when
the permission is granted to Manager, bypassing the unrestricted system
user set up by get_app. Fields whose read permission is granted only to
other roles (e.g. Anonymous and Authenticated, as for the header
settings behavior of sc.voltolighttheme on the Plone Site root) were
silently dropped from exports.

Both exporter_cli and importer_cli now run inside hooks.site(site)
without overriding roles. get_site is annotated as returning PloneSite,
since it exits when the site is not found.

Tests:
- New testing profile with a DummyContent type and a dummy_settings
  behavior on the Plone Site, with fields protected by custom read and
  write permissions.
- CLI tests for exporter and importer, running on the functional layer.

Closes #110
@ericof
ericof requested a review from gforcada September 23, 2026 19:43
@mister-roboto

Copy link
Copy Markdown

@ericof thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

pytest-plone 1.1.0 keeps test layers set up for the whole session.
Importers commit the transaction by default (intermediate_commits),
and the portal_multilingual fixtures committed through
transaction.manager, so imported content, users and groups leaked
into later integration tests. Previously each layer was rebuilt
between tests, which hid the leak.

- Add an autouse fixture disabling importer intermediate commits.
- Stop committing in the portal_multilingual fixtures.
- Declare plone.autoform, plone.behavior, plone.supermodel and
  Products.GenericSetup, imported by the plone.exportimport.testing
  package.
- Drop the license classifier from setup.py.
@ericof

ericof commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

@jenkins-plone-org please run jobs

@ericof

ericof commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

@gforcada It seems I also fixed the pytest issues

@ericof

ericof commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@gforcada Could you approve it? :-)

@gforcada gforcada left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 😄 there are a few parts, specially on tests that I skimmed over them, but otherwise looks fine 👍🏾

@ericof
ericof merged commit 8ff79d5 into main Sep 25, 2026
15 of 16 checks passed
@ericof
ericof deleted the issues-109-110 branch September 25, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export fails to serialize fields with write permission Export and import breaks if block does not have image_scales

3 participants