Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
53271b48
Commit
53271b48
authored
Nov 14, 2016
by
Kamil Trzcinski
Committed by
Z.J. van de Weg
Nov 17, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make chat authorization to work [ci skip]
parent
47621989
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
92 additions
and
35 deletions
+92
-35
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+2
-0
app/helpers/triggers_helper.rb
app/helpers/triggers_helper.rb
+4
-0
app/models/project.rb
app/models/project.rb
+3
-2
app/models/project_services/chat_service.rb
app/models/project_services/chat_service.rb
+5
-2
app/models/project_services/mattermost_chat_service.rb
app/models/project_services/mattermost_chat_service.rb
+27
-8
app/models/service.rb
app/models/service.rb
+1
-0
app/views/shared/_service_settings.html.haml
app/views/shared/_service_settings.html.haml
+21
-20
config/environments/development.rb
config/environments/development.rb
+3
-0
lib/api/services.rb
lib/api/services.rb
+26
-3
No files found.
app/controllers/projects/services_controller.rb
View file @
53271b48
...
@@ -28,6 +28,8 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -28,6 +28,8 @@ class Projects::ServicesController < Projects::ApplicationController
end
end
def
test
def
test
return
render_404
unless
@service
.
can_test?
data
=
@service
.
test_data
(
project
,
current_user
)
data
=
@service
.
test_data
(
project
,
current_user
)
outcome
=
@service
.
test
(
data
)
outcome
=
@service
.
test
(
data
)
...
...
app/helpers/triggers_helper.rb
View file @
53271b48
...
@@ -6,4 +6,8 @@ module TriggersHelper
...
@@ -6,4 +6,8 @@ module TriggersHelper
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
project_id
}
/ref/
#{
ref
}
/trigger/builds"
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
project_id
}
/ref/
#{
ref
}
/trigger/builds"
end
end
end
end
def
service_trigger_url
(
service
)
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
service
.
project_id
}
/services/
#{
service
.
to_param
}
/trigger"
end
end
end
app/models/project.rb
View file @
53271b48
...
@@ -23,8 +23,8 @@ class Project < ActiveRecord::Base
...
@@ -23,8 +23,8 @@ class Project < ActiveRecord::Base
cache_markdown_field
:description
,
pipeline: :description
cache_markdown_field
:description
,
pipeline: :description
delegate
:feature_available?
,
:builds_enabled?
,
:wiki_enabled?
,
delegate
:feature_available?
,
:builds_enabled?
,
:wiki_enabled?
,
:merge_requests_enabled?
,
:issues_enabled?
,
to: :project_feature
,
:merge_requests_enabled?
,
:issues_enabled?
,
to: :project_feature
,
allow_nil:
true
allow_nil:
true
default_value_for
:archived
,
false
default_value_for
:archived
,
false
...
@@ -91,6 +91,7 @@ class Project < ActiveRecord::Base
...
@@ -91,6 +91,7 @@ class Project < ActiveRecord::Base
has_one
:assembla_service
,
dependent: :destroy
has_one
:assembla_service
,
dependent: :destroy
has_one
:asana_service
,
dependent: :destroy
has_one
:asana_service
,
dependent: :destroy
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:gemnasium_service
,
dependent: :destroy
has_one
:mattermost_chat_service
,
dependent: :destroy
has_one
:slack_service
,
dependent: :destroy
has_one
:slack_service
,
dependent: :destroy
has_one
:buildkite_service
,
dependent: :destroy
has_one
:buildkite_service
,
dependent: :destroy
has_one
:bamboo_service
,
dependent: :destroy
has_one
:bamboo_service
,
dependent: :destroy
...
...
app/models/project_services/chat_service.rb
View file @
53271b48
...
@@ -3,13 +3,16 @@
...
@@ -3,13 +3,16 @@
class
ChatService
<
Service
class
ChatService
<
Service
default_value_for
:category
,
'chat'
default_value_for
:category
,
'chat'
has_many
:chat_
users
has_many
:chat_
names
,
foreign_key: :service_id
def
valid_token?
(
token
)
def
valid_token?
(
token
)
self
.
respond_to?
(
:token
)
&&
self
.
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
self
.
respond_to?
(
:token
)
&&
self
.
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
end
end
def
supported_events
def
supported_events
[]
end
end
def
trigger
(
params
)
def
trigger
(
params
)
...
...
app/models/project_services/mattermost_chat_service.rb
View file @
53271b48
# Base class for Chat services
class
MattermostChatService
<
ChatService
class
MattermostChatService
<
ChatService
include
TriggersHelper
prop_accessor
:token
def
can_test?
false
end
def
title
def
title
'Mattermost'
'Mattermost'
end
end
...
@@ -13,28 +20,40 @@ class MattermostChatService < ChatService
...
@@ -13,28 +20,40 @@ class MattermostChatService < ChatService
end
end
def
help
def
help
'This service allows you to use slash commands with your Mattermost installation.<br/>
"This service allows you to use slash commands with your Mattermost installation.<br/>
To setup this Service you need to create a new <b>"Slash commands"</b> in your Mattermost integration panel,
To setup this Service you need to create a new <b>Slash commands</b> in your Mattermost integration panel.<br/>
and enter the token below.'
<br/>
Create integration with URL
#{
service_trigger_url
(
self
)
}
and enter the token below."
end
end
def
fields
def
fields
[
[
{
type:
'text'
,
name:
'token'
,
placeholder:
'
https://hooks.slack.com/services/...
'
}
{
type:
'text'
,
name:
'token'
,
placeholder:
''
}
]
]
end
end
def
trigger
(
params
)
def
trigger
(
params
)
user
=
ChatNames
::
FindUserService
.
new
(
chat_names
,
params
).
execute
return
nil
unless
valid_token?
(
params
[
:token
])
user
=
find_chat_user
(
params
)
return
authorize_chat_name
(
params
)
unless
user
return
authorize_chat_name
(
params
)
unless
user
Mattermost
::
CommandService
.
new
(
project
,
user
,
params
).
execute
Mattermost
::
CommandService
.
new
(
project
,
user
,
params
.
slice
(
:command
,
:text
)).
execute
end
end
private
private
def
find_chat_user
(
params
)
params
=
params
.
slice
(
:team_id
,
:user_id
)
ChatNames
::
FindUserService
.
new
(
chat_names
,
params
).
execute
end
def
authorize_chat_name
(
params
)
def
authorize_chat_name
(
params
)
url
=
ChatNames
::
RequestService
.
new
(
service
,
params
).
execute
params
=
params
.
slice
(
:team_id
,
:team_domain
,
:user_id
,
:user_name
)
url
=
ChatNames
::
AuthorizeUserService
.
new
(
self
,
params
).
execute
{
{
response_type: :ephemeral
,
response_type: :ephemeral
,
...
...
app/models/service.rb
View file @
53271b48
...
@@ -214,6 +214,7 @@ class Service < ActiveRecord::Base
...
@@ -214,6 +214,7 @@ class Service < ActiveRecord::Base
hipchat
hipchat
irker
irker
jira
jira
mattermost_chat
pivotaltracker
pivotaltracker
pushover
pushover
redmine
redmine
...
...
app/views/shared/_service_settings.html.haml
View file @
53271b48
...
@@ -10,26 +10,27 @@
...
@@ -10,26 +10,27 @@
.col-sm-10
.col-sm-10
=
form
.
check_box
:active
=
form
.
check_box
:active
.form-group
-
if
@service
.
supported_events
.
present?
=
form
.
label
:url
,
"Trigger"
,
class:
'control-label'
.form-group
=
form
.
label
:url
,
"Trigger"
,
class:
'control-label'
.col-sm-10
-
@service
.
supported_events
.
each
do
|
event
|
.col-sm-10
%div
-
@service
.
supported_events
.
each
do
|
event
|
=
form
.
check_box
service_event_field_name
(
event
),
class:
'pull-left'
%div
.prepend-left-20
=
form
.
check_box
service_event_field_name
(
event
),
class:
'pull-left'
=
form
.
label
service_event_field_name
(
event
),
class:
'list-label'
do
.prepend-left-20
%strong
=
form
.
label
service_event_field_name
(
event
),
class:
'list-label'
do
=
event
.
humanize
%strong
=
event
.
humanize
-
field
=
@service
.
event_field
(
event
)
-
field
=
@service
.
event_field
(
event
)
-
if
field
%p
-
if
field
=
form
.
text_field
field
[
:name
],
class:
"form-control"
,
placeholder:
field
[
:placeholder
]
%p
=
form
.
text_field
field
[
:name
],
class:
"form-control"
,
placeholder:
field
[
:placeholder
]
%p
.light
=
service_event_description
(
event
)
%p
.light
=
service_event_description
(
event
)
-
@service
.
global_fields
.
each
do
|
field
|
-
@service
.
global_fields
.
each
do
|
field
|
-
type
=
field
[
:type
]
-
type
=
field
[
:type
]
...
...
config/environments/development.rb
View file @
53271b48
...
@@ -45,4 +45,7 @@ Rails.application.configure do
...
@@ -45,4 +45,7 @@ Rails.application.configure do
# Do not log asset requests
# Do not log asset requests
config
.
assets
.
quiet
=
true
config
.
assets
.
quiet
=
true
# Make hot reloading to work with Grape API
ActiveSupport
::
Dependencies
.
explicitly_unloadable_constants
<<
"API"
end
end
lib/api/services.rb
View file @
53271b48
module
API
module
API
# Projects API
# Projects API
class
Services
<
Grape
::
API
class
Services
<
Grape
::
API
before
{
authenticate!
}
before
{
authorize_admin_project
}
resource
:projects
do
resource
:projects
do
before
{
authenticate!
}
before
{
authorize_admin_project
}
# Set <service_slug> service for project
# Set <service_slug> service for project
#
#
# Example Request:
# Example Request:
...
@@ -59,5 +59,28 @@ module API
...
@@ -59,5 +59,28 @@ module API
present
project_service
,
with:
Entities
::
ProjectService
,
include_passwords:
current_user
.
is_admin?
present
project_service
,
with:
Entities
::
ProjectService
,
include_passwords:
current_user
.
is_admin?
end
end
end
end
resource
:projects
do
post
':id/services/:service_slug/trigger'
do
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
underscored_service
=
params
[
:service_slug
].
underscore
not_found!
(
'Service'
)
unless
Service
.
available_services_names
.
include?
(
underscored_service
)
service_method
=
"
#{
underscored_service
}
_service"
service
=
project
.
public_send
(
service_method
)
result
=
if
service
.
try
(
:active?
)
&&
service
.
respond_to?
(
:trigger
)
service
.
trigger
(
params
)
end
if
result
present
result
,
status:
result
[
:status
]
||
200
else
not_found!
(
'Service'
)
end
end
end
end
end
end
end
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