Skip to content

[fix] Fixed web notifications received when disabled globally #495 - #498

Closed
BHARATH0153 wants to merge 0 commit into
openwisp:masterfrom
BHARATH0153:master
Closed

[fix] Fixed web notifications received when disabled globally #495#498
BHARATH0153 wants to merge 0 commit into
openwisp:masterfrom
BHARATH0153:master

Conversation

@BHARATH0153

@BHARATH0153 BHARATH0153 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #495

Changes

  • notify_handler now only sends web notifications to users with web=None when the organization explicitly enables them, or when the global setting is enabled.
  • An explicit organization web=True still overrides a disabled global setting.
  • Added regression tests covering:
    global disabled + organization inherited setting
    global disabled + missing organization settings row
    global disabled + organization explicitly enabled

Checklist

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@BHARATH0153, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 870437c8-7eca-43f5-a2c9-00dae9f409af

📥 Commits

Reviewing files that changed from the base of the PR and between 0a784e5 and cad3205.

📒 Files selected for processing (1)
  • openwisp_notifications/tests/test_notifications.py
📝 Walkthrough

Walkthrough

notify_handler now applies WEB_ENABLED when users inherit organization settings or when organization settings are missing. Explicit organization-level enablement remains effective when global web notifications are disabled. Tests cover inherited settings with existing and missing organization rows, plus explicit organization enablement. Email and web notification outcomes are validated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: pandafy, nemesifier


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (2 errors)

Check name Status Explanation Resolution
Linked Issues check ❌ Error The PR addresses issue #495, but it does not implement the Travis Buddy failure summary requested by directly linked issue #123. Remove issue #123 from the linked issues or implement the Travis Buddy failure-summary functionality before merging.
Bug Fixes ❌ Error The handler fixes the NULL/missing organization fallback, and three deterministic regression tests cover it. The user-facing web symptom has no Selenium regression test. Add a Selenium test that disables global web notifications, sends an eligible notification, and verifies that it does not appear in the notification UI.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required [fix] prefix and clearly describes the global web-notification bug addressed by issue #495.
Description check ✅ Passed The description explains the fix, references issue #495, lists tests, and completes the checklist; the screenshot section is omitted but not relevant.
Out of Scope Changes check ✅ Passed The code and regression tests are focused on organization and global web-notification fallback behavior, with no unrelated changes identified.
Features ✅ Passed The PR fixes bug #495, not a feature request. It changes backend fallback logic and adds regression tests; no UI feature is introduced, so feature-request requirements do not apply.
Changes ✅ Passed The backend-only fix adds three regression tests, preserves public signatures, and existing docs describe global/organization preference inheritance; no UI change requires screenshots.
General Rules ✅ Passed The query uses JOINs with explicit fallback conditions, adds explanatory comments, passes syntax and whitespace checks, and includes regression tests for inherited, missing, and explicit settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@openwisp-companion openwisp-companion Bot added the invalid This doesn't seem right label Aug 2, 2026
@openwisp-companion

Copy link
Copy Markdown

Hi @BHARATH0153,

Thank you for your interest in contributing to OpenWISP.

This pull request has been flagged because external contributors must target an issue validated by maintainers before requesting review.

Please link this pull request to a validated issue by adding Fixes #ISSUE_NUMBER, Closes #ISSUE_NUMBER, or Related to #ISSUE_NUMBER to the pull request description. The issue may be in this repository or another OpenWISP repository.

If there is no validated issue yet, please open one first and wait for maintainer validation before continuing with this pull request.

An issue is considered validated when it is open, has an appropriate label other than invalid or wontfix, and is assigned to one of the project boards mentioned in the OpenWISP Contributing Guidelines.

Please see the OpenWISP Anti AI Spam Policy.

Feel free to join the OpenWISP dev chatroom to coordinate with the development team.

If this is not resolved within 24 hours, this pull request will be closed automatically. Thank you for your understanding.

@kilo-code-bot

kilo-code-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
openwisp_notifications/handlers.py 102 The app_settings.WEB_ENABLED guard was removed from the web=None inheritance path. When WEB_ENABLED=False, users with web=None can still receive web notifications if their organization has web=None or missing organization settings. The PR description states web notifications should only be sent "when the global setting is enabled," but the code no longer checks app_settings.WEB_ENABLED for the web=None inheritance path. Restore the WEB_ENABLED condition so that web=None users only inherit org settings when web notifications are globally enabled.
Files Reviewed (2 files)
  • openwisp_notifications/handlers.py - 1 issue
  • openwisp_notifications/tests/test_notifications.py

Fix these issues in Kilo Cloud

Previous Review Summaries (3 snapshots, latest commit 45c422e)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 45c422e)

Status: No Issues Found | Recommendation: Merge

This is an incremental review of commit 45c422e (chores) on top of the previously reviewed commit 72f3b3e. The only changes are a mechanical refactor in openwisp_notifications/tests/test_notifications.py that moves with patch.object(app_settings, "WEB_ENABLED", False): context managers into @patch.object(app_settings, "WEB_ENABLED", False) decorators. Since new=False is explicitly provided (not DEFAULT), no mock argument is injected into the test methods, so the def test_...(self): signatures remain valid and the patching scope is identical (the entire method body). The semantics are preserved — no behavioral change.

handlers.py was not modified in this incremental window and is out of scope for carry-forward.

Files Reviewed (1 file)
  • openwisp_notifications/tests/test_notifications.py

Previous review (commit 72f3b3e)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py

Previous review (commit 357a3be)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py

Reviewed by ling-3.0-flash-free · Input: 265.5K · Output: 30.7K · Cached: 598.4K

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openwisp_notifications/handlers.py`:
- Around line 95-108: Align the web preference resolution used by the handler’s
notification query with NotificationSetting.web_notification when WEB_ENABLED is
false. Update the model resolver or introduce a shared resolver so a missing
OrganizationNotificationSettings row applies the same fallback and yields the
same effective value as the query, preventing enabled notifications from being
reported but excluded from delivery.
🪄 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 Plus

Run ID: 08391bfe-8b85-4cf9-8dd0-36b139d3857e

📥 Commits

Reviewing files that changed from the base of the PR and between 982872b and 357a3be.

📒 Files selected for processing (2)
  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Python==3.12 | django~=5.2.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.13 | django~=5.2.0
  • GitHub Check: Python==3.11 | django~=5.0.0
  • GitHub Check: Python==3.10 | django~=5.0.0
  • GitHub Check: Python==3.12 | django~=5.0.0
  • GitHub Check: Python==3.13 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=5.2.0
  • GitHub Check: Python==3.12 | django~=4.2.0
  • GitHub Check: Python==3.11 | django~=4.2.0
  • GitHub Check: Python==3.10 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.2.0
  • GitHub Check: Python==3.10 | django~=4.2.0
  • GitHub Check: Kilo Code Review
🧰 Additional context used
📓 Path-based instructions (4)
openwisp_notifications/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Mark user-facing strings as translatable with Django i18n helpers, typically gettext_lazy imported as _

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid unnecessary blank lines inside function and method bodies
Write comments and docstrings only when they explain why code is shaped a certain way. Put comments before the relevant code block instead of scattering them inside it

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
openwisp_notifications/{serializers,views,handlers,tasks}.py

📄 CodeRabbit inference engine (AGENTS.md)

Preserve validation and permission checks when changing serializers, views, handlers, or tasks that include notification payloads with related objects and URLs

Files:

  • openwisp_notifications/handlers.py
**/*.{py,html,txt,md}

📄 CodeRabbit inference engine (Custom checks)

For Django pull requests, ensure all user-facing strings are marked as translatable using the Django i18n framework.

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
🧠 Learnings (1)
📚 Learning: 2026-05-07T16:17:11.806Z
Learnt from: pandafy
Repo: openwisp/openwisp-notifications PR: 450
File: openwisp_notifications/tests/test_selenium.py:276-285
Timestamp: 2026-05-07T16:17:11.806Z
Learning: In OpenWISP projects’ test code (e.g., openwisp-notifications), Celery is configured project-wide to run tasks eagerly/synchronously during tests (e.g., `CELERY_TASK_ALWAYS_EAGER=True` or an equivalent setting). Therefore, when reviewing these tests, don’t flag “race condition” or “async Celery” concerns for code that assumes task completion—tasks are guaranteed to finish before execution proceeds to the next line of test code.

Applied to files:

  • openwisp_notifications/tests/test_notifications.py
🔇 Additional comments (1)
openwisp_notifications/tests/test_notifications.py (1)

2049-2054: LGTM!

Also applies to: 2056-2062, 2064-2073

Comment thread openwisp_notifications/handlers.py Outdated
@BHARATH0153

BHARATH0153 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

before fix

Screen.Recording.2026-08-03.at.8.22.10.AM.mov

after fix

Screen.Recording.2026-08-03.at.8.23.44.AM.mov

@nemesifier Yes, I verified the changes line by line and did manual testing.

I reproduced the issue following #495: with OPENWISP_NOTIFICATIONS_WEB_ENABLED = False, a recipient with inherited settings (web=None, org setting NULL) still received a web notification on the base branch. With the fix, the same steps create no notification. An explicit org web=True override still works.

Video demonstration attached. Added 3 regression tests; QA and full test suite pass

@openwisp-companion

Copy link
Copy Markdown

This pull request has been automatically closed because it has been flagged as invalid (not referencing a validated issue) for more than 24 hours.

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

@BHARATH0153 please fix the authorship.

Image

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openwisp_notifications/tests/test_notifications.py`:
- Around line 2056-2062: Add coverage for the globally enabled
missing-organization-settings branch by creating a companion test near
test_web_disabled_globally_org_inherited_missing_row with WEB_ENABLED set to
True, the inherited user web setting, and the organization notification settings
row deleted. Send the notification and assert that both the notification is
created and an email is sent using _assert_notification_created and
_assert_email_sent.
🪄 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 Plus

Run ID: 74f25b6a-276d-4eb8-8915-01d8997e1a94

📥 Commits

Reviewing files that changed from the base of the PR and between 357a3be and 45c422e.

📒 Files selected for processing (2)
  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Python==3.10 | django~=5.0.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=4.2.0
  • GitHub Check: Python==3.12 | django~=5.2.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.11 | django~=5.1.0
  • GitHub Check: Kilo Code Review
🧰 Additional context used
📓 Path-based instructions (4)
openwisp_notifications/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Mark user-facing strings as translatable with Django i18n helpers, typically gettext_lazy imported as _

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid unnecessary blank lines inside function and method bodies
Write comments and docstrings only when they explain why code is shaped a certain way. Put comments before the relevant code block instead of scattering them inside it

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
openwisp_notifications/{serializers,views,handlers,tasks}.py

📄 CodeRabbit inference engine (AGENTS.md)

Preserve validation and permission checks when changing serializers, views, handlers, or tasks that include notification payloads with related objects and URLs

Files:

  • openwisp_notifications/handlers.py
**/*.{py,html,txt,md}

📄 CodeRabbit inference engine (Custom checks)

For Django pull requests, ensure all user-facing strings are marked as translatable using the Django i18n framework.

Files:

  • openwisp_notifications/handlers.py
  • openwisp_notifications/tests/test_notifications.py
🧠 Learnings (1)
📚 Learning: 2026-05-07T16:17:11.806Z
Learnt from: pandafy
Repo: openwisp/openwisp-notifications PR: 450
File: openwisp_notifications/tests/test_selenium.py:276-285
Timestamp: 2026-05-07T16:17:11.806Z
Learning: In OpenWISP projects’ test code (e.g., openwisp-notifications), Celery is configured project-wide to run tasks eagerly/synchronously during tests (e.g., `CELERY_TASK_ALWAYS_EAGER=True` or an equivalent setting). Therefore, when reviewing these tests, don’t flag “race condition” or “async Celery” concerns for code that assumes task completion—tasks are guaranteed to finish before execution proceeds to the next line of test code.

Applied to files:

  • openwisp_notifications/tests/test_notifications.py
🔇 Additional comments (2)
openwisp_notifications/handlers.py (1)

95-108: Duplicate: Align the query with the model resolver.

When app_settings.WEB_ENABLED is False and the organization settings row is missing, this query excludes users whose notificationsetting__web is None. The NotificationSetting.web_notification resolver still returns the notification type default when the reverse relation is absent. Model-level consumers can report web notifications as enabled while notify_handler omits delivery. Align the resolver with this fallback or use one shared resolver. This is the same unresolved issue from the previous review. (raw.githubusercontent.com)

openwisp_notifications/tests/test_notifications.py (1)

2049-2054: LGTM!

Also applies to: 2064-2072

Comment thread openwisp_notifications/tests/test_notifications.py Outdated
@BHARATH0153

Copy link
Copy Markdown
Contributor Author

This PR was closed because it was created from the fork master branch. Per the contributing guidelines it has been reopened as a dedicated feature branch in PR #499: #499

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.

[bug] Users can receive web notifications even if disabled globally

2 participants