diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-16 14:56:30 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-16 14:56:30 +0100 |
commit | d64183e1fa26ab77107e3a2a20be1fe4df3a1875 (patch) | |
tree | 00d7b51545c116ce67bb857fd1003ea381250584 /app | |
parent | c60437786bfe43344b4a5eb040437f73f37c6396 (diff) | |
download | gitlab-ce-d64183e1fa26ab77107e3a2a20be1fe4df3a1875.tar.gz |
Add most of specs for chat names
Diffstat (limited to 'app')
-rw-r--r-- | app/services/chat_names/authorize_user_service.rb (renamed from app/services/chat_names/request_service.rb) | 10 | ||||
-rw-r--r-- | app/services/chat_names/find_user_service.rb | 17 | ||||
-rw-r--r-- | app/views/profiles/chat_names/index.html.haml | 14 |
3 files changed, 32 insertions, 9 deletions
diff --git a/app/services/chat_names/request_service.rb b/app/services/chat_names/authorize_user_service.rb index c67b93f932f..321bf3a9205 100644 --- a/app/services/chat_names/request_service.rb +++ b/app/services/chat_names/authorize_user_service.rb @@ -1,5 +1,5 @@ module ChatNames - class RequestService + class AuthorizeUserService include Gitlab::Routing.url_helpers def initialize(service, params) @@ -8,13 +8,19 @@ module ChatNames end def execute - token = chat_name_token.store!(chat_name_params) + 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 diff --git a/app/services/chat_names/find_user_service.rb b/app/services/chat_names/find_user_service.rb index 6b7f75430a8..28e3e155be1 100644 --- a/app/services/chat_names/find_user_service.rb +++ b/app/services/chat_names/find_user_service.rb @@ -1,12 +1,23 @@ module ChatNames class FindUserService - def initialize(chat_names, params) - @chat_names = chat_names + def initialize(service, params) + @service = service @params = params end def execute - @chat_names.find_by( + chat_name = find_chat_name + return unless chat_name + + chat_name.update(used_at: Time.now) + chat_name.user + end + + private + + def find_chat_name + ChatName.find_by( + service: @service, team_id: @params[:team_id], chat_id: @params[:user_id] ) diff --git a/app/views/profiles/chat_names/index.html.haml b/app/views/profiles/chat_names/index.html.haml index f90ac4c6a03..ae0b6336944 100644 --- a/app/views/profiles/chat_names/index.html.haml +++ b/app/views/profiles/chat_names/index.html.haml @@ -1,4 +1,4 @@ -- page_title "Chat" +- page_title 'Chat' = render 'profiles/head' .row.prepend-top-default @@ -20,7 +20,7 @@ %th Service %th Team domain %th Nickname - %th Created + %th Last used %th %tbody - @chat_names.each do |chat_name| @@ -41,8 +41,14 @@ = chat_name.service.title %td= chat_name.team_domain %td= chat_name.chat_name - %td= chat_name.created_at - %td= link_to "Remove", profile_chat_name_path(chat_name), method: :delete, class: "btn btn-danger pull-right", data: { confirm: "Are you sure you want to revoke this nickname?" } + %td= + - if chat_name.used_at + time_ago_with_tooltip(chat_name.used_at) + - else + Never + + %td + = link_to 'Remove', profile_chat_name_path(chat_name), method: :delete, class: 'btn btn-danger pull-right', data: { confirm: 'Are you sure you want to revoke this nickname?' } - else .settings-message.text-center |