Improve code design after code review
This commit is contained in:
parent
2749e7a582
commit
6f714dfb4a
|
@ -13,7 +13,7 @@ class Profiles::ChatNamesController < Profiles::ApplicationController
|
||||||
new_chat_name = current_user.chat_names.new(chat_name_params)
|
new_chat_name = current_user.chat_names.new(chat_name_params)
|
||||||
|
|
||||||
if new_chat_name.save
|
if new_chat_name.save
|
||||||
flash[:notice] = "Authorized chat nickname #{new_chat_name.chat_name}"
|
flash[:notice] = "Authorized #{new_chat_name.chat_name}"
|
||||||
else
|
else
|
||||||
flash[:alert] = "Could not authorize chat nickname. Try again!"
|
flash[:alert] = "Could not authorize chat nickname. Try again!"
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ class Profiles::ChatNamesController < Profiles::ApplicationController
|
||||||
@chat_name = chat_names.find(params[:id])
|
@chat_name = chat_names.find(params[:id])
|
||||||
|
|
||||||
if @chat_name.destroy
|
if @chat_name.destroy
|
||||||
flash[:notice] = "Delete chat nickname: #{@chat_name.chat_name}!"
|
flash[:notice] = "Deleted chat nickname: #{@chat_name.chat_name}!"
|
||||||
else
|
else
|
||||||
flash[:alert] = "Could not delete chat nickname #{@chat_name.chat_name}."
|
flash[:alert] = "Could not delete chat nickname #{@chat_name.chat_name}."
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module ChatNames
|
||||||
chat_name = find_chat_name
|
chat_name = find_chat_name
|
||||||
return unless chat_name
|
return unless chat_name
|
||||||
|
|
||||||
chat_name.update(used_at: Time.now)
|
chat_name.update(last_used_at: Time.now)
|
||||||
chat_name.user
|
chat_name.user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
%h4.prepend-top-0
|
%h4.prepend-top-0
|
||||||
= page_title
|
= page_title
|
||||||
%p
|
%p
|
||||||
You can see your Chat integrations.
|
You can see your Chat accounts.
|
||||||
|
|
||||||
.col-lg-9
|
.col-lg-9
|
||||||
%h5 Active chat names (#{@chat_names.length})
|
%h5 Active chat names (#{@chat_names.length})
|
||||||
|
@ -39,11 +39,13 @@
|
||||||
= link_to service.title, edit_namespace_project_service_path(project.namespace, project, service)
|
= link_to service.title, edit_namespace_project_service_path(project.namespace, project, service)
|
||||||
- else
|
- else
|
||||||
= chat_name.service.title
|
= chat_name.service.title
|
||||||
%td= chat_name.team_domain
|
%td
|
||||||
%td= chat_name.chat_name
|
= chat_name.team_domain
|
||||||
%td=
|
%td
|
||||||
- if chat_name.used_at
|
= chat_name.chat_name
|
||||||
time_ago_with_tooltip(chat_name.used_at)
|
%td
|
||||||
|
- if chat_name.last_used_at
|
||||||
|
time_ago_with_tooltip(chat_name.last_used_at)
|
||||||
- else
|
- else
|
||||||
Never
|
Never
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
%h3.page-title Authorization required
|
%h3.page-title Authorization required
|
||||||
%main{:role => "main"}
|
%main{:role => "main"}
|
||||||
%p.h4
|
%p.h4
|
||||||
Authorize the chat user
|
Authorize
|
||||||
%strong.text-info= @chat_name_params[:chat_name]
|
%strong.text-info= @chat_name_params[:chat_name]
|
||||||
to use your account?
|
to use your account?
|
||||||
|
|
||||||
%hr/
|
%hr
|
||||||
.actions
|
.actions
|
||||||
= form_tag profile_chat_names_path, method: :post do
|
= form_tag profile_chat_names_path, method: :post do
|
||||||
= hidden_field_tag :token, @chat_name_token.token
|
= hidden_field_tag :token, @chat_name_token.token
|
||||||
|
|
|
@ -11,7 +11,7 @@ class CreateUserChatNamesTable < ActiveRecord::Migration
|
||||||
t.string :team_domain
|
t.string :team_domain
|
||||||
t.string :chat_id, null: false
|
t.string :chat_id, null: false
|
||||||
t.string :chat_name
|
t.string :chat_name
|
||||||
t.datetime :used_at
|
t.datetime :last_used_at
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ ActiveRecord::Schema.define(version: 20161113184239) do
|
||||||
t.string "team_domain"
|
t.string "team_domain"
|
||||||
t.string "chat_id", null: false
|
t.string "chat_id", null: false
|
||||||
t.string "chat_name"
|
t.string "chat_name"
|
||||||
t.datetime "used_at"
|
t.datetime "last_used_at"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Gitlab
|
||||||
attr_reader :token
|
attr_reader :token
|
||||||
|
|
||||||
TOKEN_LENGTH = 50
|
TOKEN_LENGTH = 50
|
||||||
EXPIRY_TIME = 10.minutes # 10 minutes
|
EXPIRY_TIME = 10.minutes
|
||||||
|
|
||||||
def initialize(token = new_token)
|
def initialize(token = new_token)
|
||||||
@token = token
|
@token = token
|
||||||
|
|
|
@ -12,9 +12,7 @@ describe Gitlab::ChatNameToken, lib: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when storing data' do
|
context 'when storing data' do
|
||||||
let(:data) {
|
let(:data) { { key: 'value' } }
|
||||||
{ key: 'value' }
|
|
||||||
}
|
|
||||||
|
|
||||||
subject { described_class.new(@token) }
|
subject { described_class.new(@token) }
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ describe ChatNames::AuthorizeUserService, services: true do
|
||||||
let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }
|
let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }
|
||||||
|
|
||||||
it 'requests a new token' do
|
it 'requests a new token' do
|
||||||
is_expected.to include('http')
|
is_expected.to be_url
|
||||||
is_expected.to include('://')
|
|
||||||
is_expected.to include('token=')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe ChatNames::FindUserService, services: true do
|
||||||
it 'updates when last time chat name was used' do
|
it 'updates when last time chat name was used' do
|
||||||
subject
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
RSpec::Matchers.define :be_url do |_|
|
||||||
|
match do |actual|
|
||||||
|
URI.parse(actual) rescue false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue