[PR #20612] [MERGED] Closes #20301: Add "Dismiss all" action to notifications dropdown #15983

Closed
opened 2025-12-30 00:25:09 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20612
Author: @pheus
Created: 10/17/2025
Status: Merged
Merged: 10/28/2025
Merged by: @bctiemann

Base: mainHead: 20301-add-clear-all-option-to-user-notifications-dropdown


📝 Commits (1)

  • 8eaff9d feat(extras): Add "Dismiss all" action to notifications dropdown

📊 Changes

3 files changed (+94 additions, -3 deletions)

View changed files

📝 netbox/extras/views.py (+35 -3)
📝 netbox/templates/htmx/notifications.html (+11 -0)
📝 netbox/utilities/htmx.py (+48 -0)

📄 Description

Fixes: #20301

Add a “Dismiss all” action to the bell dropdown that clears all unread notifications for the current user via a GET endpoint. The dropdown continues to show up to the most recent 10 unread items, and now includes a clear, i18n’d confirmation message that shows the total number of unread notifications affected.

Summary of changes

  • New view: NotificationDismissAllView registered with @register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False); deletes unread notifications for request.user.

    • HTMX requests: if invoked from the Notifications page, return an HX-Redirect to repaint the page; otherwise return the existing dropdown partial.
    • Non‑HTMX requests: redirect to the Notifications page.
  • Dropdown partial context: Now passes only the top 10 unread notifications plus counts:
    notifications = request.user.notifications.unread()[:10],
    total_count = request.user.notifications.count(),
    unread_count = request.user.notifications.unread().count(). :contentReference[oaicite:1]{index=1}

  • Template update (htmx/notifications.html):
    Adds a “Dismiss all” button in the dropdown header when there are unread items, with a pluralized confirmation that shows the total unread count (e.g., “Dismiss 37 unread notifications?”).

  • HTMX utility helpers:
    Introduce htmx_current_url() and htmx_maybe_redirect_current_page() to detect the current page (via HX-Current-URL) and issue an HX-Redirect when appropriate. Both are now used by the single‑item dismiss view and the new dismiss-all view to avoid stale rows on the Notifications page. :contentReference[oaicite:3]{index=3}

Screenshots

Screenshots (notifications present)

Screenshot 2025-10-22 at 14-10-59 Subscriptions NetBox Screenshot 2025-10-22 at 14-10-41 Subscriptions NetBox

Screenshots (no notifications)

Screenshot 2025-10-17 at 00-36-58 Home NetBox Screenshot 2025-10-17 at 00-37-04 Home NetBox

Notes for reviewers

  • The button label uses “Dismiss all” to align with the route name (dismiss-all).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20612 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/17/2025 **Status:** ✅ Merged **Merged:** 10/28/2025 **Merged by:** [@bctiemann](https://github.com/bctiemann) **Base:** `main` ← **Head:** `20301-add-clear-all-option-to-user-notifications-dropdown` --- ### 📝 Commits (1) - [`8eaff9d`](https://github.com/netbox-community/netbox/commit/8eaff9dce76f7ea5337a7c8c9948b2f98d9a879c) feat(extras): Add "Dismiss all" action to notifications dropdown ### 📊 Changes **3 files changed** (+94 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/views.py` (+35 -3) 📝 `netbox/templates/htmx/notifications.html` (+11 -0) 📝 `netbox/utilities/htmx.py` (+48 -0) </details> ### 📄 Description ### Fixes: #20301 Add a **“Dismiss all”** action to the bell dropdown that clears all **unread** notifications for the current user via a GET endpoint. The dropdown continues to show up to the most recent 10 unread items, and now includes a clear, i18n’d confirmation message that shows the total number of unread notifications affected. #### Summary of changes - **New view:** `NotificationDismissAllView` registered with `@register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False)`; deletes **unread** notifications for `request.user`. - HTMX requests: if invoked from the Notifications page, return an **`HX-Redirect`** to repaint the page; otherwise return the existing dropdown partial. - Non‑HTMX requests: redirect to the Notifications page. - **Dropdown partial context:** Now passes only the top **10** unread notifications plus counts: `notifications = request.user.notifications.unread()[:10]`, `total_count = request.user.notifications.count()`, `unread_count = request.user.notifications.unread().count()`. :contentReference[oaicite:1]{index=1} - **Template update (`htmx/notifications.html`):** Adds a “Dismiss all” button in the dropdown header when there are unread items, with a **pluralized** confirmation that shows the total unread count (e.g., “Dismiss 37 unread notifications?”). - **HTMX utility helpers:** Introduce `htmx_current_url()` and `htmx_maybe_redirect_current_page()` to detect the current page (via `HX-Current-URL`) and issue an `HX-Redirect` when appropriate. Both are now used by the single‑item `dismiss` view and the new `dismiss-all` view to avoid stale rows on the Notifications page. :contentReference[oaicite:3]{index=3} #### Screenshots **Screenshots (notifications present)** <img width="302" height="626" alt="Screenshot 2025-10-22 at 14-10-59 Subscriptions NetBox" src="https://github.com/user-attachments/assets/ab9dc1fc-1cf2-4259-971e-df0c977ff16f" /> <img width="302" height="626" alt="Screenshot 2025-10-22 at 14-10-41 Subscriptions NetBox" src="https://github.com/user-attachments/assets/70f47a83-1582-4f3a-a82d-0054b2bd5982" /> **Screenshots (no notifications)** <img width="302" height="78" alt="Screenshot 2025-10-17 at 00-36-58 Home NetBox" src="https://github.com/user-attachments/assets/98cf4705-20c0-44e5-a9e1-3daf836a1cd8" /> <img width="302" height="78" alt="Screenshot 2025-10-17 at 00-37-04 Home NetBox" src="https://github.com/user-attachments/assets/ad5bf3cf-cc37-418e-b411-9fde9cb46952" /> --- #### Notes for reviewers - The button label uses **“Dismiss all”** to align with the route name (`dismiss-all`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:09 +01:00
adam closed this issue 2025-12-30 00:25:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15983