From c5dd8cecd8413b50f5b23da6108abf73b9cafc33 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Fri, 27 Jul 2018 10:16:39 +0100 Subject: [PATCH] Make sure we can configure the room and URL in production --- opentech/apply/activity/messaging.py | 7 ++++--- opentech/settings/base.py | 7 +++++-- opentech/settings/production.py | 5 ----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index a97203f8f..bf30c67dc 100644 --- a/opentech/apply/activity/messaging.py +++ b/opentech/apply/activity/messaging.py @@ -106,7 +106,8 @@ class SlackAdapter(AdapterBase): def __init__(self): super().__init__() - self.destination = settings.SLACK_DESTINATION + self.destination = settings.SLACK_DESTINATION_URL + self.target_room = settings.SLACK_DESTINATION_ROOM def message(self, message_type, **kwargs): user = kwargs['user'] @@ -128,11 +129,11 @@ class SlackAdapter(AdapterBase): return f'<{user.slack}>' def send_message(self, message, **kwargs): - if not self.destination: + if not self.destination and not self.target_room: return data = { - "room": "CBQUCH458", + "room": self.target_room, "message": message, } requests.post(self.destination, data=data) diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 5a0cac06a..c4da25f92 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -5,6 +5,8 @@ Django settings for opentech project. # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +env = os.environ.copy() + PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) @@ -351,5 +353,6 @@ HIJACK_DECORATOR = 'opentech.apply.users.decorators.superuser_decorator' # Messaging Settings -SEND_MESSAGES = False -SLACK_DESTINATION = None +SEND_MESSAGES = env.get('SEND_MESSAGES', 'false').lower() == 'true' +SLACK_DESTINATION_URL = env.get('SLACK_DESTINATION_URL', None) +SLACK_DESTINATION_ROOM = env.get('SLACK_DESTINATION_ROOM', None) diff --git a/opentech/settings/production.py b/opentech/settings/production.py index f240447bd..131e63638 100644 --- a/opentech/settings/production.py +++ b/opentech/settings/production.py @@ -144,11 +144,6 @@ if 'LOG_DIR' in env: LOGGING['loggers']['django.security']['handlers'].append('errors_file') -# Messaging Settings -SEND_MESSAGES = env.get('SEND_MESSAGES', 'false').lower() == 'true' -SLACK_DESTINATION = env.get('SLACK_DESTINATION', None) - - try: from .local import * # noqa except ImportError: -- GitLab