debian-mirror-gitlab/app/controllers/projects/mattermosts_controller.rb

42 lines
1 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
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
result, message = @service.configure(current_user, configure_params)
if result
flash[:notice] = 'This service is now configured'
2017-09-10 17:25:29 +05:30
redirect_to edit_project_service_path(@project, service)
2017-08-17 22:00:37 +05:30
else
flash[:alert] = message || 'Failed to configure service'
2017-09-10 17:25:29 +05:30
redirect_to new_project_mattermost_path(@project)
2017-08-17 22:00:37 +05:30
end
end
private
def configure_params
params.require(:mattermost).permit(:trigger, :team_id).merge(
url: service_trigger_url(@service),
icon_url: asset_url('slash-command-logo.png'))
end
def teams
@teams, @teams_error_message = @service.list_teams(current_user)
end
def service
@service ||= @project.find_or_initialize_service('mattermost_slash_commands')
end
end