Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
go
Commits
d900316b
Commit
d900316b
authored
Nov 14, 2019
by
Zac Wood
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
0 deletions
+21
-0
.env
.env
+1
-0
go/go/utils.py
go/go/utils.py
+13
-0
go/go/views.py
go/go/views.py
+5
-0
go/settings/settings.py
go/settings/settings.py
+2
-0
No files found.
.env
View file @
d900316b
...
@@ -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 @
d900316b
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
}
\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 @
d900316b
...
@@ -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 @
d900316b
...
@@ -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