diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-17 21:08:24 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-17 21:08:24 +0300 |
commit | 726a414169e6c3219ff4fd410da3efd53fc7f912 (patch) | |
tree | b3cb53c9bb0724aacbf2181911b2157c5abef67a /app/services | |
parent | e96ee2a22ba56a77fcec371313e25d3b3c93cff2 (diff) | |
parent | d444fd3460e896065c21abda9a1cafa93f9315a5 (diff) |
Merge branch 'chat-name-authorize' into 'master'
Allows to authorize chat user against GitLab.
This is needed for: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7438
See merge request !7450
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/chat_names/authorize_user_service.rb | 38 | ||||
-rw-r--r-- | app/services/chat_names/find_user_service.rb | 26 |
2 files changed, 64 insertions, 0 deletions
diff --git a/app/services/chat_names/authorize_user_service.rb b/app/services/chat_names/authorize_user_service.rb new file mode 100644 index 00000000000..321bf3a9205 --- /dev/null +++ b/app/services/chat_names/authorize_user_service.rb @@ -0,0 +1,38 @@ +module ChatNames + class AuthorizeUserService + include Gitlab::Routing.url_helpers + + def initialize(service, params) + @service = service + @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 + Gitlab::ChatNameToken.new + end + + def chat_name_params + { + service_id: @service.id, + team_id: @params[:team_id], + team_domain: @params[:team_domain], + chat_id: @params[:user_id], + chat_name: @params[:user_name] + } + end + end +end diff --git a/app/services/chat_names/find_user_service.rb b/app/services/chat_names/find_user_service.rb new file mode 100644 index 00000000000..4f5c5567b42 --- /dev/null +++ b/app/services/chat_names/find_user_service.rb @@ -0,0 +1,26 @@ +module ChatNames + class FindUserService + def initialize(service, params) + @service = service + @params = params + end + + def execute + chat_name = find_chat_name + return unless chat_name + + chat_name.touch(:last_used_at) + chat_name.user + end + + private + + def find_chat_name + ChatName.find_by( + service: @service, + team_id: @params[:team_id], + chat_id: @params[:user_id] + ) + end + end +end |