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

46 lines
1.2 KiB
Ruby
Raw Normal View History

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