Skip to content

Added option to define signers from templates#124

Open
chris-adam wants to merge 1 commit into
masterfrom
PARAF-426/template_signers
Open

Added option to define signers from templates#124
chris-adam wants to merge 1 commit into
masterfrom
PARAF-426/template_signers

Conversation

@chris-adam
Copy link
Copy Markdown
Contributor

@chris-adam chris-adam commented May 18, 2026

Summary by CodeRabbit

  • New Features

    • Templates can define signers that are applied to outgoing mail during document generation
    • Template edit/view pages improved to surface configurable signing options
  • Configuration

    • New outgoing-mail setting to enable/disable template-based signer assignment
    • Signing form visibility adapts when the feature is disabled
  • Behavior / Validation

    • Signing validations now apply specifically to outgoing mail (templates exempted)
  • Tests

    • Added tests covering template signer copying and registry toggling behavior

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

This PR introduces the ability to define outgoing-mail signers from POD template configuration instead of using signer rules. It adds a registry flag omail_use_template_signers, implements template signer copying during document generation, narrows validations to allow templates to skip outgoing-mail-specific checks, and provides form/view overrides to control signing fieldset visibility.

Changes

Template Signer Configuration

Layer / File(s) Summary
Registry configuration and template signing setup
imio/dms/mail/browser/settings.py, imio/dms/mail/profiles/default/types/ConfigurablePODTemplate.xml
Adds boolean omail_use_template_signers registry field to control whether signer rules are bypassed in favor of template signers; enables ISigningBehavior on ConfigurablePODTemplate type.
Validation scoping to outgoing mails
imio/dms/mail/content/behaviors.py, imio/dms/mail/tests/test_behaviors.py
Restricts approval-state edit checks and file-format validation to IImioDmsOutgoingMail contexts only, allowing templates and other contexts to bypass these constraints while retaining generic signing validations.
Template signer copy implementation
imio/dms/mail/browser/documentgenerator.py, imio/dms/mail/tests/test_documentgenerator.py
Core feature: _copy_template_signers() helper deep-copies signing configuration from template into outgoing mail during document generation, sets seal/esign from template, detects and warns on signer conflicts, and emits modification events.
Template view and form overrides
imio/dms/mail/browser/documentgenerator.py, imio/dms/mail/browser/configure.zcml, imio/dms/mail/browser/overrides.zcml
Adds browser view and form classes (edit, view, documentviewer, add) for ConfigurablePODTemplate that conditionally hide the signing fieldset when the feature flag is disabled; registers views in ZCML.
Subscriber signer auto-assignment update
imio/dms/mail/subscribers.py, imio/dms/mail/tests/test_subscribers.py
Gates signer auto-assignment logic on the registry flag, preserving existing signers and preventing rule-based initialization when template-based signers are enabled.
Changelog entry
CHANGES.rst
Documents new option to define signers from templates in release notes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • IMIO/imio.dms.mail#97: Implements the @@signing_actions_panel view that is now rendered by template pages added in this PR.
  • IMIO/imio.dms.mail#112: Modifies signer computation in the same subscribers.py logic path via omail_signer_substitutes, creating related but distinct signer-resolution strategies.

Suggested reviewers

  • sgeulette

Poem

🐰 I copied signers from a template neat and small,

No rule-ruled chaos, just a tidy call.
The form may hide, the view may gleam,
Templates whisper signers into the mail stream.
Hooray — a rabbit's hop for code so small!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main feature: adding an option to define signers from templates.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 PARAF-426/template_signers

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

@chris-adam chris-adam force-pushed the PARAF-426/template_signers branch from ac0b199 to 8573e81 Compare May 18, 2026 10:24
@chris-adam chris-adam marked this pull request as ready for review May 18, 2026 10:24
</property>
<property name="behaviors" purge="False">
<element value="imio.dms.mail.content.behaviors.IDefaultContentCategoryBehavior"/>
<element value="imio.dms.mail.content.behaviors.ISigningBehavior"/>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Est-ce qu'une migration est en cours de préparation ou il faut en créer une nouvelle ?

@chris-adam chris-adam force-pushed the PARAF-426/template_signers branch from 8573e81 to 4491d66 Compare May 18, 2026 12:41
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@imio/dms/mail/browser/overrides.zcml`:
- Around line 168-177: The browser:page registration for class
imio.dms.mail.browser.documentgenerator.DmsViewConfigurablePodTemplate currently
uses layer=".interfaces.ILayer" which resolves to the wrong package; update the
layer attribute to the fully qualified interface
imio.dms.mail.interfaces.IImioDmsMailLayer to match the other registrations and
keep layer usage consistent across the overrides (adjust the layer="..." value
in that browser:page element referencing DmsViewConfigurablePodTemplate and
template="templates/documentviewerdx.pt").
🪄 Autofix (Beta)

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: abc8f84d-caad-4074-ba09-a09c192cecaf

📥 Commits

Reviewing files that changed from the base of the PR and between 8573e81 and 4491d66.

📒 Files selected for processing (11)
  • CHANGES.rst
  • imio/dms/mail/browser/configure.zcml
  • imio/dms/mail/browser/documentgenerator.py
  • imio/dms/mail/browser/overrides.zcml
  • imio/dms/mail/browser/settings.py
  • imio/dms/mail/content/behaviors.py
  • imio/dms/mail/profiles/default/types/ConfigurablePODTemplate.xml
  • imio/dms/mail/subscribers.py
  • imio/dms/mail/tests/test_behaviors.py
  • imio/dms/mail/tests/test_documentgenerator.py
  • imio/dms/mail/tests/test_subscribers.py
✅ Files skipped from review due to trivial changes (1)
  • CHANGES.rst
🚧 Files skipped from review as they are similar to previous changes (8)
  • imio/dms/mail/profiles/default/types/ConfigurablePODTemplate.xml
  • imio/dms/mail/content/behaviors.py
  • imio/dms/mail/browser/configure.zcml
  • imio/dms/mail/subscribers.py
  • imio/dms/mail/tests/test_subscribers.py
  • imio/dms/mail/tests/test_documentgenerator.py
  • imio/dms/mail/browser/settings.py
  • imio/dms/mail/tests/test_behaviors.py

Comment on lines +168 to +177
<configure package="collective.documentviewer">
<browser:page
name="documentviewer"
for="collective.documentgenerator.content.pod_template.IConfigurablePODTemplate"
class="imio.dms.mail.browser.documentgenerator.DmsViewConfigurablePodTemplate"
template="templates/documentviewerdx.pt"
permission="zope2.View"
layer=".interfaces.ILayer"
/>
</configure>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 18, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how other overrides in this package handle layer registration
rg -n "layer=" imio/dms/mail/browser/overrides.zcml | head -20

# Check if there's a pattern for package-scoped overrides
rg -n "configure package=" imio/dms/mail/browser/overrides.zcml -A5

Repository: IMIO/imio.dms.mail

Length of output: 3435


Standardize layer specification to imio.dms.mail for consistency.

Line 175 uses layer=".interfaces.ILayer" (resolving to collective.documentviewer.interfaces.ILayer), while lines 183 and 224 both use the fully qualified imio.dms.mail.interfaces.IImioDmsMailLayer. Since all three registrations are in the same overrides file and serve as imio.dms.mail customizations, use imio.dms.mail.interfaces.IImioDmsMailLayer at line 175 for consistency.

🤖 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 `@imio/dms/mail/browser/overrides.zcml` around lines 168 - 177, The
browser:page registration for class
imio.dms.mail.browser.documentgenerator.DmsViewConfigurablePodTemplate currently
uses layer=".interfaces.ILayer" which resolves to the wrong package; update the
layer attribute to the fully qualified interface
imio.dms.mail.interfaces.IImioDmsMailLayer to match the other registrations and
keep layer usage consistent across the overrides (adjust the layer="..." value
in that browser:page element referencing DmsViewConfigurablePodTemplate and
template="templates/documentviewerdx.pt").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The ZCML registration for DmsViewConfigurablePodTemplate in browser/configure.zcml used layer="imio.dms.mail.interfaces.IImioDmsMailLayer", but the collective.documentgenerator registration it was trying to override used layer="collective.documentviewer.interfaces.ILayer". These are different discriminators, so Zope treated them as two separate registrations rather than an override. At runtime, the DG registration won the adapter lookup.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@chris-adam, that's a great clarification — you're absolutely right, and my suggestion was incorrect.

In Zope's adapter/page registry, all discriminators (including layer) form the lookup key. To override an existing registration, the overriding registration must use the same discriminators as the original. If collective.documentgenerator registers the documentviewer page with layer="collective.documentviewer.interfaces.ILayer", then matching that exact layer is the only way to replace it. Using imio.dms.mail.interfaces.IImioDmsMailLayer would register a parallel entry under a different discriminator set, leaving the original DG registration still active and winning the lookup — which is exactly the bug you observed.

The .interfaces.ILayer inside <configure package="collective.documentviewer"> resolving to collective.documentviewer.interfaces.ILayer is therefore intentional and correct. I'll note this for future reviews.


✏️ Learnings added
Learnt from: chris-adam
Repo: IMIO/imio.dms.mail PR: 124
File: imio/dms/mail/browser/overrides.zcml:168-177
Timestamp: 2026-05-18T12:49:17.654Z
Learning: In Zope ZCML, overriding a `browser:page` registration requires matching ALL discriminators (including `layer`) of the original registration. In `imio/dms/mail/browser/overrides.zcml`, the `DmsViewConfigurablePodTemplate` page registration for `IConfigurablePODTemplate` must use `layer=".interfaces.ILayer"` (resolving to `collective.documentviewer.interfaces.ILayer`) to properly override the existing `collective.documentgenerator`/`collective.documentviewer` registration. Using `imio.dms.mail.interfaces.IImioDmsMailLayer` instead creates a separate registration and leaves the original DG registration active, so the override never takes effect at runtime.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@chris-adam chris-adam requested a review from sgeulette May 18, 2026 12:49
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