Skip to content

[feat] Add unsubscribe link to email notifications #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 117 commits into from
Mar 21, 2025

Conversation

Dhanus3133
Copy link
Member

@Dhanus3133 Dhanus3133 commented Aug 24, 2024

Fixes: #256

FYR, Please note that this feature depends on PR #290 to manage global email notification preferences, which is not implemented in this PR. Currently, the user's first notification will be treated as their global email notification preference.

Regarding the email token generated:

  • No expiry.
  • Invalidated once the user updates their password.

Dhanus3133 and others added 30 commits August 21, 2024 12:32
Implements and closes #132.

---------

Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
Co-authored-by: Gagan Deep <pandafy.dev@gmail.com>
- Updated the `NotificationSettingSerializer` to also include
`organization_name`.
- New endpoint `/api/user-setting/organization/<uuid:organization_id>/`
to allow changes toggling of email/web notification settings of a
particular org with just a single API call.
@pandafy pandafy force-pushed the notification-preferences branch from bdadba4 to 0feb0d2 Compare December 27, 2024 15:56
@pandafy pandafy force-pushed the notification-preferences branch from 2c7ffb4 to 8dea29f Compare March 5, 2025 14:09
Base automatically changed from notification-preferences to gsoc24-rebased March 5, 2025 14:27
Comment on lines 28 to 34
<p id="status-message">
{% if is_subscribed %}
{% trans 'You are currently subscribed to notifications.' %}
{% else %}
{% trans 'You are currently unsubscribed from notifications.' %}
{% endif %}
</p>
Copy link
Member

Choose a reason for hiding this comment

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

We are duplicating these text messages in JS. Maybe, we can create separate paragraph elements for each condition and hide one using CSS based on is_subscribed

Comment on lines 24 to 26
statusMessage.textContent = gettext(
"You are currently subscribed to notifications."
);
Copy link
Member

Choose a reason for hiding this comment

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

Then, we can update this logic to hide/show the required message.

toggleBtn.setAttribute("data-hasSubscribe", "false");
}

confirmationMsg.textContent = gettext(data.message);
Copy link
Member

Choose a reason for hiding this comment

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

We are displaying output from the API/view here. This is not optimal. We can make the confirmation message independent of the API response. We can similar messages to statusMessage in the HTML and hide/show using CSS.

confirmationMsg.textContent = gettext(data.message);
confirmationMsg.style.display = "block";
} else {
window.alert(data.message);
Copy link
Member

Choose a reason for hiding this comment

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

This appears a bad UX. We can add an error message paragraph element instead of using alert. Also, we can instruct the user that they can login and update the notification preference from the notification preference page.

}
})
.catch((error) => {
window.console.error("Error:", error);
Copy link
Member

Choose a reason for hiding this comment

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

Same here, use should be notified of the error.

pandafy added 4 commits March 11, 2025 20:01
The email summary template adds additional style element.
By default, send_email injects body_html inside the body tag.
With this patch, the code extends the default template for email
and fixes the semantics of HTML.
@pandafy pandafy moved this from To do (general) to Needs review in OpenWISP Contributor's Board Mar 19, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I don't see any documentation change relating to this new feature, but I think is relevant.

We could mention this feature here:
https://openwisp.io/docs/dev/notifications/user/web-email-notifications.html

I think we should update this screenshot to show the unsubscribe link in the footer:
https://raw.githubusercontent.com/openwisp/openwisp-notifications/docs/docs/images/email-template.png
(rather than updating, we should upload a new one, eg: docs/images/25/email-template.png).

Please also update this other screenshot as well:
https://github.com/openwisp/openwisp-notifications/blob/docs/docs/images/25/emails/batch-email.png

@github-project-automation github-project-automation bot moved this from Needs review to In progress in OpenWISP Contributor's Board Mar 19, 2025

// Update button text and attribute
toggleBtn.textContent = gettext(
subscribe ? "Unsubscribe" : "Subscribe"
Copy link
Member

Choose a reason for hiding this comment

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

flag as translatable

<p>
{% trans 'Manage other preferences?' %}
<a href="{% url 'notifications:notification_preference' %}">
{% trans 'Click here' %}
Copy link
Member

Choose a reason for hiding this comment

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

For some reason I hadn't seen this.
For the 1000000th time, please don't do this, see Why You Should Never Write “Click Here”.

@@ -0,0 +1,2 @@
{% load i18n %}
<p style="margin-bottom: 0px; font-size: small">{% blocktrans %}To unsubscribe from these notifications, <a href="{{ unsubscribe_url }}">click here</a>.{% endblocktrans %}</p>
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of centering this?

Why You Should Never Write “Click Here” applies here as well.

@nemesifier nemesifier merged commit 50ef458 into gsoc24-rebased Mar 21, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in OpenWISP Contributor's Board Mar 21, 2025
@nemesifier nemesifier deleted the feat/manage-notifications-unsubscribe branch March 21, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants