first stab at user/org sync
This commit is contained in:
parent
0511223ca5
commit
b7466074ca
|
@ -50,7 +50,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-core.git
|
remote: git://github.com/travis-ci/travis-core.git
|
||||||
revision: ba10e214824632f15598555a2634ce3347d2f227
|
revision: 4834399048b8c9cff4882d435f770826930665f6
|
||||||
specs:
|
specs:
|
||||||
travis-core (0.0.1)
|
travis-core (0.0.1)
|
||||||
actionmailer (~> 3.2.19)
|
actionmailer (~> 3.2.19)
|
||||||
|
@ -81,7 +81,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-support.git
|
remote: git://github.com/travis-ci/travis-support.git
|
||||||
revision: 4fdd220ed7b06a12951e5d74a763c05a80eb0d20
|
revision: e7f81093f83bd029cca6508739c5720e57e3d571
|
||||||
specs:
|
specs:
|
||||||
travis-support (0.0.1)
|
travis-support (0.0.1)
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,10 @@ module Travis::API::V3
|
||||||
unrestricted_api?
|
unrestricted_api?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_writable?(user)
|
||||||
|
user and user == self.user
|
||||||
|
end
|
||||||
|
|
||||||
def repository_visible?(repository)
|
def repository_visible?(repository)
|
||||||
return true if unrestricted_api? and not repository.private?
|
return true if unrestricted_api? and not repository.private?
|
||||||
private_repository_visible?(repository)
|
private_repository_visible?(repository)
|
||||||
|
|
|
@ -6,5 +6,8 @@ module Travis::API::V3
|
||||||
return Models::Organization.find_by_id(id) if id
|
return Models::Organization.find_by_id(id) if id
|
||||||
raise WrongParams, 'missing organization.id'.freeze
|
raise WrongParams, 'missing organization.id'.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,5 +6,8 @@ module Travis::API::V3
|
||||||
return Models::User.find_by_id(id) if id
|
return Models::User.find_by_id(id) if id
|
||||||
raise WrongParams, 'missing user.id'.freeze
|
raise WrongParams, 'missing user.id'.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync(user = find)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,12 +32,13 @@ module Travis::API::V3
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_async(identifier, *args)
|
def perform_async(identifier, *args)
|
||||||
class_name, queue = @@sidekiq_cache[identifier] ||= [
|
Sidekiqs[identifier].perform_async(*args)
|
||||||
"Travis::Sidekiq::#{identifier.to_s.camelcase}".freeze,
|
# class_name, queue = @@sidekiq_cache[identifier] ||= [
|
||||||
identifier.to_s.pluralize.freeze
|
# "Travis::Sidekiq::#{identifier.to_s.camelcase}".freeze,
|
||||||
]
|
# identifier.to_s.pluralize.freeze
|
||||||
|
# ]
|
||||||
::Sidekiq::Client.push('queue'.freeze => queue, 'class'.freeze => class_name, 'args'.freeze => args)
|
#
|
||||||
|
# ::Sidekiq::Client.push('queue'.freeze => queue, 'class'.freeze => class_name, 'args'.freeze => args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def includes?(key)
|
def includes?(key)
|
||||||
|
|
|
@ -34,8 +34,9 @@ module Travis::API::V3
|
||||||
|
|
||||||
resource :user do
|
resource :user do
|
||||||
route '/user'
|
route '/user'
|
||||||
get :current
|
get :current
|
||||||
get :find, '/{user.id}'
|
get :find, '/{user.id}'
|
||||||
|
post :sync, '/{user.id}/sync'
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :organization do
|
resource :organization do
|
||||||
|
|
7
lib/travis/api/v3/services/user/sync.rb
Normal file
7
lib/travis/api/v3/services/user/sync.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Services::User::Sync < Service
|
||||||
|
def run!
|
||||||
|
query.sync if access_control.writable? find
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
27
lib/travis/api/v3/sidekiq.rb
Normal file
27
lib/travis/api/v3/sidekiq.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Sidekiq
|
||||||
|
def self.client(value = nil)
|
||||||
|
@client = value if value
|
||||||
|
@client ||= defined?(super) ? super : ::Sidekiq::Client.default
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_accessor :class_name, :queue, :identifier
|
||||||
|
attr_writer :client
|
||||||
|
|
||||||
|
def initialize(identifier, class_name: nil, queue: nil, client: nil)
|
||||||
|
@identifier = identifier
|
||||||
|
@class_name = class_name || identifier
|
||||||
|
@class_name = "Travis::Sidekiq::%s".freeze % @class_name.to_s.camelcase if @class_name.is_a? Symbol
|
||||||
|
@queue = queue.to_s || "default".freeze
|
||||||
|
@client = client
|
||||||
|
end
|
||||||
|
|
||||||
|
def client
|
||||||
|
@client || self.class.client
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform_async(*args)
|
||||||
|
client.push('queue'.freeze => queue, 'class'.freeze => class_name, 'args'.freeze => args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
8
lib/travis/api/v3/sidekiqs.rb
Normal file
8
lib/travis/api/v3/sidekiqs.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
module Sidekiqs
|
||||||
|
extend ConstantResolver
|
||||||
|
|
||||||
|
BuildRequest = Sidekiq.new(:build_request, queue: :build_requests)
|
||||||
|
SyncUser = Sidekiq.new(:synchronize_user, queue: :user_sync)
|
||||||
|
end
|
||||||
|
end
|
|
@ -104,7 +104,11 @@ describe Travis::API::V3::ServiceIndex do
|
||||||
"find"=>
|
"find"=>
|
||||||
[{"@type"=>"template",
|
[{"@type"=>"template",
|
||||||
"request_method"=>"GET",
|
"request_method"=>"GET",
|
||||||
"uri_template"=>"#{path}user/{user.id}"}]},
|
"uri_template"=>"#{path}user/{user.id}"}],
|
||||||
|
"sync"=>
|
||||||
|
[{"@type"=>"template",
|
||||||
|
"request_method"=>"POST",
|
||||||
|
"uri_template"=>"#{path}user/{user.id}/sync"}]},
|
||||||
"attributes"=>["id", "login", "name", "github_id", "is_syncing", "synced_at"]}}
|
"attributes"=>["id", "login", "name", "github_id", "is_syncing", "synced_at"]}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
spec/v3/services/user/sync_spec.rb
Normal file
35
spec/v3/services/user/sync_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::API::V3::Services::User::Find do
|
||||||
|
let(:user) { User.find_by_login('svenfuchs') }
|
||||||
|
|
||||||
|
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) }
|
||||||
|
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
||||||
|
|
||||||
|
before do
|
||||||
|
Travis::Features.stubs(:owner_active?).returns(true)
|
||||||
|
@original_sidekiq = Sidekiq::Client
|
||||||
|
Sidekiq.send(:remove_const, :Client) # to avoid a warning
|
||||||
|
Sidekiq::Client = []
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Sidekiq.send(:remove_const, :Client) # to avoid a warning
|
||||||
|
Sidekiq::Client = @original_sidekiq
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "authenticated as user with access" do
|
||||||
|
before { post("/v3/user/#{user.id}/sync", {}, headers) }
|
||||||
|
example { expect(last_response.status).to be 202 }
|
||||||
|
# example { expect(JSON.load(body)).to be == {
|
||||||
|
# "@type" => "user",
|
||||||
|
# "@href" => "/v3/user/#{user.id}",
|
||||||
|
# "id" => user.id,
|
||||||
|
# "login" => "svenfuchs",
|
||||||
|
# "name" =>"Sven Fuchs",
|
||||||
|
# "github_id" => user.github_id,
|
||||||
|
# "is_syncing" => user.is_syncing,
|
||||||
|
# "synced_at" => user.synced_at
|
||||||
|
# }}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user