diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index a97203f8f0d570896aa0c26f9f99090fc413fe78..bf30c67dca20ed639725e22959b5d7355370064e 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 5a0cac06a8eeec6b8e78209aaa56dab7960c6208..c4da25f92ef4553be9dbb4358242a49b94d39b46 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 f240447bd3b482d1871a9a3b816e0af029cd1606..131e636384ec8591fa81ad050380abb9a9629fd7 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: