2016-12-19 17:53:19 -05:00
|
|
|
class Projects::MattermostsController < Projects::ApplicationController
|
|
|
|
include TriggersHelper
|
|
|
|
include ActionView::Helpers::AssetUrlHelper
|
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :service
|
|
|
|
before_action :teams, only: [:new]
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-12-20 13:11:53 -05:00
|
|
|
result, message = @service.configure(current_user, configure_params)
|
|
|
|
|
|
|
|
if result
|
|
|
|
flash[:notice] = 'This service is now configured'
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to edit_project_service_path(@project, service)
|
2016-12-20 13:11:53 -05:00
|
|
|
else
|
|
|
|
flash[:alert] = message || 'Failed to configure service'
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to new_project_mattermost_path(@project)
|
2016-12-20 13:11:53 -05:00
|
|
|
end
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def configure_params
|
|
|
|
params.require(:mattermost).permit(:trigger, :team_id).merge(
|
|
|
|
url: service_trigger_url(@service),
|
2016-12-29 04:58:27 -05:00
|
|
|
icon_url: asset_url('slash-command-logo.png'))
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teams
|
2017-01-26 03:16:07 -05:00
|
|
|
@teams, @teams_error_message = @service.list_teams(current_user)
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def service
|
|
|
|
@service ||= @project.find_or_initialize_service('mattermost_slash_commands')
|
|
|
|
end
|
|
|
|
end
|