Skip to content

refactor: consolidate notifications into dojo/notifications/ package#14767

Merged
Maffooch merged 4 commits intoDefectDojo:devfrom
Maffooch:worktree-concurrent-chasing-piglet
Apr 30, 2026
Merged

refactor: consolidate notifications into dojo/notifications/ package#14767
Maffooch merged 4 commits intoDefectDojo:devfrom
Maffooch:worktree-concurrent-chasing-piglet

Conversation

@Maffooch
Copy link
Copy Markdown
Contributor

Summary

  • Consolidates the entire notification domain — models, admin, services (helper.py), signals, tasks, settings, context processors, forms, UI views/urls/templates, and API serializers/viewsets/urls — under dojo/notifications/, matching the canonical dojo/url/ shape from CLAUDE.md.
  • Backward-compatible re-exports preserved at every original location (dojo/models.py, dojo/forms.py, dojo/utils.py, dojo/tasks.py, dojo/context_processors.py, dojo/api_v2/{serializers,views}.py, dojo/notifications/helper.py).
  • 69 templates relocated into dojo/notifications/templates/notifications/ (62 channel .tpl files keep identical lookup names; 7 UI .html files re-namespaced from dojo/...html to notifications/...html). A new TEMPLATES DIRS entry resolves both trees from the package.
  • Notification env-var schema (NOTIFICATIONS_ENV_DEFAULTS + populate_settings) extracted into dojo/notifications/settings.py; settings.dist.py consumes it. Celery beat task paths updated.
  • No new migrations — string FK references in the relocated models are migration-equivalent to the original class references.

Test plan

  • python manage.py check — clean (4 silenced)
  • python manage.py makemigrations --check --dry-runNo changes detected
  • python manage.py spectacular --fail-on-warn — clean
  • Pytest: test_notifications, test_apiv2_notifications, test_jira_webhook, test_cleanup_alerts, test_rest_framework (1325 tests; all pass, 610 version-skipped)
  • CI passes
  • Smoke-test in dev: trigger a finding save and confirm Slack/email/webhook channels still fire end-to-end

🤖 Generated with Claude Code

@Maffooch Maffooch requested a review from mtesauro as a code owner April 27, 2026 22:27
@github-actions github-actions Bot added settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR apiv2 unittests labels Apr 27, 2026
@Maffooch Maffooch changed the title Consolidate notifications into dojo/notifications/ package refactor: consolidate notifications into dojo/notifications/ package Apr 27, 2026
@Maffooch Maffooch force-pushed the worktree-concurrent-chasing-piglet branch from 60d786c to 4791b8a Compare April 27, 2026 22:39
Move notification models, admin, services (helper.py), signals, tasks,
settings, context processors, forms, UI views/urls/templates, and API
serializers/viewsets/urls into dojo/notifications/, matching the
canonical dojo/url/ shape from CLAUDE.md.

- Notifications, Notification_Webhooks, Alerts (and constants) extracted
  from dojo/models.py into dojo/notifications/models.py; admin moved to
  dojo/notifications/admin.py using @admin.register(); registered from
  dojo/apps.py ready() to keep model class definition out of the
  settings-loading import chain.
- helper.py absorbs process_tag_notifications and sla_compute_and_notify
  from dojo/utils.py. All @app.task wrappers (log_generic_alert,
  add_alerts, cleanup_alerts, async_sla_compute_and_notify_task,
  async_create_notification, send_{slack,msteams,mail,webhooks}_notification,
  webhook_reactivation, webhook_status_cleanup) consolidated into
  dojo/notifications/tasks.py. async_create_notification calls into
  helper.create_notification via lazy import so test patches still apply.
- Default-Notifications-on-User-create logic moved out of dojo/utils.py
  into dojo/notifications/signals.py and registered via apps.py ready().
- 7 UI .html templates and 62 channel .tpl templates moved under
  dojo/notifications/templates/notifications/. New TEMPLATES DIRS entry
  added so notifications/{channel}/{event}.tpl lookups still resolve;
  view template_name strings updated where the namespace changed.
- Env-var schema extracted into dojo/notifications/settings.py
  (NOTIFICATIONS_ENV_DEFAULTS dict + populate_settings); settings.dist.py
  unpacks it into env() and applies values to globals().
- bind_alert_count and session_expiry_notification moved to
  dojo/notifications/context_processors.py; TEMPLATES paths updated.
- API NotificationsSerializer/NotificationWebhooksSerializer and
  Viewsets relocated under dojo/notifications/api/, exposed via
  add_notifications_urls(router) (CLAUDE.md API pattern).
- Celery beat task paths updated to dojo.notifications.tasks.*.
- Backward-compatible re-exports preserved at every original location
  (dojo/models.py, dojo/forms.py, dojo/utils.py, dojo/tasks.py,
  dojo/context_processors.py, dojo/api_v2/{serializers,views}.py,
  dojo/notifications/helper.py).
- No new migrations (string FK references are migration-equivalent).

Verified: manage.py check, makemigrations --check (no diff),
spectacular --fail-on-warn, the notification + cleanup-alerts +
jira-webhook + REST framework test suites pass, and ruff check . is
clean for new code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Maffooch Maffooch force-pushed the worktree-concurrent-chasing-piglet branch from 4791b8a to 991d3b7 Compare April 27, 2026 23:01
@Maffooch Maffooch added the affects_pro PRs that affect Pro and need a coordinated release/merge moment. label Apr 28, 2026
@Maffooch Maffooch added this to the 2.58.0 milestone Apr 28, 2026
Copy link
Copy Markdown
Member

@valentijnscholten valentijnscholten left a comment

Choose a reason for hiding this comment

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

What does this PR mean for users that have customized their templates?

@Maffooch
Copy link
Copy Markdown
Contributor Author

They will need to change their templates - I can add some breaking changes to the release notes

@valentijnscholten
Copy link
Copy Markdown
Member

My question was about the tpl files and it looks like no action is needed for people who modified those?

@Maffooch
Copy link
Copy Markdown
Contributor Author

Yeah most folks will likely not be impacted. The tpl files are changing locations, so if there folks with custom template downstream, and then update to the new version, the default tpl files will be read rather than the custom ones. So the action required for users that have modified those templates will be to move them to the new location.

@valentijnscholten
Copy link
Copy Markdown
Member

For me it's not clear from the added upgrade notes that users need to move their customized templates (and where).
I would make that explicit. And then remove all the text about the html templates as that is not a typical use case / something we actively support.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Copy Markdown
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

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

Approved

# Conflicts:
#	dojo/models.py
#	dojo/settings/settings.dist.py
@github-actions
Copy link
Copy Markdown
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@Maffooch Maffooch merged commit 7ea54d4 into DefectDojo:dev Apr 30, 2026
158 checks passed
Maffooch pushed a commit to devGregA/django-DefectDojo that referenced this pull request Apr 30, 2026
Pulls in 15 upstream commits including:

* dojo/sso/ consolidation (DefectDojo#14765) — SSO settings/urls/views/templates/
  remote-user moved into a self-contained package.
* dojo/notifications/ consolidation (DefectDojo#14767) — notification helper +
  templates moved into the package, with a new context_processors split.
* dojo/github/ consolidation (DefectDojo#14766) — github_issue_link package
  renamed and reshaped under dojo/github/{models,services,ui,...}.
* test_tag_inheritance.py extension (DefectDojo#14771).
* Bulk-delete findings extension hook (DefectDojo#14740).
* Planned-remediation-version column alignment fix (DefectDojo#14773).
* Dependency bumps (datatables.net, gitpython, python-gitlab, pyopenssl,
  vulners, ruff, postcss).

Conflict resolutions worth flagging:

* dojo/forms.py — kept dev's reshuffled imports (GITHUB_* models now
  re-exported via dojo.github.ui.forms; Global_Role moved to
  dojo.models). Dropped the duplicate Global_Role import; the legacy
  authorization rewrite still imports from
  dojo.authorization.models for the rest.
* dojo/settings/settings.dist.py — kept tailwind's UIPreferenceLoader
  chain and APP_DIRS=False, but added a shared
  _DOJO_EXTRA_TEMPLATE_DIRS list referenced by both TEMPLATES[0]["DIRS"]
  and the FilesystemLoader so that dojo/sso/settings.py:apply_sso_settings
  can append the SSO template dir at startup and have it resolved at
  render time.
* dojo/templates/dojo/login.html — Tailwind tree, kept the inline
  Tailwind-styled SSO buttons rather than dev's
  {% include "dojo/sso_login_buttons.html" %} (which is Bootstrap-classic
  flavored and mounted by the SSO consolidation against the classic tree
  only).
* unittests/test_remote_user.py — adopted dev's import path
  (dojo.sso.remote_user, dojo.models.Dojo_Group_Member).
* dojo/api_v2/permissions.py — added a backward-compat shim
  re-exporting from dojo.authorization.api_permissions because the
  legacy authorization consolidation deleted the old module but
  dojo/notifications/api/views.py (new from dev) still imports from the
  old path.

Verified: ruff clean on touched files; manage.py check passes;
unittests.test_authorized_users_ui + unittests.authorization +
unittests.test_user_ui_timestamps + unittests.test_rest_framework +
unittests.test_remote_user all green (1144 tests, 542 skipped).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects_pro PRs that affect Pro and need a coordinated release/merge moment. apiv2 docs settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR unittests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants