Skip to content

Commit

Permalink
Merge pull request #5446 from nyaruka/note_vs_body_pt4
Browse files Browse the repository at this point in the history
Drop `Ticket.body`
  • Loading branch information
rowanseymour authored Aug 8, 2024
2 parents ce8a7bb + b673952 commit e7c02f1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 39 deletions.
1 change: 0 additions & 1 deletion temba/mailroom/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def from_ticket_event(cls, org: Org, user: User, obj: TicketEvent) -> dict:
"closed_on": ticket.closed_on.isoformat() if ticket.closed_on else None,
"topic": _topic(ticket.topic) if ticket.topic else None,
"status": ticket.status,
"body": None,
},
"created_on": get_event_time(obj).isoformat(),
"created_by": _user(obj.created_by) if obj.created_by else None,
Expand Down
2 changes: 0 additions & 2 deletions temba/mailroom/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ def test_from_ticket_event(self):
"closed_on": None,
"status": "O",
"topic": {"uuid": str(self.org.default_ticket_topic.uuid), "name": "General"},
"body": None,
},
"created_on": matchers.ISODate(),
"created_by": {
Expand Down Expand Up @@ -559,7 +558,6 @@ def test_from_ticket_event(self):
"closed_on": None,
"status": "O",
"topic": {"uuid": str(self.org.default_ticket_topic.uuid), "name": "General"},
"body": None,
},
"created_on": matchers.ISODate(),
"created_by": None,
Expand Down
2 changes: 1 addition & 1 deletion temba/tickets/migrations/0062_move_body_to_open_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import migrations


def move_body_to_open_note(apps, schema_editor):
def move_body_to_open_note(apps, schema_editor): # pragma: no cover
Ticket = apps.get_model("tickets", "Ticket")

num_updated = 0
Expand Down
17 changes: 17 additions & 0 deletions temba/tickets/migrations/0063_remove_ticket_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.8 on 2024-08-08 19:21

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("tickets", "0062_move_body_to_open_note"),
]

operations = [
migrations.RemoveField(
model_name="ticket",
name="body",
),
]
3 changes: 0 additions & 3 deletions temba/tickets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ class Ticket(models.Model):
# when this ticket last had activity which includes messages being sent and received, and is used for ordering
last_activity_on = models.DateTimeField(default=timezone.now)

# deprecated
body = models.TextField(null=True)

def assign(self, user: User, *, assignee: User):
self.bulk_assign(self.org, user, [self], assignee=assignee)

Expand Down
32 changes: 1 addition & 31 deletions temba/tickets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from temba.contacts.models import Contact, ContactField, ContactURN
from temba.orgs.models import Export
from temba.tests import CRUDLTestMixin, MigrationTest, TembaTest, matchers, mock_mailroom
from temba.tests import CRUDLTestMixin, TembaTest, matchers, mock_mailroom
from temba.utils.dates import datetime_to_timestamp
from temba.utils.uuid import uuid4

Expand Down Expand Up @@ -38,7 +38,6 @@ def test_model(self, mr_mocks):
org=self.org,
contact=contact,
topic=self.org.default_ticket_topic,
body="Where are my cookies?",
status="O",
)

Expand Down Expand Up @@ -489,7 +488,6 @@ def assert_tickets(resp, tickets: list):
"uuid": str(contact2.tickets.filter(status="O").first().uuid),
"assignee": None,
"topic": {"uuid": matchers.UUID4String(), "name": "General"},
"body": None,
"last_activity_on": matchers.ISODate(),
"closed_on": None,
},
Expand All @@ -510,7 +508,6 @@ def assert_tickets(resp, tickets: list):
"uuid": str(joes_open_tickets[0].uuid),
"assignee": None,
"topic": {"uuid": matchers.UUID4String(), "name": "General"},
"body": None,
"last_activity_on": matchers.ISODate(),
"closed_on": None,
},
Expand All @@ -536,7 +533,6 @@ def assert_tickets(resp, tickets: list):
"email": "[email protected]",
},
"topic": {"uuid": matchers.UUID4String(), "name": "General"},
"body": None,
"last_activity_on": matchers.ISODate(),
"closed_on": None,
},
Expand Down Expand Up @@ -588,7 +584,6 @@ def assert_tickets(resp, tickets: list):
"uuid": str(c3_t2.uuid),
"assignee": None,
"topic": {"uuid": matchers.UUID4String(), "name": "General"},
"body": None,
"last_activity_on": matchers.ISODate(),
"closed_on": matchers.ISODate(),
},
Expand Down Expand Up @@ -1396,28 +1391,3 @@ def _record_last_close(self, org, d: date, seconds: int, undo: bool = False):
TicketDailyTiming.objects.create(
count_type=TicketDailyTiming.TYPE_LAST_CLOSE, scope=f"o:{org.id}", day=d, count=count, seconds=seconds
)


class MoveBodyToOpenNoteTest(MigrationTest):
app = "tickets"
migrate_from = "0061_alter_ticket_body_alter_ticketevent_note"
migrate_to = "0062_move_body_to_open_note"

def setUpBeforeMigration(self, apps):
contact = self.create_contact("Bob", urns=["twitter:bobby"])

self.ticket1 = self.create_ticket(contact)
self.ticket2 = self.create_ticket(contact)
self.ticket2.body = "I was a body"
self.ticket2.save(update_fields=("body",))

def test_migration(self):
self.ticket1.refresh_from_db()
self.ticket2.refresh_from_db()

# body unchanged
self.assertIsNone(self.ticket1.body)
self.assertEqual("I was a body", self.ticket2.body)

self.assertEqual(None, self.ticket1.events.get(event_type="O").note)
self.assertEqual("I was a body", self.ticket2.events.get(event_type="O").note)
1 change: 0 additions & 1 deletion temba/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ def as_json(t):
"uuid": str(t.uuid),
"assignee": user_as_json(t.assignee) if t.assignee else None,
"topic": topic_as_json(t.topic) if t.topic else None,
"body": t.body,
"last_activity_on": t.last_activity_on,
"closed_on": t.closed_on,
},
Expand Down

0 comments on commit e7c02f1

Please sign in to comment.