From 30bdd176d1077b69dc80452d2ea30895b53359f3 Mon Sep 17 00:00:00 2001 From: Kenneth Hansen Date: Wed, 9 Sep 2020 21:32:57 +0200 Subject: [PATCH] Log interactions with single mails and the queue --- src/mail/viewsets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mail/viewsets.py b/src/mail/viewsets.py index a0dd8144..63fc1d87 100644 --- a/src/mail/viewsets.py +++ b/src/mail/viewsets.py @@ -11,6 +11,7 @@ from pymailq.store import PostqueueStore from django.conf import settings from core.models import Setting, MailScannerHost +from compliance.models import DataLogEntry import datetime from django.db.models import Q import subprocess @@ -163,6 +164,7 @@ def get_message_mailscanner_report(self, request, pk=None): @action(methods=['get'], detail=False, permission_classes=[IsAdminUser], url_path='queue', url_name='message-queue') def get_queue(self, request): + DataLogEntry.objects.log_create(None, changes='User {} requested to view the mail queue'.format(request.user.email)) host_count = MailScannerHost.objects.count() store = PostqueueStore() store.load() @@ -218,7 +220,7 @@ def post_resend(self, request): if message['hostname'] == settings.APP_HOSTNAME: command = "{} -i {}".format(settings.POSTQUEUE_BIN, message['qid']) output = subprocess.check_output(command, shell=True) - message.released = True + DataLogEntry.objects.log_create(message, changes='Message {} was resent from the queue'.format(message.id)) message.save() response.append({ 'qid':message['qid'], 'command': command, 'output': output }) elif host_count > 0 and not settings.API_ONLY: @@ -306,6 +308,7 @@ def post_action_spam(self, request): if settings.APP_HOSTNAME == message.mailscanner_hostname: command = "{0} -p {1} -r {2}".format(settings.SA_BIN, settings.MAILSCANNER_CONFIG_DIR + '/spamassassin.conf', message.file_path()) output = subprocess.check_output(command, shell=True) + DataLogEntry.objects.log_create(message, action='updated', changes='Message was marked as spam') response.append({ 'id':message_id, 'command': command, 'output': output }) elif not settings.API_ONLY: token = Token.objects.get(user=request.user) @@ -344,6 +347,7 @@ def post_action_nonspam(self, request): if settings.APP_HOSTNAME == message.mailscanner_hostname: command = "{0} -p {1} -k {2}".format(settings.SA_BIN, settings.MAILSCANNER_CONFIG_DIR + '/spamassassin.conf', message.file_path()) output = subprocess.check_output(command, shell=True) + DataLogEntry.objects.log_create(message, action='updated', changes='Message was marked as not being spam') response.append({ 'id':message_id, 'command': command, 'output': output }) elif not settings.API_ONLY: token = Token.objects.get(user=request.user)