try fixing updating github oauth scopes
This commit is contained in:
parent
7250656de0
commit
25f74defe5
|
@ -292,7 +292,7 @@ class Travis::Api::App
|
||||||
Travis.run_service(:sync_user, user)
|
Travis.run_service(:sync_user, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
Travis::Github::Oauth.track_scopes(user) # unless Travis.env == 'test'
|
Travis::Github::Oauth.update_scopes(user) # unless Travis.env == 'test'
|
||||||
|
|
||||||
nullify_logins(user.github_id, user.login)
|
nullify_logins(user.github_id, user.login)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Travis::Features.enable_for_all(:education_data_sync)
|
Travis::Features.enable_for_all(:education_data_sync)
|
||||||
Travis::Github::Oauth.stubs(:track_scopes) # TODO test that scopes are being updated
|
Travis::Github::Oauth.stubs(:update_scopes) # TODO test that scopes are being updated
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#info' do
|
describe '#info' do
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe Travis::Github::Oauth do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'track_scopes' do
|
describe 'update_scopes' do
|
||||||
before { user.reload }
|
before { user.reload }
|
||||||
|
|
||||||
describe 'the token did not change' do
|
describe 'the token did not change' do
|
||||||
|
@ -28,7 +28,7 @@ describe Travis::Github::Oauth do
|
||||||
|
|
||||||
it 'does not resolve github scopes' do
|
it 'does not resolve github scopes' do
|
||||||
Travis::Github::Oauth.expects(:scopes_for).never
|
Travis::Github::Oauth.expects(:scopes_for).never
|
||||||
described_class.track_scopes(user)
|
described_class.update_scopes(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ describe Travis::Github::Oauth do
|
||||||
|
|
||||||
it 'updates github scopes' do
|
it 'updates github scopes' do
|
||||||
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
|
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
|
||||||
described_class.track_scopes(user)
|
described_class.update_scopes(user)
|
||||||
expect(user.reload.github_scopes).to eq ['foo', 'bar']
|
expect(user.reload.github_scopes).to eq ['foo', 'bar']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -57,7 +57,7 @@ describe Travis::Github::Oauth do
|
||||||
|
|
||||||
it 'updates github scopes' do
|
it 'updates github scopes' do
|
||||||
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
|
Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar'])
|
||||||
described_class.track_scopes(user)
|
described_class.update_scopes(user)
|
||||||
expect(user.reload.github_scopes).to eq ['foo', 'bar']
|
expect(user.reload.github_scopes).to eq ['foo', 'bar']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
10
vendor/travis-core/lib/travis/github/oauth.rb
vendored
10
vendor/travis-core/lib/travis/github/oauth.rb
vendored
|
@ -1,7 +1,7 @@
|
||||||
module Travis
|
module Travis
|
||||||
module Github
|
module Github
|
||||||
module Oauth
|
module Oauth
|
||||||
class TrackScopes < Struct.new(:user)
|
class UpdateScopes < Struct.new(:user)
|
||||||
def run
|
def run
|
||||||
update if update?
|
update if update?
|
||||||
end
|
end
|
||||||
|
@ -14,17 +14,17 @@ module Travis
|
||||||
end
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
github_oauth_token_changed?(user) or user.github_scopes.blank?
|
token_changed?(user) or not Oauth.correct_scopes?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_oauth_token_changed?(user)
|
def token_changed?(user)
|
||||||
user.github_oauth_token_changed? or user.previous_changes.key?('github_oauth_token')
|
user.github_oauth_token_changed? or user.previous_changes.key?('github_oauth_token')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def track_scopes(user)
|
def update_scopes(user)
|
||||||
TrackScopes.new(user).run
|
UpdateScopes.new(user).run
|
||||||
end
|
end
|
||||||
|
|
||||||
def correct_scopes?(user)
|
def correct_scopes?(user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user