Browse Source

Send an "Ownership Transfer Request" email notification.

pull/360/head
Pēteris Caune 5 years ago
parent
commit
57da17b8e2
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
10 changed files with 72 additions and 2 deletions
  1. +2
    -1
      CHANGELOG.md
  2. +13
    -0
      hc/accounts/models.py
  3. +6
    -0
      hc/accounts/tests/test_transfer_project.py
  4. +3
    -1
      hc/accounts/views.py
  5. +4
    -0
      hc/lib/emails.py
  6. +8
    -0
      templates/accounts/project.html
  7. +2
    -0
      templates/base.html
  8. +19
    -0
      templates/emails/transfer-request-body-html.html
  9. +14
    -0
      templates/emails/transfer-request-body-text.html
  10. +1
    -0
      templates/emails/transfer-request-subject.html

+ 2
- 1
CHANGELOG.md View File

@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file.
### Improvements
- Rate limiting for Telegram notifications (10 notifications per chat per minute)
- Use Slack V2 OAuth flow
- "Edit" function for webhook integrations (#176)
- Users can edit their existing webhook integrations (#176)
- Add a "Transfer Ownership" feature in Project Settings
### Bug Fixes
- "Get a single check" API call now supports read-only API keys (#346)


+ 13
- 0
hc/accounts/models.py View File

@ -96,6 +96,19 @@ class Profile(models.Model):
}
emails.login(self.user.email, ctx)
def send_transfer_request(self, project):
token = self.prepare_token("login")
settings_path = reverse("hc-project-settings", args=[project.code])
path = reverse("hc-check-token", args=[self.user.username, token])
path += "?next=%s" % settings_path
ctx = {
"button_text": "Project Settings",
"button_url": settings.SITE_ROOT + path,
"project": project,
}
emails.transfer_request(self.user.email, ctx)
def send_set_password_link(self):
token = self.prepare_token("set-password")
path = reverse("hc-set-password", args=[token])


+ 6
- 0
hc/accounts/tests/test_transfer_project.py View File

@ -1,3 +1,4 @@
from django.core import mail
from django.utils.timezone import now
from hc.api.models import Check
from hc.test import BaseTestCase
@ -21,6 +22,11 @@ class ProjectTestCase(BaseTestCase):
self.bobs_membership.refresh_from_db()
self.assertIsNotNone(self.bobs_membership.transfer_request_date)
# Bob should receive an email notification
self.assertEqual(len(mail.outbox), 1)
body = mail.outbox[0].body
self.assertTrue("/?next=" + self.url in body)
def test_transfer_project_checks_ownership(self):
self.client.login(username="[email protected]", password="password")


+ 3
- 1
hc/accounts/views.py View File

@ -34,6 +34,7 @@ NEXT_WHITELIST = (
"hc-add-slack",
"hc-add-pushover",
"hc-add-telegram",
"hc-project-settings",
)
@ -350,7 +351,8 @@ def project(request, code):
ctx["transfer_initiated"] = True
ctx["transfer_status"] = "success"
# FIXME send email
profile = Profile.objects.get(user__email=email)
profile.send_transfer_request(project)
elif "cancel_transfer" in request.POST:
if not is_owner:


+ 4
- 0
hc/lib/emails.py View File

@ -41,6 +41,10 @@ def login(to, ctx):
send("login", to, ctx)
def transfer_request(to, ctx):
send("transfer-request", to, ctx)
def set_password(to, ctx):
send("set-password", to, ctx)


+ 8
- 0
templates/accounts/project.html View File

@ -460,6 +460,7 @@
</div>
<div class="modal-body">
{% if project.team %}
<div class="form-group">
<label for="update-name-input" class="col-sm-4 control-label">
Choose owner
@ -476,6 +477,13 @@
</select>
</div>
</div>
{% else %}
<p>
This project currently has no team members.
To transfer the ownership of this project, please start by
inviting the new owner as a team member.
</p>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>


+ 2
- 0
templates/base.html View File

@ -159,6 +159,8 @@
{% endfor %}
<li role="separator" class="divider"></li>
<li class="dropdown-header">{{ request.user.email }}</li>
<li><a href="{% url 'hc-profile' %}">Account Settings</a></li>
<li><a href="{% url 'hc-logout' %}">Log Out</a></li>
</ul>


+ 19
- 0
templates/emails/transfer-request-body-html.html View File

@ -0,0 +1,19 @@
{% extends "emails/base.html" %}
{% load hc_extras %}
{% block content %}
Hello,
<br />
<strong>{{ project.owner.email }}</strong> would like to transfer the ownership of
their project
{% if project.name %}<strong>{{ project.name }}</strong>{% endif %} to you.
<br /><br />
To accept or reject this request, please visit the project's Settings
page:
{% endblock %}
{% block content_more %}
Thanks,<br>
The {% site_name %} Team
{% endblock %}

+ 14
- 0
templates/emails/transfer-request-body-text.html View File

@ -0,0 +1,14 @@
{% load hc_extras %}
{% block content %}Hello,
{{ project.owner.email }} would like to transfer the ownership of their
project {% if project.name %}"{{ project.name }}"{% endif %} to you.
To accept or reject this request, please visit the project's Settings
page:
{{ button_url }}
Thanks,
The {% site_name %} Team
{% endblock %}

+ 1
- 0
templates/emails/transfer-request-subject.html View File

@ -0,0 +1 @@
Ownership Transfer Request

Loading…
Cancel
Save