Compare commits
No commits in common. "5a1cfedd56e3ec3cf114cfdbd543ac7f994b8cb8" and "4664d6255d84caf68feea01ef03cd7dcdb3f42bf" have entirely different histories.
5a1cfedd56
...
4664d6255d
6 changed files with 18 additions and 100 deletions
|
@ -174,6 +174,7 @@ def receive_email(envelope, log=None):
|
|||
|
||||
active_issue_thread, new = find_active_issue_thread(header_in_reply_to, subject)
|
||||
|
||||
|
||||
email = Email.objects.create(
|
||||
sender=sender, recipient=recipient, body=body, subject=subject, reference=header_message_id,
|
||||
in_reply_to=header_in_reply_to, raw=envelope.content.decode('utf-8'), event=target_event,
|
||||
|
@ -187,19 +188,8 @@ def receive_email(envelope, log=None):
|
|||
# auto reply if new issue
|
||||
references = collect_references(active_issue_thread)
|
||||
if not sender.startswith('noreply'):
|
||||
subject = f"Re: {subject} [#{active_issue_thread.short_uuid()}]"
|
||||
body = '''Your request (#{}) has been received and will be reviewed by our lost&found angels.
|
||||
|
||||
We are reviewing incoming requests during the event and teardown. Immediately after the event, expect a delay as the \
|
||||
workload is high. We will not forget about your request and get back in touch once we have updated information on your \
|
||||
request. Requests for devices, wallets, credit cards or similar items will be handled with priority.
|
||||
|
||||
If you happen to find your lost item or just want to add additional information, please reply to this email. Please \
|
||||
do not create a new request.
|
||||
|
||||
Your c3lf (Cloakroom + Lost&Found) Team'''.format(active_issue_thread.short_uuid())
|
||||
reply_email = Email.objects.create(
|
||||
sender=recipient, recipient=sender, body=body, subject=subject,
|
||||
sender=recipient, recipient=sender, body="Thank you for your message.", subject="Message received",
|
||||
in_reply_to=header_message_id, event=target_event, issue_thread=active_issue_thread)
|
||||
reply = make_reply(reply_email, references)
|
||||
else:
|
||||
|
|
|
@ -12,19 +12,6 @@ from mail.models import Email, EventAddress, EmailAttachment
|
|||
from mail.protocol import LMTPHandler
|
||||
from tickets.models import IssueThread, StateChange
|
||||
|
||||
expected_auto_reply_subject = 'Re: {} [#{}]'
|
||||
|
||||
expected_auto_reply = '''Your request (#{}) has been received and will be reviewed by our lost&found angels.
|
||||
|
||||
We are reviewing incoming requests during the event and teardown. Immediately after the event, expect a delay as the \
|
||||
workload is high. We will not forget about your request and get back in touch once we have updated information on your \
|
||||
request. Requests for devices, wallets, credit cards or similar items will be handled with priority.
|
||||
|
||||
If you happen to find your lost item or just want to add additional information, please reply to this email. Please \
|
||||
do not create a new request.
|
||||
|
||||
Your c3lf (Cloakroom + Lost&Found) Team'''
|
||||
|
||||
|
||||
def make_mocked_coro(return_value=mock.sentinel, raise_exception=mock.sentinel):
|
||||
async def mock_coro(*args, **kwargs):
|
||||
|
@ -106,12 +93,10 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||
self.assertEqual(expected_auto_reply_subject.format('test', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test2@test', Email.objects.all()[1].sender)
|
||||
self.assertEqual('test1@test', Email.objects.all()[1].recipient)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
|
||||
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
|
||||
|
@ -347,15 +332,13 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test
|
|||
self.assertEqual(event, Email.objects.all()[0].event)
|
||||
self.assertEqual(event, Email.objects.all()[1].event)
|
||||
self.assertEqual('test', Email.objects.all()[0].subject)
|
||||
self.assertEqual(expected_auto_reply_subject.format('test', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test1@test', Email.objects.all()[0].sender)
|
||||
self.assertEqual('test_event@localhost', Email.objects.all()[0].recipient)
|
||||
self.assertEqual('test_event@localhost', Email.objects.all()[1].sender)
|
||||
self.assertEqual('test1@test', Email.objects.all()[1].recipient)
|
||||
self.assertEqual('test', Email.objects.all()[0].body)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
|
@ -421,12 +404,10 @@ test2
|
|||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||
self.assertEqual(expected_auto_reply_subject.format('test', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test2@test', Email.objects.all()[1].sender)
|
||||
self.assertEqual('test1@test', Email.objects.all()[1].recipient)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
|
||||
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
|
||||
|
@ -489,12 +470,10 @@ dGVzdGltYWdl
|
|||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||
self.assertEqual(expected_auto_reply_subject.format('test', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test2@test', Email.objects.all()[1].sender)
|
||||
self.assertEqual('test1@test', Email.objects.all()[1].recipient)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
|
||||
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
|
||||
|
@ -570,12 +549,10 @@ dGVzdGltYWdl
|
|||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||
self.assertEqual(expected_auto_reply_subject.format('No subject', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test2@test', Email.objects.all()[1].sender)
|
||||
self.assertEqual('test1@test', Email.objects.all()[1].recipient)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
|
||||
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
|
||||
|
@ -614,12 +591,10 @@ dGVzdGltYWdl
|
|||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[0].issue_thread)
|
||||
self.assertEqual('<1@test>', Email.objects.all()[0].reference)
|
||||
self.assertEqual(None, Email.objects.all()[0].in_reply_to)
|
||||
self.assertEqual(expected_auto_reply_subject.format('test', IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].subject)
|
||||
self.assertEqual('Message received', Email.objects.all()[1].subject)
|
||||
self.assertEqual('test2@test', Email.objects.all()[1].sender)
|
||||
self.assertEqual('<test1@test>', Email.objects.all()[1].recipient)
|
||||
self.assertEqual(expected_auto_reply.format(IssueThread.objects.all()[0].short_uuid()),
|
||||
Email.objects.all()[1].body)
|
||||
self.assertEqual('Thank you for your message.', Email.objects.all()[1].body)
|
||||
self.assertEqual(IssueThread.objects.all()[0], Email.objects.all()[1].issue_thread)
|
||||
self.assertTrue(Email.objects.all()[1].reference.startswith("<"))
|
||||
self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>"))
|
||||
|
|
|
@ -22,8 +22,8 @@ class IssueSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = IssueThread
|
||||
fields = ('id', 'timeline', 'name', 'state', 'assigned_to', 'last_activity', 'uuid')
|
||||
read_only_fields = ('id', 'timeline', 'last_activity', 'uuid')
|
||||
fields = ('id', 'timeline', 'name', 'state', 'assigned_to', 'last_activity')
|
||||
read_only_fields = ('id', 'timeline', 'last_activity')
|
||||
|
||||
def to_internal_value(self, data):
|
||||
ret = super().to_internal_value(data)
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2024-01-12 21:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
from tickets.models import IssueThread
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tickets', '0005_remove_issuethread_last_activity'),
|
||||
]
|
||||
|
||||
def set_uuid(apps, schema_editor):
|
||||
import uuid
|
||||
for issue_thread in IssueThread.objects.all():
|
||||
issue_thread.uuid = str(uuid.uuid4())
|
||||
issue_thread.save()
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='issuethread',
|
||||
name='uuid',
|
||||
field=models.CharField(max_length=255, null=True),
|
||||
),
|
||||
migrations.RunPython(set_uuid),
|
||||
migrations.AlterField(
|
||||
model_name='issuethread',
|
||||
name='uuid',
|
||||
field=models.CharField(max_length=255, unique=True, null=False, blank=False),
|
||||
),
|
||||
]
|
|
@ -2,7 +2,7 @@ from django.db import models
|
|||
from django_softdelete.models import SoftDeleteModel
|
||||
|
||||
from inventory.models import Event
|
||||
from django.db.models.signals import post_save, pre_save
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
STATE_CHOICES = (
|
||||
|
@ -25,14 +25,10 @@ STATE_CHOICES = (
|
|||
|
||||
class IssueThread(SoftDeleteModel):
|
||||
id = models.AutoField(primary_key=True)
|
||||
uuid = models.CharField(max_length=255, unique=True, null=False, blank=False)
|
||||
name = models.CharField(max_length=255)
|
||||
assigned_to = models.CharField(max_length=255, null=True)
|
||||
manually_created = models.BooleanField(default=False)
|
||||
|
||||
def short_uuid(self):
|
||||
return self.uuid[:8]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
try:
|
||||
|
@ -53,13 +49,6 @@ class IssueThread(SoftDeleteModel):
|
|||
]
|
||||
|
||||
|
||||
@receiver(pre_save, sender=IssueThread)
|
||||
def set_uuid(sender, instance, **kwargs):
|
||||
import uuid
|
||||
if instance.uuid is None or instance.uuid == '':
|
||||
instance.uuid = str(uuid.uuid4())
|
||||
|
||||
|
||||
@receiver(post_save, sender=IssueThread)
|
||||
def create_issue_thread(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
|
|
|
@ -51,10 +51,7 @@ class IssueApiTest(TestCase):
|
|||
comment="test",
|
||||
timestamp=now + timedelta(seconds=3),
|
||||
)
|
||||
self.assertEqual('pending_new', issue.state)
|
||||
self.assertEqual('test issue', issue.name)
|
||||
self.assertEqual(None, issue.assigned_to)
|
||||
self.assertEqual(36, len(issue.uuid))
|
||||
|
||||
response = self.client.get('/api/2/tickets/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.json()), 1)
|
||||
|
@ -62,7 +59,6 @@ class IssueApiTest(TestCase):
|
|||
self.assertEqual(response.json()[0]['name'], "test issue")
|
||||
self.assertEqual(response.json()[0]['state'], "pending_new")
|
||||
self.assertEqual(response.json()[0]['assigned_to'], None)
|
||||
self.assertEqual(response.json()[0]['uuid'], issue.uuid)
|
||||
self.assertEqual(response.json()[0]['last_activity'], comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
||||
self.assertEqual(len(response.json()[0]['timeline']), 4)
|
||||
self.assertEqual(response.json()[0]['timeline'][0]['type'], 'state')
|
||||
|
|
Loading…
Reference in a new issue