Welcome to mirror list, hosted at ThFree Co, Russian Federation.

slack_option_service.rb « integrations « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a659f8b0634d21bf6e1e910ec9f4735096d6b121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Integrations
  class SlackOptionService
    UnknownOptionError = Class.new(StandardError)

    OPTIONS = {
      'assignee' => SlackOptions::UserSearchHandler,
      'labels' => SlackOptions::LabelSearchHandler
    }.freeze

    def initialize(params)
      @params = params
      @search_type = params.delete(:action_id)
      @selected_value = params.delete(:value)
      @view_id = params.dig(:view, :id)
    end

    def execute
      raise UnknownOptionError, "Unable to handle option: '#{search_type}'" \
        unless option?(search_type)

      handler_class = OPTIONS[search_type]
      handler_class.new(current_user, selected_value, view_id).execute
    end

    private

    def current_user
      ChatNames::FindUserService.new(
        params.dig(:team, :id),
        params.dig(:user, :id)
      ).execute
    end

    def option?(option)
      OPTIONS.key?(option)
    end

    attr_reader :params, :search_type, :selected_value, :view_id
  end
end