diff --git a/app/controllers/profiles/chat_names_controller.rb b/app/controllers/profiles/chat_names_controller.rb index 0d3bdeff416e08bf085ca9a197ae8a2c648e1b4d..7f9c8e64cca09ea7b298723ce653713128f39f6c 100644 --- a/app/controllers/profiles/chat_names_controller.rb +++ b/app/controllers/profiles/chat_names_controller.rb @@ -13,7 +13,7 @@ class Profiles::ChatNamesController < Profiles::ApplicationController new_chat_name = current_user.chat_names.new(chat_name_params) if new_chat_name.save - flash[:notice] = "Authorized chat nickname #{new_chat_name.chat_name}" + flash[:notice] = "Authorized #{new_chat_name.chat_name}" else flash[:alert] = "Could not authorize chat nickname. Try again!" end @@ -34,7 +34,7 @@ class Profiles::ChatNamesController < Profiles::ApplicationController @chat_name = chat_names.find(params[:id]) if @chat_name.destroy - flash[:notice] = "Delete chat nickname: #{@chat_name.chat_name}!" + flash[:notice] = "Deleted chat nickname: #{@chat_name.chat_name}!" else flash[:alert] = "Could not delete chat nickname #{@chat_name.chat_name}." end diff --git a/app/services/chat_names/find_user_service.rb b/app/services/chat_names/find_user_service.rb index 28e3e155be173cd9675ec3dffb17978949edd04f..08079fdaf70783e8855ee5daa0f14e96234513b7 100644 --- a/app/services/chat_names/find_user_service.rb +++ b/app/services/chat_names/find_user_service.rb @@ -9,7 +9,7 @@ module ChatNames chat_name = find_chat_name return unless chat_name - chat_name.update(used_at: Time.now) + chat_name.update(last_used_at: Time.now) chat_name.user end diff --git a/app/views/profiles/chat_names/index.html.haml b/app/views/profiles/chat_names/index.html.haml index ae0b6336944f7cfd1713ebbfa76c13998ff33987..6d8d606583d9d16aecea93cbd4a27169ed333faa 100644 --- a/app/views/profiles/chat_names/index.html.haml +++ b/app/views/profiles/chat_names/index.html.haml @@ -6,7 +6,7 @@ %h4.prepend-top-0 = page_title %p - You can see your Chat integrations. + You can see your Chat accounts. .col-lg-9 %h5 Active chat names (#{@chat_names.length}) @@ -39,11 +39,13 @@ = link_to service.title, edit_namespace_project_service_path(project.namespace, project, service) - else = chat_name.service.title - %td= chat_name.team_domain - %td= chat_name.chat_name - %td= - - if chat_name.used_at - time_ago_with_tooltip(chat_name.used_at) + %td + = chat_name.team_domain + %td + = chat_name.chat_name + %td + - if chat_name.last_used_at + time_ago_with_tooltip(chat_name.last_used_at) - else Never diff --git a/app/views/profiles/chat_names/new.html.haml b/app/views/profiles/chat_names/new.html.haml index 0b9ee8c71ad3fcc78aaeee45ce104eb233ffff15..f635acf96e206e956b0cc1e1848c9cadee7715ae 100644 --- a/app/views/profiles/chat_names/new.html.haml +++ b/app/views/profiles/chat_names/new.html.haml @@ -1,11 +1,11 @@ %h3.page-title Authorization required %main{:role => "main"} %p.h4 - Authorize the chat user + Authorize %strong.text-info= @chat_name_params[:chat_name] to use your account? - %hr/ + %hr .actions = form_tag profile_chat_names_path, method: :post do = hidden_field_tag :token, @chat_name_token.token diff --git a/db/migrate/20161113184239_create_user_chat_names_table.rb b/db/migrate/20161113184239_create_user_chat_names_table.rb index 1e138fba202080ea4cf4ec773ea6641bd1041a90..97b597654f78040cbfe8fe6da42b706341581d7e 100644 --- a/db/migrate/20161113184239_create_user_chat_names_table.rb +++ b/db/migrate/20161113184239_create_user_chat_names_table.rb @@ -11,7 +11,7 @@ class CreateUserChatNamesTable < ActiveRecord::Migration t.string :team_domain t.string :chat_id, null: false t.string :chat_name - t.datetime :used_at + t.datetime :last_used_at t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 3688df3a2389d9f9f35f56ac5fa503bdb9a6592f..5732b1b73c11d3418fe0d3f3abc938bddf4927fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -159,7 +159,7 @@ ActiveRecord::Schema.define(version: 20161113184239) do t.string "team_domain" t.string "chat_id", null: false t.string "chat_name" - t.datetime "used_at" + t.datetime "last_used_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/lib/gitlab/chat_name_token.rb b/lib/gitlab/chat_name_token.rb index 543f038a4d4b95e871f8782c1748a413757395ef..1b081aa9b1d7d281c06438cb5522dd299a31e10f 100644 --- a/lib/gitlab/chat_name_token.rb +++ b/lib/gitlab/chat_name_token.rb @@ -5,7 +5,7 @@ module Gitlab attr_reader :token TOKEN_LENGTH = 50 - EXPIRY_TIME = 10.minutes # 10 minutes + EXPIRY_TIME = 10.minutes def initialize(token = new_token) @token = token diff --git a/spec/lib/gitlab/chat_name_token_spec.rb b/spec/lib/gitlab/chat_name_token_spec.rb index 8d7e7a9905962c60c78645640dfefe122fdf8bba..8c1e6efa9db437ab467e304b40e886ef6196d0b3 100644 --- a/spec/lib/gitlab/chat_name_token_spec.rb +++ b/spec/lib/gitlab/chat_name_token_spec.rb @@ -12,9 +12,7 @@ describe Gitlab::ChatNameToken, lib: true do end context 'when storing data' do - let(:data) { - { key: 'value' } - } + let(:data) { { key: 'value' } } subject { described_class.new(@token) } diff --git a/spec/services/chat_names/authorize_user_service_spec.rb b/spec/services/chat_names/authorize_user_service_spec.rb index f8c26e51bfc7293cc0f91c44c000dc3682a6ac09..2ecee58e92dd7b6f5c81b69e28e5e6e289169a79 100644 --- a/spec/services/chat_names/authorize_user_service_spec.rb +++ b/spec/services/chat_names/authorize_user_service_spec.rb @@ -10,9 +10,7 @@ describe ChatNames::AuthorizeUserService, services: true do let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } } it 'requests a new token' do - is_expected.to include('http') - is_expected.to include('://') - is_expected.to include('token=') + is_expected.to be_url end end diff --git a/spec/services/chat_names/find_user_service_spec.rb b/spec/services/chat_names/find_user_service_spec.rb index cf5844069f95884c1c0eccd761fb336ed52fedbe..5b885b2c6571cd95bf2855e272f1dbcbf3b466f7 100644 --- a/spec/services/chat_names/find_user_service_spec.rb +++ b/spec/services/chat_names/find_user_service_spec.rb @@ -20,7 +20,7 @@ describe ChatNames::FindUserService, services: true do it 'updates when last time chat name was used' do subject - expect(chat_name.reload.used_at).to be_like_time(Time.now) + expect(chat_name.reload.last_used_at).to be_like_time(Time.now) end end diff --git a/spec/support/matchers/be_url.rb b/spec/support/matchers/be_url.rb new file mode 100644 index 0000000000000000000000000000000000000000..f8096af1b22f9cdd5bf3fab0af28ed657612caba --- /dev/null +++ b/spec/support/matchers/be_url.rb @@ -0,0 +1,5 @@ +RSpec::Matchers.define :be_url do |_| + match do |actual| + URI.parse(actual) rescue false + end +end