Skip to content

Commit

Permalink
Merge pull request #5441 from nyaruka/note_vs_body
Browse files Browse the repository at this point in the history
Update open ticket modal to use note instead of body
  • Loading branch information
rowanseymour authored Aug 8, 2024
2 parents ea3121a + 19fc954 commit 2e44057
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"dependencies": {
"@nyaruka/flow-editor": "1.35.0",
"@nyaruka/flow-editor": "1.35.1",
"@nyaruka/temba-components": "0.104.0",
"codemirror": "5.18.2",
"colorette": "1.2.2",
Expand Down
2 changes: 0 additions & 2 deletions temba/api/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,6 @@ class TicketsEndpoint(ListAPIMixin, BaseEndpoint):
* **status** - the status of the ticket, either `open` or `closed`.
* **topic** - the topic of the ticket (object).
* **assignee** - the user assigned to the ticket (object).
* **body** - the body of the ticket (string).
* **opened_on** - when this ticket was opened (datetime).
* **opened_by** - the user who opened the ticket (object).
* **opened_in** - the flow which opened the ticket (object).
Expand All @@ -3298,7 +3297,6 @@ class TicketsEndpoint(ListAPIMixin, BaseEndpoint):
"status": "open",
"topic": {"uuid": "040edbfe-be55-48f3-864d-a4a7147c447b", "name": "Support"},
"assignee": {"email": "[email protected]", "name": "Bob McFlow"},
"body": "Where did I leave my shorts?",
"opened_on": "2013-02-27T09:06:15.456",
"opened_by": null,
"opened_in": {"uuid": "54cd8e2c-6334-49a4-abf9-f0fa8d0971da", "name": "Support Flow"},
Expand Down
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
9 changes: 5 additions & 4 deletions temba/contacts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,14 @@ def test_open_ticket(self, mr_mocks):
open_url = reverse("contacts.contact_open_ticket", args=[contact.id])

self.assertRequestDisallowed(open_url, [None, self.user, self.agent, self.admin2])
self.assertUpdateFetch(open_url, [self.editor, self.admin], form_fields=("topic", "body", "assignee"))
self.assertUpdateFetch(open_url, [self.editor, self.admin], form_fields=("topic", "assignee", "note"))

# can submit with no assignee
response = self.assertUpdateSubmit(open_url, self.admin, {"topic": general.id, "body": "Help", "assignee": ""})

# should have new ticket
ticket = contact.tickets.get()
self.assertEqual(general, ticket.topic)
self.assertEqual("Help", ticket.body)
self.assertIsNone(ticket.assignee)

# and we're redirected to that ticket
Expand Down Expand Up @@ -1751,10 +1750,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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@nyaruka/[email protected].0":
version "1.35.0"
resolved "https://registry.yarnpkg.com/@nyaruka/flow-editor/-/flow-editor-1.35.0.tgz#1a0d23e2eca6520a7eefbe7f4a4aa7d82d52adcf"
integrity sha512-u79UdFnXhXk0Bq3yKix/3AnQJij9mw4v4nyKIOxCk2vdTDRvI8Wiv57dwJhoSUBh4E+gzA/SEILaVKzLDhsp1g==
"@nyaruka/[email protected].1":
version "1.35.1"
resolved "https://registry.yarnpkg.com/@nyaruka/flow-editor/-/flow-editor-1.35.1.tgz#1a443252a2c974e2afe231f626cd998c4d558114"
integrity sha512-0DIgyiTt30wqfCPrZB9v5mIki+uhfCe9prL0hfhXaX1nUclUqQ+9Xl4PMTnQJTMnv+jLFGNir9t3k5EC63PyHQ==
dependencies:
"@nyaruka/temba-components" "0.101.0"
react "^16.8.6"
Expand Down

0 comments on commit 2e44057

Please sign in to comment.