2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-19 17:53:19 -05:00
|
|
|
class Projects::MattermostsController < Projects::ApplicationController
|
2021-01-11 13:10:43 -05:00
|
|
|
include Ci::TriggersHelper
|
2016-12-19 17:53:19 -05:00
|
|
|
include ActionView::Helpers::AssetUrlHelper
|
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
|
|
|
before_action :authorize_admin_project!
|
2021-06-23 14:07:10 -04:00
|
|
|
before_action :integration
|
2016-12-19 17:53:19 -05:00
|
|
|
before_action :teams, only: [:new]
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :integrations
|
|
|
|
|
2016-12-19 17:53:19 -05:00
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2021-06-23 14:07:10 -04:00
|
|
|
result, message = integration.configure(current_user, configure_params)
|
2016-12-20 13:11:53 -05:00
|
|
|
|
|
|
|
if result
|
|
|
|
flash[:notice] = 'This service is now configured'
|
2022-05-25 14:08:15 -04:00
|
|
|
redirect_to edit_project_settings_integration_path(@project, integration)
|
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(
|
2021-06-23 14:07:10 -04:00
|
|
|
url: service_trigger_url(integration),
|
2020-04-22 05:09:36 -04:00
|
|
|
icon_url: asset_url('slash-command-logo.png', skip_pipeline: true))
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teams
|
2021-06-23 14:07:10 -04:00
|
|
|
@teams, @teams_error_message = integration.list_teams(current_user)
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
|
2021-06-23 14:07:10 -04:00
|
|
|
def integration
|
|
|
|
@integration ||= @project.find_or_initialize_integration('mattermost_slash_commands')
|
2016-12-19 17:53:19 -05:00
|
|
|
end
|
|
|
|
end
|