[fix] Resync org settings on repeated global email disable #431#446
[fix] Resync org settings on repeated global email disable #431#446hypnoastic wants to merge 1 commit intoopenwisp:masterfrom
Conversation
📝 WalkthroughWalkthroughThe patch ensures explicitly provided global notification fields propagate to organization-level settings even if their values don’t change. The serializer records which global fields ( Sequence Diagram(s)This section is skipped because the changes are primarily a bug fix that modifies existing internal logic flow rather than introducing a new feature or significantly restructuring control flow across multiple components in a way that would benefit from visualization. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
There was a problem hiding this comment.
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 `@openwisp_notifications/base/models.py`:
- Around line 470-474: The update-building logic applies the
explicit_global_update_fields check for email but not for web; make web
symmetric by only adding updates["web"] when self.web != previous_state.web or
"web" in explicit_global_update_fields (mirroring the email check using
self.email, previous_state.email, explicit_global_update_fields and
updates["email"]) so future conditional logic for web behaves consistently.
In `@openwisp_notifications/tests/test_api.py`:
- Around line 819-824: Add a symmetric test that verifies reapplying the global
"web" setting behaves like the "email" case: create a new test method (e.g.,
test_reapplying_global_web_setting_updates_organization_settings) that follows
the same setup and flow as the existing email resync test but toggles web (use
web=False then reapply web=True) and asserts the org setting changes and any
side effects are triggered; reference the same request flow that posts to
org_setting_url and the same explicit_global_update_fields handling to ensure
the code path for "web" is exercised.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4f1f1349-0c79-418a-bd24-3239df5c1e02
📒 Files selected for processing (3)
openwisp_notifications/api/serializers.pyopenwisp_notifications/base/models.pyopenwisp_notifications/tests/test_api.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: Python==3.11 | django~=5.1.0
- GitHub Check: Python==3.12 | django~=5.0.0
- GitHub Check: Python==3.11 | django~=5.2.0
- GitHub Check: Python==3.13 | django~=5.2.0
- GitHub Check: Python==3.12 | django~=4.2.0
- GitHub Check: Python==3.12 | django~=5.2.0
- GitHub Check: Python==3.12 | django~=5.1.0
- GitHub Check: Python==3.10 | django~=5.1.0
- GitHub Check: Python==3.11 | django~=4.2.0
- GitHub Check: Python==3.10 | django~=5.0.0
- GitHub Check: Python==3.10 | django~=4.2.0
- GitHub Check: Python==3.10 | django~=5.2.0
- GitHub Check: Python==3.11 | django~=5.0.0
🔇 Additional comments (3)
openwisp_notifications/base/models.py (1)
448-453: LGTM: Clean extraction and cleanup of the hint attribute.The pattern of reading
_explicit_global_update_fieldsinto a local variable and immediately deleting the transient attribute is sound. This prevents stale state if the instance is saved multiple times.openwisp_notifications/api/serializers.py (1)
94-102: LGTM: Clean implementation of the explicit field detection.The logic correctly:
- Detects which fields (
web/validated_data.- Only applies this to global settings (where both
organizationandtypeareNone).- Passes the hint to the model via a transient instance attribute before delegating to
super().update().This approach keeps the serializer and model properly decoupled while enabling the model to know the caller's intent.
openwisp_notifications/tests/test_api.py (1)
797-841: LGTM: Comprehensive regression test for the bug fix.This test accurately reproduces the bug scenario from issue
#431:
- Disables global email notifications
- Re-enables email for a specific organization
- Re-applies the global email disable
- Verifies that organization-level email settings are properly synced
The assertions correctly validate the fix by checking that no
email=Truesettings remain for the organization after step 3.
Preserve explicit global preference updates from the preferences API so reapplying the same global state still propagates to organization notification settings, add API regression coverage for repeated global email and web updates, and include the CI-requested formatting fix. Fixes openwisp#431
0a228b7 to
9009484
Compare
|
Forced Push to keep the commit history clean before review. |
|
I have addressed all the review feedback given by CodeRabbit and the PR is ready for a review. |
What does this PR do?
This fixes a notification preferences bug where reapplying the global email disable state did not resync the user’s organization-level notification settings.
What changed and why?
UI Verification
Screen.Recording.2026-03-21.at.8.20.33.PM.mov
Self Review Checklist
Fixes #431