Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
06526c2f
Commit
06526c2f
authored
Nov 13, 2019
by
Zac Wood
Browse files
Send slack messages on /newLink
parent
bb7b3254
Pipeline
#5143
passed with stages
in 2 minutes and 7 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.env
View file @
06526c2f
...
@@ -14,4 +14,5 @@ GO_EMAIL_HOST_PASSWORD=
...
@@ -14,4 +14,5 @@ GO_EMAIL_HOST_PASSWORD=
GO_EMAIL_FROM=
GO_EMAIL_FROM=
GO_EMAIL_TO=
GO_EMAIL_TO=
GO_SECRET_KEY=spookyspecret
GO_SECRET_KEY=spookyspecret
GO_SLACK_URL=
superuser=zwood2
superuser=zwood2
go/go/utils.py
0 → 100644
View file @
06526c2f
import
requests
from
django.conf
import
settings
import
logging
import
sys
import
functools
from
threading
import
Thread
logger
=
logging
.
getLogger
(
__name__
)
def
build_msg
(
request
):
target
=
request
.
POST
[
'target'
]
short
=
f
'go.gmu.edu/
{
request
.
POST
[
"short"
]
}
'
return
f
'Short:
{
short
}
\n
Target:
{
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
()
go/go/views.py
View file @
06526c2f
...
@@ -18,10 +18,12 @@ from django.utils import timezone
...
@@ -18,10 +18,12 @@ from django.utils import timezone
# Other imports
# Other imports
from
ratelimit.decorators
import
ratelimit
from
ratelimit.decorators
import
ratelimit
import
requests
# App Imports
# App Imports
from
.forms
import
URLForm
,
EditForm
from
.forms
import
URLForm
,
EditForm
from
.models
import
URL
,
RegisteredUser
from
.models
import
URL
,
RegisteredUser
from
.utils
import
build_msg
,
send_slack_message
def
index
(
request
):
def
index
(
request
):
"""
"""
...
@@ -88,6 +90,9 @@ def _new_link_post(request):
...
@@ -88,6 +90,9 @@ def _new_link_post(request):
# Call our post method to assemble our new URL object
# Call our post method to assemble our new URL object
res
=
post
(
request
,
url_form
)
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 there is a 500 error returned, handle it
if
res
==
500
:
if
res
==
500
:
return
HttpResponseServerError
(
render
(
request
,
'500.html'
))
return
HttpResponseServerError
(
render
(
request
,
'500.html'
))
...
...
go/settings/settings.py
View file @
06526c2f
...
@@ -193,3 +193,5 @@ EMAIL_TO = os.environ["GO_EMAIL_TO"]
...
@@ -193,3 +193,5 @@ EMAIL_TO = os.environ["GO_EMAIL_TO"]
# Domain used to email to users. See implementation in views.py
# Domain used to email to users. See implementation in views.py
# ie. '@gmu.edu'
# ie. '@gmu.edu'
EMAIL_DOMAIN
=
os
.
environ
[
"GO_EMAIL_DOMAIN"
]
EMAIL_DOMAIN
=
os
.
environ
[
"GO_EMAIL_DOMAIN"
]
SLACK_URL
=
os
.
environ
.
get
(
"GO_SLACK_URL"
,
""
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment