mattermosts_controller.rb 1.03 KB
Newer Older
Kamil Trzcinski's avatar
Kamil Trzcinski committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
15 16 17 18
    result, message = @service.configure(current_user, configure_params)

    if result
      flash[:notice] = 'This service is now configured'
19
      redirect_to edit_project_service_path(@project, service)
Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
20 21
    else
      flash[:alert] = message || 'Failed to configure service'
22
      redirect_to new_project_mattermost_path(@project)
Kamil Trzcinski's avatar
WIP  
Kamil Trzcinski committed
23
    end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
24 25 26 27 28 29 30
  end

  private

  def configure_params
    params.require(:mattermost).permit(:trigger, :team_id).merge(
      url: service_trigger_url(@service),
31
      icon_url: asset_url('slash-command-logo.png'))
Kamil Trzcinski's avatar
Kamil Trzcinski committed
32 33 34
  end

  def teams
35
    @teams, @teams_error_message = @service.list_teams(current_user)
Kamil Trzcinski's avatar
Kamil Trzcinski committed
36 37 38 39 40 41
  end

  def service
    @service ||= @project.find_or_initialize_service('mattermost_slash_commands')
  end
end