Skip to content

Web 4461 save and publish button - #32

Open
boulch wants to merge 2 commits into
mainfrom
WEB-4461_save_and_publish_button
Open

Web 4461 save and publish button#32
boulch wants to merge 2 commits into
mainfrom
WEB-4461_save_and_publish_button

Conversation

@boulch

@boulch boulch commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added an optional “Save and publish” button to content creation and editing forms.
    • The button can be enabled per content type and appears only when publishing is available.
    • Content is saved first, then published automatically when the submission is valid.
    • Existing save and cancel actions remain available.
  • Bug Fixes

    • Prevented publishing when form validation fails.
    • Added handling for unavailable or unsuccessful publishing transitions.

boulch and others added 2 commits August 7, 2026 14:37
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Version 1.2.58 adds an opt-in Save and publish action to Dexterity add and edit forms. The action saves valid content, detects an allowed transition to published, and applies it. Tests cover visibility, ordering, validation, permissions, and workflow errors.

Changes

Save and publish

Layer / File(s) Summary
Publishing behavior and workflow helpers
src/imio/smartweb/common/behaviors/publish.py, src/imio/smartweb/common/behaviors/configure.zcml, src/imio/smartweb/common/profiles/testing/types/Document.xml, src/imio/smartweb/common/tests/test_publish.py
The new ISaveAndPublish behavior and publishing helpers detect eligible types and allowed transitions. Workflow failures produce warning messages. The test Document type enables the behavior.
Add and edit form actions
src/imio/smartweb/common/browser/forms.py, src/imio/smartweb/common/tests/test_forms.py, CHANGES.rst, docs/superpowers/specs/2026-08-07-save-and-publish-button-design.md
Add and edit forms preserve inherited actions, place Save and publish with the existing buttons, save valid submissions, and publish the stored object. Invalid submissions do not publish.
Estimated code review effort: 3 (Moderate) ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant CustomAddForm
  participant publish_transition
  participant publish
  participant Workflow
  Browser->>CustomAddForm: Submit Save and publish
  CustomAddForm->>CustomAddForm: Create and store object
  CustomAddForm->>publish_transition: Find allowed published transition
  publish_transition-->>CustomAddForm: Return transition
  CustomAddForm->>publish: Publish stored object
  publish->>Workflow: Apply transition
  Workflow-->>Browser: Return workflow result or warning
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a save-and-publish button.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch WEB-4461_save_and_publish_button

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/superpowers/specs/2026-08-07-save-and-publish-button-design.md`:
- Around line 42-43: Update the documented publish API and edit-form example to
include the required request argument used by publish in the implementation.
Ensure every shown invocation passes request alongside obj and transition so
copied examples do not raise TypeError.
- Around line 137-143: Update the documented minimum-coverage test module
reference from tests/test_save_and_publish.py to
src/imio/smartweb/common/tests/test_publish.py, preserving the listed test
scenarios.

In `@src/imio/smartweb/common/behaviors/configure.zcml`:
- Around line 22-27: Update the behavior metadata in the plone:behavior
declaration for imio.smartweb.save_and_publish to use the message factory from
imio.smartweb.locales for both title and description instead of literal strings,
preserving their current meanings and translation keys.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17ada98e-8202-45a3-965e-18cf04f832fd

📥 Commits

Reviewing files that changed from the base of the PR and between b325053 and e3ca7a2.

📒 Files selected for processing (8)
  • CHANGES.rst
  • docs/superpowers/specs/2026-08-07-save-and-publish-button-design.md
  • src/imio/smartweb/common/behaviors/configure.zcml
  • src/imio/smartweb/common/behaviors/publish.py
  • src/imio/smartweb/common/browser/forms.py
  • src/imio/smartweb/common/profiles/testing/types/Document.xml
  • src/imio/smartweb/common/tests/test_forms.py
  • src/imio/smartweb/common/tests/test_publish.py

Comment on lines +42 to +43
def publish(obj, transition):
"""Apply transition on obj, warning the user instead of failing."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the documented publish API.

publish requires request in src/imio/smartweb/common/behaviors/publish.py so it can add a warning status message. The documented signature and edit-form example omit this argument. Copied code will raise TypeError.

Proposed documentation update
-def publish(obj, transition):
+def publish(obj, transition, request):
     """Apply transition on obj, warning the user instead of failing."""
...
-publish(self.context, self.publish_transition)
+publish(self.context, self.publish_transition, self.request)
...
-`publish(obj, transition)` est la troisième fonction
+`publish(obj, transition, request)` est la troisième fonction

Also applies to: 93-103

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/superpowers/specs/2026-08-07-save-and-publish-button-design.md` around
lines 42 - 43, Update the documented publish API and edit-form example to
include the required request argument used by publish in the implementation.
Ensure every shown invocation passes request alongside obj and transition so
copied examples do not raise TypeError.

Comment on lines +137 to +143
`tests/test_save_and_publish.py`, couverture minimale 90 % :

- bouton présent sur un `Document` privé avec le behavior actif ;
- bouton absent sur un type sans le behavior (`Folder`) ;
- bouton absent sur un contenu déjà publié ;
- le bouton publie effectivement, depuis le formulaire d'édition ;
- le bouton crée puis publie, depuis le formulaire d'ajout.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the documented test module path.

The implemented test module is src/imio/smartweb/common/tests/test_publish.py. Replace tests/test_save_and_publish.py so the specification points to the test file in this PR.

🧰 Tools
🪛 LanguageTool

[typographical] ~140-~140: Caractère d’apostrophe incorrect.
Context: ...ton absent sur un type sans le behavior (Folder) ; - bouton absent sur un conten...

(APOS_INCORRECT)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/superpowers/specs/2026-08-07-save-and-publish-button-design.md` around
lines 137 - 143, Update the documented minimum-coverage test module reference
from tests/test_save_and_publish.py to
src/imio/smartweb/common/tests/test_publish.py, preserving the listed test
scenarios.

Comment on lines +22 to +27
<plone:behavior
name="imio.smartweb.save_and_publish"
title="Save and publish"
description="Add a 'Save and publish' button on add and edit forms."
provides=".publish.ISaveAndPublish"
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use message-factory-backed behavior metadata.

Lines 24-25 add user-facing behavior labels as literal strings. Use messages from imio.smartweb.locales for the title and description so the behavior picker can translate them.

As per coding guidelines, use “the message factory from imio.smartweb.locales for all user-facing strings in Plone views and components.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/imio/smartweb/common/behaviors/configure.zcml` around lines 22 - 27,
Update the behavior metadata in the plone:behavior declaration for
imio.smartweb.save_and_publish to use the message factory from
imio.smartweb.locales for both title and description instead of literal strings,
preserving their current meanings and translation keys.

Source: Coding guidelines

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.

1 participant