Comprehensive Newsletter functionality
Closes: https://github.com/OWASP-BLT/BLT/issues/3725
WIP, currently requires testing. I've created newsletter modals and incorporated various functions which provides users with functionality mentioned below:
- User Functionality:
- Subscribe to newsletters
- Manage their subscription preferences
- View past newsletters
- Receive personalised newsletters based on their preferences
- Unsubscribe if they wish
- The admin interface allows site administrators to:
- Create and publish newsletters
- Send newsletters to subscribers
- Manage subscriber lists
- Track newsletter views and engagement
Implementation includes proper subscription management, confirmation emails, and preference controls.
Summary by CodeRabbit
-
New Features
- Launched a comprehensive newsletter system with dedicated pages for viewing, subscribing, confirming, unsubscribing, and managing preferences.
- Introduced engaging UI enhancements including a subscription banner, intuitive sidebar navigation, and detailed newsletter display.
- Upgraded email communications with modern, responsive confirmation and newsletter update templates.
- Enhanced administrative tools for efficient newsletter and subscriber management.
- Added a markdown filter for improved content formatting in newsletters.
-
Bug Fixes
- Resolved issues related to user activity logging during newsletter interactions.
-
Documentation
- Updated templates and context processors to improve user experience regarding newsletter subscriptions and management.
@DonnieBLT sir, please review the newsletter functionality I've implemented:
https://github.com/user-attachments/assets/b7b06112-9cfb-4a2c-8b17-1c9d890b0c8e
@tsu-ki sure, can you please resolve the conflicts and fix the video / screenshot?
Walkthrough
This change set introduces an extensive newsletter feature. It adds new Django models for newsletters and newsletter subscribers along with associated migrations. New view functions, URL routes, and templates support newsletter subscription, confirmation, unsubscription, preference management, and detail display. A management command for sending newsletters is implemented, and new admin classes enable management via the admin interface. Additionally, relevant settings, context processors, custom template filters, and dependency updates are applied to integrate Markdown rendering and newsletter functionality within the project.
Changes
| File(s) | Change Summary |
|---|---|
| blt/settings.py blt/urls.py |
Modified environment variable handling and added a new context processor for newsletters; introduced multiple newsletter URL patterns and imported include in URLs, removing an old management commands route. |
| website/admin.py website/management/commands/send_newsletter.py |
Introduced NewsletterAdmin and NewsletterSubscriberAdmin classes in the admin; added a management command to send newsletters, including methods to handle email sending and error logging. |
| website/models.py website/migrations/0233_ & 0234_ ** |
Added Newsletter and NewsletterSubscriber models with their methods and properties; created migrations for these models and added a token_created_at field to NewsletterSubscriber. |
| website/templates/base.html website/templates/includes/sidenav.html website/templates/newsletter/ |
Updated base and sidenav templates to include a newsletter subscription banner and navigation link; added new newsletter templates for detail, email (confirmation and newsletter), home, preferences, and subscription pages. |
| website/views/core.py website/views/user.py website/templatetags/custom_filters.py |
Enhanced view functions by adding a newsletter context processor and various newsletter-related functions (home, detail, subscribe, confirm, unsubscribe, preferences, resend confirmation); added a markdown_filter for Markdown conversion in templates. |
| pyproject.toml | Downgraded django-gravatar2 version and added new dependencies: environ, google-auth, django-markdown-deux, bleach, django-anymail, and django-ckeditor. |
Sequence Diagram(s)
sequenceDiagram
participant U as User
participant FE as Frontend (subscribe.html)
participant VS as Newsletter Subscribe View
participant NE as send_confirmation_email
participant ES as Email Server
participant EC as User Email Client
U->>FE: Submit subscription form
FE->>VS: POST subscription data
VS->>NE: Create/update subscriber and send confirmation
NE->>ES: Send confirmation email (confirmation_email.html)
ES->>EC: Deliver confirmation email
EC->>U: User receives email
U->>VS: Clicks confirmation link (newsletter_confirm view)
VS->>VS: Validate token and update subscription status
sequenceDiagram
participant A as Admin
participant CMD as send_newsletter Command
participant NL as Newsletter Model
participant NS as NewsletterSubscriber Model
participant ES as Email Server
A->>CMD: Run send_newsletter command
CMD->>NL: Retrieve newsletter(s) pending send
CMD->>NS: Retrieve active and confirmed subscribers
loop For each subscriber
CMD->>ES: Send newsletter email (using EmailMultiAlternatives)
end
CMD->>NL: Mark newsletter as sent
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 40c14bdf0fbd641f51b3ce0a82db083b755a743f and 803feffe5a6ea7aac7f0bf398c933a8bd032512b.
π Files selected for processing (1)
website/migrations/0234_newslettersubscriber_token_created_at.py(1 hunks)
π§ Files skipped from review as they are similar to previous changes (1)
- website/migrations/0234_newslettersubscriber_token_created_at.py
β° Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
πͺ§ Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@DonnieBLT sir, I've uploaded 2 videos, which show the user-side functionality and admin-side functionality. Please check them out and update me if there's anything else I should change. (another video is attached in the top comment)
https://github.com/user-attachments/assets/4e0663da-b2c5-49ca-b8a7-ff8f3189457e
@tsu-ki can you please fix the conflicts and address the comments
@tsu-ki can you please fix the conflicts and address the comments
@DonnieBLT sir, I'll resolve the conflicts. I've also addressed most of the comments and will push the final code once it's ready, just need to fix linting and some dependency errors. Another thing I wanted to address was using inline css in email template. As, external css is stripped away during email generation, I've resorted to using it inline. Is that okay?
@tsu-ki can you please fix the conflicts and address the comments
@DonnieBLT sir, I'll resolve the conflicts. I've also addressed most of the comments and will push the final code once it's ready, just need to fix linting and some dependency errors. Another thing I wanted to address was using inline css in email template. As, external css is stripped away during email generation, I've resorted to using it inline. Is that okay?
Itβs ok if itβs inline tailwind
@DonnieBLT sir, I've made the required corrections. I've tried to resolve the failing pre-commit test but not sure why it's not getting resolved. please review the changes, thank you!
/giphy nice feature

can you please update this
β οΈ Merge Conflicts Detected
Hi @tsu-ki!
This pull request has merge conflicts with the base branch that need to be resolved before it can be merged.
To resolve the conflicts:
-
Sync your branch with the base branch:
git fetch origin git merge origin/main -
Resolve any conflicts in your editor
-
Commit the changes:
git add . git commit -m "Resolve merge conflicts" git push
Once you push the resolved conflicts, this label and comment will be automatically updated.
Thank you! π