From 470541d239f11514354df4602d6bd8d2dd40d41d Mon Sep 17 00:00:00 2001 From: jedi Date: Wed, 6 Dec 2023 05:06:26 +0100 Subject: [PATCH] stash --- core/mail/protocol.py | 9 +++++---- core/mail/tests/v2/test_mails.py | 12 ++++++++++-- core/tickets/tests/v2/test_tickets.py | 10 ++++++---- web/src/App.vue | 9 ++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/core/mail/protocol.py b/core/mail/protocol.py index d7dbaf9..39a4c63 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -46,12 +46,12 @@ async def send_smtp(message, log): await aiosmtplib.send(message, hostname="127.0.0.1", port=25, use_tls=False, start_tls=False) -def find_active_issue_thread(in_reply_to): +def find_active_issue_thread(in_reply_to, subject=None): reply_to = Email.objects.filter(reference=in_reply_to) if reply_to.exists(): return reply_to.first().issue_thread else: - return IssueThread.objects.create() + return IssueThread.objects.create(name=subject) class LMTPHandler: @@ -102,6 +102,7 @@ class LMTPHandler: recipient = envelope.rcpt_tos[0] sender = envelope.mail_from + subject = parsed.get('Subject') target_event = None try: address_map = await sync_to_async(EventAddress.objects.get)(address=recipient) @@ -110,12 +111,12 @@ class LMTPHandler: except EventAddress.DoesNotExist: pass - active_issue_thread = await sync_to_async(find_active_issue_thread)(header_in_reply_to) + active_issue_thread = await sync_to_async(find_active_issue_thread)(header_in_reply_to, subject) email = await sync_to_async(Email.objects.create)(sender=sender, recipient=recipient, body=body.decode('utf-8'), - subject=parsed.get('Subject'), + subject=subject, reference=header_message_id, in_reply_to=header_in_reply_to, raw=envelope.content.decode('utf-8'), diff --git a/core/mail/tests/v2/test_mails.py b/core/mail/tests/v2/test_mails.py index c02067d..0afd799 100644 --- a/core/mail/tests/v2/test_mails.py +++ b/core/mail/tests/v2/test_mails.py @@ -83,11 +83,16 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test self.assertTrue(Email.objects.all()[1].reference.startswith("<")) self.assertTrue(Email.objects.all()[1].reference.endswith("@localhost>")) self.assertEqual(Email.objects.all()[1].in_reply_to, "<1@test>") + self.assertEqual(IssueThread.objects.all()[0].name, 'test') + self.assertEqual(IssueThread.objects.all()[0].state, 'new') + self.assertEqual(IssueThread.objects.all()[0].assigned_to, None) def test_handle_client_reply(self): - issue_thread = IssueThread.objects.create() + issue_thread = IssueThread.objects.create( + name="test", + ) mail1 = Email.objects.create( - subject='test', + subject='test subject', body='test', sender='test1@test', recipient='test2@test', @@ -134,6 +139,9 @@ class LMTPHandlerTestCase(TestCase): # TODO replace with less hacky test self.assertTrue(Email.objects.all()[3].reference.startswith("<")) self.assertTrue(Email.objects.all()[3].reference.endswith("@localhost>")) self.assertEqual(Email.objects.all()[3].in_reply_to, "<3@test>") + self.assertEqual(IssueThread.objects.all()[0].name, 'test') + self.assertEqual(IssueThread.objects.all()[0].state, 'new') + self.assertEqual(IssueThread.objects.all()[0].assigned_to, None) # class AsyncLMTPTestCase(TestCase): # diff --git a/core/tickets/tests/v2/test_tickets.py b/core/tickets/tests/v2/test_tickets.py index 52a6384..963119a 100644 --- a/core/tickets/tests/v2/test_tickets.py +++ b/core/tickets/tests/v2/test_tickets.py @@ -17,7 +17,9 @@ class IssueApiTest(TestCase): def test_issues(self): now = datetime.now() - issue = IssueThread.objects.create() + issue = IssueThread.objects.create( + name="test issue", + ) mail1 = Email.objects.create( subject='test', body='test', @@ -50,9 +52,9 @@ class IssueApiTest(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(len(response.json()), 1) self.assertEqual(response.json()[0]['id'], issue.id) - self.assertEqual(response.json()[0]['name'], issue.name) - self.assertEqual(response.json()[0]['state'], issue.state) - self.assertEqual(response.json()[0]['assigned_to'], issue.assigned_to) + self.assertEqual(response.json()[0]['name'], "test issue") + self.assertEqual(response.json()[0]['state'], "new") + self.assertEqual(response.json()[0]['assigned_to'], None) self.assertEqual(response.json()[0]['last_activity'], issue.last_activity.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) self.assertEqual(len(response.json()[0]['timeline']), 4) self.assertEqual(response.json()[0]['timeline'][0]['type'], 'mail') diff --git a/web/src/App.vue b/web/src/App.vue index 81273aa..bedb68c 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -17,7 +17,7 @@ import Navbar from '@/components/Navbar'; import AddItemModal from '@/components/AddItemModal'; import Toast from './components/Toast'; -import {mapState, mapMutations} from 'vuex'; +import {mapState, mapMutations, mapActions} from 'vuex'; export default { name: 'app', @@ -30,6 +30,7 @@ export default { }), methods: { ...mapMutations(['removeToast', 'createToast']), + ...mapActions(['loadItems', 'loadTickets']), openAddModal() { this.addModalOpen = true; }, @@ -90,14 +91,16 @@ export default { }; this.notify_socket.onmessage = (e) => { let data = JSON.parse(e.data); - console.log(data); + //this.loadItems() + this.loadTickets() + } } }, }, created: function () { - //this.tryConnect(); + this.tryConnect(); } };