From 9e051e71b7ec8090389c05c14b1a00a369571a29 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sun, 24 Feb 2019 19:34:59 +0100 Subject: [PATCH] Implement ticket.ref() Returning the ticket reference string ~user/tracker#scoped_id. --- tests/test_assignment.py | 8 ++++---- todosrht/emails/ticket_assigned | 2 +- todosrht/tickets.py | 16 +++------------- todosrht/types/ticket.py | 6 ++++++ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/tests/test_assignment.py b/tests/test_assignment.py index d76aa01..78ebd27 100644 --- a/tests/test_assignment.py +++ b/tests/test_assignment.py @@ -22,9 +22,9 @@ def test_assignment(mailbox): assert len(mailbox) == 1 assert mailbox[0].to == assignee1.email - assert mailbox[0].subject == "~foo/bar/#1: Hilfe!" + assert mailbox[0].subject == "~foo/bar#1: Hilfe!" assert mailbox[0].body.startswith( - "You were assigned to ~foo/bar/#1 by ~assigner") + "You were assigned to ~foo/bar#1 by ~assigner") # Assignment is idempotent assign(ticket, assignee1, assigner) @@ -37,9 +37,9 @@ def test_assignment(mailbox): assert len(mailbox) == 2 assert mailbox[1].to == assignee2.email - assert mailbox[1].subject == "~foo/bar/#1: Hilfe!" + assert mailbox[1].subject == "~foo/bar#1: Hilfe!" assert mailbox[1].body.startswith( - "You were assigned to ~foo/bar/#1 by ~assigner") + "You were assigned to ~foo/bar#1 by ~assigner") unassign(ticket, assignee1, assigner) db.session.commit() diff --git a/todosrht/emails/ticket_assigned b/todosrht/emails/ticket_assigned index fcffc84..a564b3e 100644 --- a/todosrht/emails/ticket_assigned +++ b/todosrht/emails/ticket_assigned @@ -1,5 +1,5 @@ {{! vim: set ft=email }} -You were assigned to {{ ticket_path }} by {{ assigner }}. +You were assigned to {{ ticket_ref }} by {{ assigner }}. -- diff --git a/todosrht/tickets.py b/todosrht/tickets.py index 2599bc7..449955f 100644 --- a/todosrht/tickets.py +++ b/todosrht/tickets.py @@ -69,12 +69,7 @@ def _create_event_notification(user, event): return notification def _send_comment_notification(subscription, ticket, user, comment, resolution): - subject = "Re: {}/{}/#{}: {}".format( - ticket.tracker.owner.canonical_name, - ticket.tracker.name, - ticket.scoped_id, - ticket.title) - + subject = "Re: {}: {}".format(ticket.ref(), ticket.title) headers = { "From": "~{} <{}>".format(user.username, notify_from), "Sender": smtp_user, @@ -180,12 +175,7 @@ def notify_assignee(subscription, ticket, assigner, assignee): """ Sends a notification email to the person who was assigned to the issue. """ - ticket_path = "{}/{}/#{}".format( - ticket.tracker.owner.canonical_name, - ticket.tracker.name, - ticket.scoped_id) - subject = "{}: {}".format(ticket_path, ticket.title) - + subject = "{}: {}".format(ticket.ref(), ticket.title) headers = { "From": "~{} <{}>".format(assigner.username, notify_from), "Sender": smtp_user, @@ -193,7 +183,7 @@ def notify_assignee(subscription, ticket, assigner, assignee): context = { "assigner": assigner.canonical_name, - "ticket_path": ticket_path, + "ticket_ref": ticket.ref(), "ticket_url": ticket_url(ticket) } diff --git a/todosrht/types/ticket.py b/todosrht/types/ticket.py index a19aa36..f8b8d12 100644 --- a/todosrht/types/ticket.py +++ b/todosrht/types/ticket.py @@ -61,3 +61,9 @@ class Ticket(Base): assigned_users = sa.orm.relationship("User", secondary="ticket_assignee", foreign_keys="[TicketAssignee.ticket_id,TicketAssignee.assignee_id]") + + def ref(self): + return "{}/{}#{}".format( + self.tracker.owner.canonical_name, + self.tracker.name, + self.scoped_id)