From c725456f7f3beec453150a845bda67cccf52d261 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Wed, 12 Feb 2020 11:24:52 +0100 Subject: [PATCH] Add SLACK_DESTINATION_ROOM_COMMENTS setting allowing comments notifications to go to seperate Slack room. --- opentech/apply/activity/messaging.py | 12 ++++++++++-- opentech/settings/base.py | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index 3c07ee7c9..d33402150 100644 --- a/opentech/apply/activity/messaging.py +++ b/opentech/apply/activity/messaging.py @@ -429,6 +429,7 @@ class SlackAdapter(AdapterBase): super().__init__() self.destination = settings.SLACK_DESTINATION_URL self.target_room = settings.SLACK_DESTINATION_ROOM + self.comments_room = settings.SLACK_DESTINATION_ROOM_COMMENTS def slack_links(self, links, sources): return ', '.join( @@ -591,7 +592,7 @@ class SlackAdapter(AdapterBase): return f'<{user.slack}>' - def slack_channels(self, source): + def slack_channels(self, source, **kwargs): target_rooms = [self.target_room] try: extra_rooms = source.get_from_parent('slack_channel').split(',') @@ -601,6 +602,13 @@ class SlackAdapter(AdapterBase): else: target_rooms.extend(extra_rooms) + try: + if self.comments_room and kwargs['comment']: + target_rooms.extend([self.comments_room]) + except KeyError: + # Not a comment. + pass + # Make sure each channel name starts with a "#". target_rooms = [ room if room.startswith('#') else '#' + room @@ -611,7 +619,7 @@ class SlackAdapter(AdapterBase): return target_rooms def send_message(self, message, recipient, source, **kwargs): - target_rooms = self.slack_channels(source) + target_rooms = self.slack_channels(source, **kwargs) if not self.destination or not any(target_rooms): errors = list() diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 0aebe1efc..3e8e7c85f 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -505,6 +505,7 @@ if not SEND_MESSAGES: SLACK_DESTINATION_URL = env.get('SLACK_DESTINATION_URL', None) SLACK_DESTINATION_ROOM = env.get('SLACK_DESTINATION_ROOM', None) +SLACK_DESTINATION_ROOM_COMMENTS = env.get('SLACK_DESTINATION_ROOM_COMMENTS', None) # Celery config -- GitLab