summaryrefslogtreecommitdiff
path: root/app/services/chat_names/authorize_user_service.rb
blob: 6c28a1cea7e467279b37c4fbeeefcef34539261b (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
# frozen_string_literal: true

module ChatNames
  class AuthorizeUserService
    include Gitlab::Routing

    def initialize(integration, params)
      @integration = integration
      @params = params
    end

    def execute
      return unless chat_name_params.values.all?(&:present?)

      token = request_token

      new_profile_chat_name_url(token: token) if token
    end

    private

    def request_token
      chat_name_token.store!(chat_name_params)
    end

    def chat_name_token
      @chat_name_token ||= Gitlab::ChatNameToken.new
    end

    def chat_name_params
      {
        integration_id: @integration.id,
        team_id: @params[:team_id],
        team_domain: @params[:team_domain],
        chat_id: @params[:user_id],
        chat_name: @params[:user_name]
      }
    end
  end
end