Skip to content
Snippets Groups Projects
Unverified Commit e13e6f41 authored by Fredrik Jonsson's avatar Fredrik Jonsson Committed by GitHub
Browse files

Merge pull request #757 from OpenTechFund/feature/slack-channel-fund-lab

Add slack channel field to Funds and Labs.
parents 9ba0495a 2c172da2
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,6 @@ jobs:
flake8 ./opentech
python manage.py collectstatic --noinput --verbosity=0
python manage.py check
python manage.py makemigrations --check --noinput --verbosity=0
python manage.py makemigrations --check --noinput --verbosity=1
coverage run --source='opentech' manage.py test
codecov
......@@ -225,19 +225,44 @@ class SlackAdapter(AdapterBase):
return f'<{user.slack}>'
return ''
def slack_channel(self, submission):
try:
target_room = submission.get_from_parent('slack_channel')
except AttributeError:
# If not a submission object, set room to default.
target_room = self.target_room
else:
if not target_room:
# If no custom room, set to default.
target_room = self.target_room
# Make sure the channel name starts with a "#".
if target_room and not target_room.startswith('#'):
target_room = f"#{target_room}"
return target_room
def send_message(self, message, recipient, **kwargs):
if not self.destination or not self.target_room:
try:
submission = kwargs['submission']
except Exception:
# If no submission, set room to default.
target_room = self.target_room
else:
target_room = self.slack_channel(submission)
if not self.destination or not target_room:
errors = list()
if not self.destination:
errors.append('Destination URL')
if not self.target_room:
if not target_room:
errors.append('Room ID')
return 'Missing configuration: {}'.format(', '.join(errors))
message = ' '.join([recipient, message]).strip()
data = {
"room": self.target_room,
"room": target_room,
"message": message,
}
response = requests.post(self.destination, json=data)
......
......@@ -225,7 +225,7 @@ class TestActivityAdapter(TestCase):
class TestSlackAdapter(AdapterMixin, TestCase):
target_url = 'https://my-slack-backend.com/incoming/my-very-secret-key'
target_room = '<ROOM ID>'
target_room = '#<ROOM ID>'
@override_settings(
SLACK_DESTINATION_URL=target_url,
......
# Generated by Django 2.0.9 on 2019-01-14 12:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('funds', '0047_add_markdown'),
]
operations = [
migrations.AddField(
model_name='applicationbase',
name='slack_channel',
field=models.CharField(blank=True, help_text='The slack #channel for notifications.', max_length=128),
),
migrations.AddField(
model_name='labbase',
name='slack_channel',
field=models.CharField(blank=True, help_text='The slack #channel for notifications.', max_length=128),
),
]
......@@ -7,6 +7,7 @@ from django.db.models import OuterRef, Q, Subquery
from django.http import Http404
from django.utils.functional import cached_property
from django.utils.text import mark_safe
from django.utils.translation import ugettext_lazy as _
from modelcluster.fields import ParentalManyToManyField
......@@ -48,6 +49,8 @@ class ApplicationBase(EmailForm, WorkflowStreamForm): # type: ignore
blank=True,
)
slack_channel = models.CharField(blank=True, max_length=128, help_text=_('The slack #channel for notifications.'))
objects = PageManager.from_queryset(ApplicationBaseManager)()
parent_page_types = ['apply_home.ApplyHomePage']
......@@ -82,6 +85,7 @@ class ApplicationBase(EmailForm, WorkflowStreamForm): # type: ignore
content_panels = WorkflowStreamForm.content_panels + [
FieldPanel('reviewers'),
FieldPanel('slack_channel'),
]
edit_handler = TabbedInterface([
......@@ -280,12 +284,15 @@ class LabBase(EmailForm, WorkflowStreamForm, SubmittableStreamForm): # type: ig
blank=True,
)
slack_channel = models.CharField(blank=True, max_length=128, help_text=_('The slack #channel for notifications.'))
parent_page_types = ['apply_home.ApplyHomePage']
subpage_types = [] # type: ignore
content_panels = WorkflowStreamForm.content_panels + [
FieldPanel('lead'),
FieldPanel('reviewers'),
FieldPanel('slack_channel'),
]
edit_handler = TabbedInterface([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment