Fixing unassignment notifications

remotes/origin/issue/4795/notification_even_they_are_disabled
Alejandro Alonso 2016-11-24 07:59:18 +01:00
parent c0daa9180f
commit 5449aac84d
2 changed files with 37 additions and 5 deletions

View File

@ -223,11 +223,9 @@ def send_notifications(obj, *, history):
# If the history is an unassignment change we should notify that user too
if history.type == HistoryType.change and "assigned_to" in history.diff:
if history.diff["assigned_to"][0] is not None:
notification.notify_users.add(history.diff["assigned_to"][0])
if history.diff["assigned_to"][1] is not None:
notification.notify_users.add(history.diff["assigned_to"][1])
for assigned_to in history.diff["assigned_to"]:
if assigned_to is not None and owner.id != assigned_to:
notification.notify_users.add(assigned_to)
# If we are the min interval is 0 it just work in a synchronous and spamming way
if settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL == 0:

View File

@ -762,6 +762,40 @@ def test_send_notifications_on_unassigned(client, mail):
assert mail.outbox[0].to == [member2.user.email]
def test_not_send_notifications_on_unassigned_if_executer_and_unassigned_match(client, mail):
project = f.ProjectFactory.create()
role = f.RoleFactory.create(project=project, permissions=['modify_issue', 'view_issues', 'view_us', 'view_tasks', 'view_wiki_pages'])
member1 = f.MembershipFactory.create(project=project, role=role)
member2 = f.MembershipFactory.create(project=project, role=role)
issue = f.IssueFactory.create(project=project,
owner=member1.user,
milestone=None,
status=project.default_issue_status,
severity=project.default_severity,
priority=project.default_priority,
type=project.default_issue_type)
take_snapshot(issue, user=issue.owner)
client.login(member1.user)
url = reverse("issues-detail", args=[issue.pk])
data = {
"assigned_to": member1.user.id,
"version": issue.version
}
response = client.json.patch(url, json.dumps(data))
assert len(mail.outbox) == 0
mail.outbox = []
data = {
"assigned_to": None,
"version": issue.version + 1
}
response = client.json.patch(url, json.dumps(data))
assert len(mail.outbox) == 0
def test_resource_notification_test(client, settings, mail):
settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL = 1