diff --git a/CHANGELOG.md b/CHANGELOG.md index 38563fae..9d48fcff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Fix project sort order to be case-insensitive everywhere in the UI (#768) - Fix special character encoding in project invite emails - Fix check transfer between same account's projects when at check limit +- Fix wording in the invite email when inviting read-only users ## v2.5 - 2022-12-14 diff --git a/hc/accounts/models.py b/hc/accounts/models.py index ec75d05b..c3c79d16 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -116,7 +116,7 @@ class Profile(models.Model): return "login" in self.token and check_password(token, self.token) - def send_instant_login_link(self, inviting_project=None, redirect_url=None): + def send_instant_login_link(self, membership=None, redirect_url=None): token = self.prepare_token() path = reverse("hc-check-token", args=[self.user.username, token]) if redirect_url: @@ -125,7 +125,7 @@ class Profile(models.Model): ctx = { "button_text": "Sign In", "button_url": settings.SITE_ROOT + path, - "inviting_project": inviting_project, + "membership": membership, } emails.login(self.user.email, ctx) @@ -393,9 +393,9 @@ class Project(models.Model): if self.owner_id == user.id: return False - Member.objects.create(user=user, project=self, role=role) + m = Member.objects.create(user=user, project=self, role=role) checks_url = reverse("hc-checks", args=[self.code]) - user.profile.send_instant_login_link(self, redirect_url=checks_url) + user.profile.send_instant_login_link(membership=m, redirect_url=checks_url) return True def update_next_nag_dates(self): diff --git a/hc/accounts/tests/test_project.py b/hc/accounts/tests/test_project.py index c4ab7fca..97f61420 100644 --- a/hc/accounts/tests/test_project.py +++ b/hc/accounts/tests/test_project.py @@ -115,8 +115,13 @@ class ProjectTestCase(BaseTestCase): self.assertFalse(member.user.project_set.exists()) # And an email should have been sent + message = mail.outbox[0] subj = f"You have been invited to join Alice's Project on {settings.SITE_NAME}" - self.assertEqual(mail.outbox[0].subject, subj) + self.assertEqual(message.subject, subj) + + html, _ = message.alternatives[0] + self.assertIn("You will be able to manage", message.body) + self.assertIn("You will be able to manage", html) def test_it_adds_readonly_team_member(self): self.client.login(username="alice@example.org", password="password") @@ -131,6 +136,12 @@ class ProjectTestCase(BaseTestCase): self.assertEqual(member.role, member.Role.READONLY) + # And an email should have been sent + message = mail.outbox[0] + html, _ = message.alternatives[0] + self.assertIn("You will be able to view", message.body) + self.assertIn("You will be able to view", html) + def test_it_adds_manager_team_member(self): self.client.login(username="alice@example.org", password="password") diff --git a/templates/emails/login-body-html.html b/templates/emails/login-body-html.html index 14bc3b38..ac905062 100644 --- a/templates/emails/login-body-html.html +++ b/templates/emails/login-body-html.html @@ -5,20 +5,23 @@ Hello, <br /> -{% if inviting_project %} - {% if inviting_project.name %} - <strong>{{ inviting_project.owner.email }}</strong> invites you to their +{% if membership %} + {% if membership.project.name %} + <strong>{{ membership.project.owner.email }}</strong> invites you to their <a href="{% site_root %}">{% site_name %}</a> - project <strong>{{ inviting_project }}</strong>. + project <strong>{{ membership.project }}</strong>. {% else %} - <strong>{{ inviting_project.owner.email }}</strong> invites you to their + <strong>{{ membership.project.owner.email }}</strong> invites you to their <a href="{% site_root %}">{% site_name %}</a> account. {% endif %} <br /><br /> - You will be able to manage their - existing monitoring checks and set up new ones. If you already have your - own account on {% site_name %}, you will be able to switch + {% if membership.role == "r" %} + You will be able to view their existing monitoring checks, but not modify them. + {% else %} + You will be able to manage their existing monitoring checks and set up new ones. + {% endif %} + If you already have your own account on {% site_name %}, you will be able to switch between the two accounts. <br /><br /> {% endif %} diff --git a/templates/emails/login-body-text.html b/templates/emails/login-body-text.html index a6e53e39..ee8c7aea 100644 --- a/templates/emails/login-body-text.html +++ b/templates/emails/login-body-text.html @@ -1,11 +1,13 @@ {% load hc_extras %} {% block content %}Hello, -{% if inviting_project %} -{{ inviting_project.owner.email }} invites you to their {% site_name %} account. +{% if membership %} +{{ membership.project.owner.email }} invites you to their {% site_name %} account. -You will be able to manage their existing monitoring checks and set up new -ones. If you already have your own account on {% site_name %}, you will +{% if membership.role == "r" %}You will be able to view their existing monitoring checks, but not +modify them.{% else %}You will be able to manage their existing monitoring checks and set up +new ones.{% endif %} If you already have your own account on {% site_name %}, you will be able to switch between the two accounts.{% endif %} + To log into {% site_name %}, please open the link below: {{ button_url }} diff --git a/templates/emails/login-subject.html b/templates/emails/login-subject.html index b6fd9da0..69eefb4a 100644 --- a/templates/emails/login-subject.html +++ b/templates/emails/login-subject.html @@ -1,6 +1,6 @@ {% load hc_extras %} -{% if inviting_project %} - You have been invited to join {{ inviting_project|safe }} on {% site_name %} +{% if membership %} + You have been invited to join {{ membership.project|safe }} on {% site_name %} {% else %} Log in to {% site_name %} {% endif %}