Nullify logins and rename repos owner when updating/creating user
This commit is contained in:
parent
5fc8cd7860
commit
3508f25bdf
|
@ -196,6 +196,8 @@ class Travis::Api::App
|
|||
end
|
||||
|
||||
class UserManager < Struct.new(:data, :token, :drop_token)
|
||||
include User::Renaming
|
||||
|
||||
def info(attributes = {})
|
||||
info = data.to_hash.slice('name', 'login', 'gravatar_id')
|
||||
info.merge! attributes.stringify_keys
|
||||
|
@ -207,10 +209,15 @@ class Travis::Api::App
|
|||
user = ::User.find_by_github_id(data['id'])
|
||||
info = drop_token ? info : info(github_oauth_token: token)
|
||||
|
||||
if user
|
||||
user.update_attributes info
|
||||
else
|
||||
user = ::User.create! info
|
||||
ActiveRecord::Base.transaction do
|
||||
if user
|
||||
rename_repos_owner(user.login, info['login'])
|
||||
user.update_attributes info
|
||||
else
|
||||
user = ::User.create! info
|
||||
end
|
||||
|
||||
nullify_logins(user.github_id, user.login)
|
||||
end
|
||||
|
||||
user
|
||||
|
|
|
@ -31,7 +31,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
|||
|
||||
context 'with existing user' do
|
||||
it 'updates user data' do
|
||||
user = mock('user')
|
||||
user = stub('user', login: 'drogus', github_id: 456)
|
||||
User.expects(:find_by_github_id).with(456).returns(user)
|
||||
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
||||
user.expects(:update_attributes).with(attributes)
|
||||
|
@ -42,7 +42,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
|||
|
||||
context 'without existing user' do
|
||||
it 'creates new user' do
|
||||
user = mock('user')
|
||||
user = stub('user', login: 'drogus', github_id: 456)
|
||||
User.expects(:find_by_github_id).with(456).returns(nil)
|
||||
attributes = { login: 'drogus', github_id: 456, github_oauth_token: 'abc123' }.stringify_keys
|
||||
User.expects(:create!).with(attributes).returns(user)
|
||||
|
|
Loading…
Reference in New Issue
Block a user