Skip to content

URB-3480: Add content rule events for successful and broken NOTICe handling#533

Open
daggelpop wants to merge 3 commits into
2.9.xfrom
URB-3480_notice_content_rules
Open

URB-3480: Add content rule events for successful and broken NOTICe handling#533
daggelpop wants to merge 3 commits into
2.9.xfrom
URB-3480_notice_content_rules

Conversation

@daggelpop

@daggelpop daggelpop commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Emits notifications when NOTICe imports succeed or fail and hooks those events into content rules.
    • Makes notice ID and notice type available for use in rule substitutions.
  • Documentation

    • Added French translations for NOTICe import notifications and related rule text.

@daggelpop daggelpop requested a review from mpeeters March 3, 2026 08:35
@coderabbitai

coderabbitai Bot commented Mar 3, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds Plone content-rule events and substitutions for NOTICe import lifecycle, emits NoticeImportSucceededEvent and NoticeImportFailedEvent from the notice import cron flow, registers ZCML bindings for subscribers and substitutions, and adds French translations and a feature note.

Changes

Cohort / File(s) Summary
Feature Declaration
news/URB-3480.feature
Added feature file documenting new content-rule events for successful and failed NOTICe handling.
Cron: Notice import
src/Products/urban/browser/cron/notice.py
Added _notify_successful_import() and _notify_import_error(); import event classes and IContextWrapper; emit success/failure events across import, retry, fetch, and document-creation flows.
Content rules ZCML
src/Products/urban/contentrules/configure.zcml
Registered new event interfaces and subscriber for notice import events; added two plone.stringinterp substitution adapters notice_id and notice_type.
Content rules implementation
src/Products/urban/contentrules/notice.py
New module: INoticeImportEvent, INoticeImportSucceededEvent, INoticeImportFailedEvent, event classes, notice_import dispatcher, and NoticeIdSubstitution / NoticeTypeSubstitution adapters exposing notice metadata.
Translations
src/Products/urban/locales/fr/LC_MESSAGES/urban.po
Added French translations for NOTICe import success/failure messages, NOTICe labels and substitutions; minor message line adjustments.

Sequence Diagram

sequenceDiagram
    participant Cron as Notice Import Process
    participant Wrapper as IContextWrapper
    participant Emitter as Event Dispatcher
    participant RuleEngine as Plone Content Rules
    participant Action as Rule Action Handler

    Cron->>Wrapper: Wrap notice details (notice_id, notice_type, context)
    Wrapper->>Emitter: Emit NoticeImportSucceededEvent / NoticeImportFailedEvent
    Emitter->>RuleEngine: Dispatch event to rule engine
    RuleEngine->>RuleEngine: Evaluate conditions (using notice_id / notice_type substitutions)
    RuleEngine->>Action: Execute matching actions (email, notifications, etc.)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I wrapped a notice snug and neat,
I hopped and sent an event so fleet,
Success or fail, the rules take part,
Tiny actions, big heart,
Hooray — automation's treat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding content rule events for NOTICe import success and failure handling.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch URB-3480_notice_content_rules

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Products/urban/browser/cron/notice.py`:
- Around line 164-171: The helper _notify_import_error is never called so
NoticeImportFailedEvent is never emitted; locate the import workflow (e.g., the
function/method that performs the notice import—search for import_notice,
process_notice_import, or similar in the same module/class) and call
_notify_import_error(notice_id=..., notice_type=...) inside the exception/error
handling path where imports fail (catch the exception or detect import failure),
ensuring you pass the relevant notice_id and notice_type before re-raising or
handling the error so rules bound to NoticeImportFailedEvent will run.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2184a and ab99ff0.

📒 Files selected for processing (6)
  • news/URB-3480.feature
  • src/Products/urban/browser/cron/notice.py
  • src/Products/urban/contentrules/configure.zcml
  • src/Products/urban/contentrules/notice.py
  • src/Products/urban/locales/fr/LC_MESSAGES/urban.po
  • src/Products/urban/locales/urban.pot

Comment thread src/Products/urban/browser/cron/notice.py Outdated

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Products/urban/browser/cron/notice.py`:
- Around line 79-80: The code is overloading notice_type with failure reasons
(e.g., "failed retry", "failed import"); change the data model to keep
notice_type as the actual notice type and add a separate field (e.g.,
failure_reason or import_status) for failure details: update assignments that
set notice_type = "failed retry"/"failed import" to instead set failure_reason =
"failed retry"/"failed import" (or pass that string as a new parameter), adjust
calls to _notify_import_error to accept/forward the failure_reason, and update
any place that reads notice_type (including uses around failed_notice_id,
remaining_failed, and the _notify_import_error implementation) to use the new
failure_reason field for filtering and messages. Ensure all occurrences
referenced in the diff (the blocks using failed_notice_id, remaining_failed and
calls to _notify_import_error) are updated consistently.
- Around line 79-80: Make failed-event emission best-effort: wrap calls that
emit failure events (calls to IContextWrapper(...) and notify(...) and the
helper _notify_import_error) in their own try/except so any exception from
emitting the error is caught and logged but not allowed to propagate or
interrupt bookkeeping (e.g., the remaining_failed.append flow). Specifically,
around the places that call IContextWrapper(...) / notify(...) (including the
block that calls self._notify_import_error and the other locations referenced),
catch Exception, log the emission failure with context, and continue so the
original import exception handling and remaining_failed/other bookkeeping always
run; do this for all occurrences (lines referenced 122-123, 167-174 and the
shown call to self._notify_import_error) so event emission is non-blocking.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab99ff0 and db24a47.

📒 Files selected for processing (1)
  • src/Products/urban/browser/cron/notice.py

Comment thread src/Products/urban/browser/cron/notice.py

@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.

♻️ Duplicate comments (1)
src/Products/urban/browser/cron/notice.py (1)

79-80: ⚠️ Potential issue | 🟠 Major

Keep notice_type semantic; use a separate failure field.

On Line 79, Line 122, and Line 156, notice_type is populated with failure reasons instead of the actual NOTICe type. This breaks type-based content-rule filtering and makes ${notice_type} substitutions misleading for failed imports.

🔧 Suggested direction
- def _notify_import_error(self, notice_id="", notice_type=""):
+ def _notify_import_error(self, notice_id="", notice_type="", failure_reason=""):
     try:
         args = {
             "notice_id": notice_id,
             "notice_type": notice_type,
+            "failure_reason": failure_reason,
         }
         urban_folder = api.portal.get().urban
         event_wrapper = IContextWrapper(urban_folder)(**args)
         notify(NoticeImportFailedEvent(event_wrapper))
- self._notify_import_error(failed_notice_id, "failed retry")
+ self._notify_import_error(
+     notice_id=failed_notice_id,
+     notice_type="",  # unknown here unless you persist/recover it
+     failure_reason="failed retry",
+ )
- self._notify_import_error(notice_id, "failed import")
+ self._notify_import_error(
+     notice_id=notice_id,
+     notice_type="",  # pass real type when available
+     failure_reason="failed import",
+ )

Also applies to: 122-123, 156-157, 176-181

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Products/urban/browser/cron/notice.py` around lines 79 - 80, The code is
incorrectly overwriting notice_type with failure reasons; keep notice_type as
the actual NOTICE type and add a separate failure field (e.g., import_failure or
failure_reason) to carry error text. Update places that call
_notify_import_error (the call that currently passes "failed retry" or other
messages alongside remaining_failed) so they pass the real notice_type unchanged
and an extra parameter or payload key for the failure reason, and modify
_notify_import_error to accept and log that new failure field instead of using
notice_type for failures; ensure any message templating or substitutions still
use notice_type for the original type and use the new field where failure
details are needed (references: _notify_import_error, remaining_failed, and the
blocks that append failed_notice_id).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/Products/urban/browser/cron/notice.py`:
- Around line 79-80: The code is incorrectly overwriting notice_type with
failure reasons; keep notice_type as the actual NOTICE type and add a separate
failure field (e.g., import_failure or failure_reason) to carry error text.
Update places that call _notify_import_error (the call that currently passes
"failed retry" or other messages alongside remaining_failed) so they pass the
real notice_type unchanged and an extra parameter or payload key for the failure
reason, and modify _notify_import_error to accept and log that new failure field
instead of using notice_type for failures; ensure any message templating or
substitutions still use notice_type for the original type and use the new field
where failure details are needed (references: _notify_import_error,
remaining_failed, and the blocks that append failed_notice_id).

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db24a47 and 66741b8.

📒 Files selected for processing (1)
  • src/Products/urban/browser/cron/notice.py

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