From 61cd2ae4f13bec217aca6b08b96bcecfd59ce0a5 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 26 Jul 2018 14:39:46 +0100
Subject: [PATCH] Add comment messaging

---
 opentech/apply/activity/messaging.py | 8 +++++---
 opentech/apply/activity/views.py     | 8 +++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py
index 10e1ab4c6..22fc27ed7 100644
--- a/opentech/apply/activity/messaging.py
+++ b/opentech/apply/activity/messaging.py
@@ -85,17 +85,19 @@ class ActivityAdapter(AdapterBase):
 class SlackAdapter(AdapterBase):
     adapter_type = "Slack"
     messages = {
-        MESSAGES.UPDATE_LEAD: 'has updated the lead of "{submission.title}" to {submission.lead}'
+        MESSAGES.UPDATE_LEAD: 'The lead of "{submission.title}" has been updated form { old.lead } to {submission.lead} by {user}',
+        MESSAGES.COMMENT: 'A new comment has been posted on "{submission.title}"',
     }
 
     def __init__(self):
         super().__init__()
         self.destination = settings.SLACK_DESTINATION
 
-    def message(self, message_type, **kwargs):
+    def message(self, message_type,  **kwargs):
         message = super().message(message_type, **kwargs)
         user = kwargs['user']
-        message = ' '.join([self.slack_id(user), message])
+        submission = kwargs['submission']
+        message = ' '.join([self.slack_id(submission.lead), message])
         return message
 
     def slack_id(self, user):
diff --git a/opentech/apply/activity/views.py b/opentech/apply/activity/views.py
index fb9f59bc1..68a8cefad 100644
--- a/opentech/apply/activity/views.py
+++ b/opentech/apply/activity/views.py
@@ -38,13 +38,15 @@ class CommentFormView(DelegatedViewMixin, CreateView):
         form.instance.user = self.request.user
         form.instance.submission = self.kwargs['submission']
         form.instance.type = COMMENT
+        response = super().form_valid(form)
         messenger(
             MESSAGES.COMMENT,
+            request=self.request,
             user=self.request.user,
-            submission=self.submission,
-            comment=form.instance,
+            submission=self.object.submission,
+            comment=self.object,
         )
-        return super().form_valid(form)
+        return response
 
     def get_success_url(self):
         return self.object.submission.get_absolute_url() + '#communications'
-- 
GitLab