stash
This commit is contained in:
parent
76dd805262
commit
470541d239
4 changed files with 27 additions and 13 deletions
|
@ -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'),
|
||||
|
|
|
@ -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):
|
||||
#
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue