Commit 99d8d6f0 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Add MattermostController

parent 87d16063
class Projects::MattermostController < Projects::ApplicationController
layout 'project_settings'
before_action :authorize_admin_project!
before_action :service
before_action :teams, only: [:new]
def new
end
def configure
@service.configure(host, current_user, params)
redirect_to(
new_namespace_project_service_path(@project.namespace, @project, @service.to_param),
notice: 'This service is now configured.'
)
rescue Mattermost::NoSessionError
redirect_to(
edit_namespace_project_service_path(@project.namespace, @project, @service.to_param),
alert: 'No session could be set up, is Mattermost configured with Single Sign on?'
)
end
private
def configure_params
params.require(:configure_params).permit(:trigger, :team_id)
end
def service
@service ||= @project.services.find_by(type: 'MattermostSlashCommandsService')
end
def teams
# Mocking for frontend development
@teams = [{"id"=>"qz8gdr1fopncueb8n9on8ohk3h", "create_at"=>1479992105904, "update_at"=>1479992105904, "delete_at"=>0, "display_name"=>"chatops", "name"=>"chatops", "email"=>"admin@example.com", "type"=>"O", "company_name"=>"", "allowed_domains"=>"", "invite_id"=>"gthxi47gj7rxtcx6zama63zd1w", "allow_open_invite"=>false}]
# @teams =
# begin
# Mattermost::Mattermost.new(Gitlab.config.mattermost.host, current_user).with_session do
# Mattermost::Team.all
# end
# rescue Mattermost::NoSessionError
# @teams = []
# end
end
end
= "hello world"
= form_for(:create, method: :post, url: configure_namespace_project_mattermost_path(@project.namespace, @project, @service.to_param)) do |f|
= "Team ID"
= f.text_field(:team_id)
= f.submit 'Configure', class: 'btn btn-save'
- pretty_path_with_namespace = "#{@project ? @project.namespace.name : 'namespace'} / #{@project ? @project.name : 'name'}" - pretty_path_with_namespace = "#{@project ? @project.namespace.name : 'namespace'} / #{@project ? @project.name : 'name'}"
- run_actions_text = "Perform common operations on this project: #{pretty_path_with_namespace}" - run_actions_text = "Perform common operations on this project: #{pretty_path_with_namespace}"
- unless GitLab.config.mattermost.enabled .well
.well
This service allows GitLab users to perform common operations on this This service allows GitLab users to perform common operations on this
project by entering slash commands in Mattermost. project by entering slash commands in Mattermost.
%br %br
...@@ -99,3 +98,6 @@ ...@@ -99,3 +98,6 @@
3. After adding the slash command, paste the 3. After adding the slash command, paste the
%strong token %strong token
into the field below into the field below
- if Gitlab.config.mattermost.enabled
= link_to "Auto config", new_namespace_project_mattermost_path(@project.namespace, @project)
...@@ -65,6 +65,12 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -65,6 +65,12 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
resources :mattermost, only: [:new] do
member do
post :configure
end
end
resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do resources :deploy_keys, constraints: { id: /\d+/ }, only: [:index, :new, :create] do
member do member do
put :enable put :enable
......
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