Commit d900316b authored by Zac Wood's avatar Zac Wood

Merge branch 'slackbot' into 'v2.3'

Send slack messages on /newLink

See merge request !139
parents bb7b3254 04fe20c7
Pipeline #5145 passed with stages
in 2 minutes and 2 seconds
......@@ -14,4 +14,5 @@ GO_EMAIL_HOST_PASSWORD=
GO_EMAIL_FROM=
GO_EMAIL_TO=
GO_SECRET_KEY=spookyspecret
GO_SLACK_URL=
superuser=zwood2
import requests
from django.conf import settings
from threading import Thread
def build_msg(request):
target = request.POST['target']
short = f'go.gmu.edu/{request.POST["short"]}'
return f'Short: {short}\nTarget: {target}'
def send_slack_message(msg):
# Send slack message
slack_url = settings.SLACK_URL
Thread(target=requests.post, args=(slack_url,), kwargs={ 'json': { 'text': msg }}).start()
......@@ -18,10 +18,12 @@ from django.utils import timezone
# Other imports
from ratelimit.decorators import ratelimit
import requests
# App Imports
from .forms import URLForm, EditForm
from .models import URL, RegisteredUser
from .utils import build_msg, send_slack_message
def index(request):
"""
......@@ -88,6 +90,9 @@ def _new_link_post(request):
# Call our post method to assemble our new URL object
res = post(request, url_form)
if settings.SLACK_URL:
send_slack_message(build_msg(request))
# If there is a 500 error returned, handle it
if res == 500:
return HttpResponseServerError(render(request, '500.html'))
......
......@@ -193,3 +193,5 @@ EMAIL_TO = os.environ["GO_EMAIL_TO"]
# Domain used to email to users. See implementation in views.py
# ie. '@gmu.edu'
EMAIL_DOMAIN = os.environ["GO_EMAIL_DOMAIN"]
SLACK_URL = os.environ.get("GO_SLACK_URL", "")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment