-
Notifications
You must be signed in to change notification settings - Fork 7
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
Async team deletion with email #1169
base: main
Are you sure you want to change the base?
Changes from all commits
0d03ab5
0bcb60e
bd393c4
b90ebe8
d8e8ff3
7642fab
78cc311
8628d2b
a5534a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
from celery import shared_task | ||
|
||
from apps.teams.invitations import send_invitation_accepted | ||
from apps.teams.models import Invitation | ||
from apps.teams.models import Invitation, Team | ||
from apps.utils.deletion import ( | ||
delete_object_with_auditing_of_related_objects, | ||
get_admin_emails_with_delete_permission, | ||
send_team_deleted_notification, | ||
) | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def send_invitation_accepted_notification(invitation_id): | ||
invitation = Invitation.objects.get(id=invitation_id) | ||
send_invitation_accepted(invitation) | ||
|
||
|
||
@shared_task | ||
def delete_team_async(team_id): | ||
team = Team.objects.get(id=team_id) | ||
|
||
# get required info for emails prior to deleting team info | ||
team_name = team.name | ||
admin_emails = get_admin_emails_with_delete_permission(team) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all users maybe be notified instead of only those that can delete the team? It might be a bit surprising for someone to find their team is gone. Probably an edge case, but still |
||
delete_object_with_auditing_of_related_objects(team) | ||
send_team_deleted_notification(team_name, admin_emails) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
from apps.teams.invitations import get_admin_emails | ||
from apps.teams.utils import set_current_team | ||
from apps.users.models import CustomUser | ||
from apps.utils.deletion import get_admin_emails_with_delete_permission | ||
from apps.utils.factories.team import MembershipFactory | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_get_admin_emails(team_with_users): | ||
def test_get_admin_emails_can_view_invite(team_with_users): | ||
set_current_team(team_with_users) | ||
|
||
MembershipFactory(team=team_with_users, groups=lambda: list(Group.objects.filter(name=TEAM_ADMIN_GROUP))) | ||
|
@@ -21,3 +22,18 @@ def test_get_admin_emails(team_with_users): | |
} | ||
emails = get_admin_emails(team_with_users) | ||
assert set(emails) == expected | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_get_admin_emails_can_delete_team(team_with_users): | ||
set_current_team(team_with_users) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could use the |
||
|
||
MembershipFactory(team=team_with_users, groups=lambda: list(Group.objects.filter(name=TEAM_ADMIN_GROUP))) | ||
|
||
expected = { | ||
user.email | ||
for user in CustomUser.objects.filter(membership__team=team_with_users).all() | ||
if user.has_perm("teams.delete_team") | ||
} | ||
emails = get_admin_emails_with_delete_permission(team_with_users) | ||
assert set(emails) == expected |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,6 +546,7 @@ | |
"account_reset_password_from_key", | ||
"teams:signup_after_invite", | ||
"account_login", | ||
"single_team:delete_team", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #1169 (comment) |
||
] | ||
FIELD_AUDIT_REQUEST_ID_HEADERS = [ | ||
"X-Request-ID", # Heroku | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p> | ||
Team '{{ team_name }}' has been successfully deleted. | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Team '{{ team_name }}' has been successfully deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
with current_team(team)
to set the team for auditing