Skip to content

Commit

Permalink
Update open ticket modal to use note instead of body
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 7, 2024
1 parent 53a3a79 commit 9a726f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions temba/contacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,14 @@ def set_note(self, user, text):
notes = self.notes.order_by("-id").values_list("id", flat=True)[5:]
self.notes.filter(id__in=notes).delete()

def open_ticket(self, user, topic, body: str, assignee=None):
def open_ticket(self, user, *, topic, assignee, note: str):
"""
Opens a new ticket for this contact.
"""
mod = modifiers.Ticket(
topic=modifiers.TopicRef(uuid=str(topic.uuid), name=topic.name),
body=body or "",
assignee=modifiers.UserRef(email=assignee.email, name=assignee.name) if assignee else None,
note=note,
)
self.modify(user, [mod], refresh=False)
return self.tickets.order_by("id").last()
Expand Down
6 changes: 4 additions & 2 deletions temba/contacts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,10 +1751,12 @@ def test_block_and_stop(self, mr_mocks):
def test_open_ticket(self, mock_contact_modify):
mock_contact_modify.return_value = {self.joe.id: {"contact": {}, "events": []}}

ticket = self.joe.open_ticket(self.admin, self.org.default_ticket_topic, "Looks sus", assignee=self.agent)
ticket = self.joe.open_ticket(
self.admin, topic=self.org.default_ticket_topic, assignee=self.agent, note="Looks sus"
)

self.assertEqual(self.org.default_ticket_topic, ticket.topic)
self.assertEqual("Looks sus", ticket.body)
self.assertEqual("Looks sus", ticket.events.get(event_type="O").note)

@mock_mailroom
def test_interrupt(self, mr_mocks):
Expand Down
14 changes: 7 additions & 7 deletions temba/contacts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,18 +797,18 @@ class OpenTicket(ComponentFormMixin, ModalMixin, OrgObjPermsMixin, SmartUpdateVi

class Form(forms.Form):
topic = forms.ModelChoiceField(queryset=Topic.objects.none(), label=_("Topic"), required=True)
body = forms.CharField(
label=_("Body"),
widget=InputWidget(attrs={"textarea": True, "placeholder": _("Optional")}),
required=False,
)
assignee = forms.ModelChoiceField(
queryset=User.objects.none(),
label=_("Assignee"),
widget=SelectWidget(),
required=False,
empty_label=_("Unassigned"),
)
note = forms.CharField(
label=_("Note"),
widget=InputWidget(attrs={"textarea": True, "placeholder": _("Optional")}),
required=False,
)

def __init__(self, instance, org, **kwargs):
super().__init__(**kwargs)
Expand All @@ -827,9 +827,9 @@ def get_form_kwargs(self):
def save(self, obj):
self.ticket = obj.open_ticket(
self.request.user,
self.form.cleaned_data["topic"],
self.form.cleaned_data.get("body"),
topic=self.form.cleaned_data["topic"],
assignee=self.form.cleaned_data.get("assignee"),
note=self.form.cleaned_data.get("note"),
)

def get_success_url(self):
Expand Down
2 changes: 1 addition & 1 deletion temba/mailroom/modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class Groups(Modifier):
class Ticket(Modifier):
type: str = field(default="ticket", init=False)
topic: TopicRef
body: str
assignee: Optional[UserRef]
note: Optional[str]


@dataclass(frozen=True)
Expand Down
6 changes: 4 additions & 2 deletions temba/tests/mailroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,15 @@ def apply_modifiers(org, user, contacts, modifiers: list):
topic = org.topics.get(uuid=mod.topic.uuid, is_active=True)
assignee = org.users.get(email=mod.assignee.email, is_active=True) if mod.assignee else None
for contact in contacts:
contact.tickets.create(
ticket = contact.tickets.create(
org=org,
topic=topic,
status=Ticket.STATUS_OPEN,
body=mod.body,
assignee=assignee,
)
ticket.events.create(
org=org, contact=contact, event_type=TicketEvent.TYPE_OPENED, note=mod.note, created_by=user
)

elif mod.type == "urns":
assert len(contacts) == 1, "should never be trying to bulk update contact URNs"
Expand Down

0 comments on commit 9a726f1

Please sign in to comment.