V3 add user/:id/sync endpoint
This commit is contained in:
parent
b923b21252
commit
26b1d85d43
|
@ -34,6 +34,7 @@ module Travis
|
|||
ServerError = Error .create(status: 500)
|
||||
NotImplemented = ServerError .create('request not (yet) implemented', status: 501)
|
||||
RequestLimitReached = ClientError .create('request limit reached for resource', status: 429)
|
||||
AlreadySyncing = ClientError .create('sync already in progress', status: 409)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,6 +75,10 @@ module Travis::API::V3
|
|||
unrestricted_api?
|
||||
end
|
||||
|
||||
def user_writable?(user)
|
||||
self.user == user
|
||||
end
|
||||
|
||||
def repository_visible?(repository)
|
||||
return true if unrestricted_api? and not repository.private?
|
||||
private_repository_visible?(repository)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Travis::API::V3
|
||||
class Queries::User < Query
|
||||
params :id, :login, :email, :github_id
|
||||
params :id, :login, :email, :github_id, :is_syncing
|
||||
|
||||
def find
|
||||
return Models::User.find_by_id(id) if id
|
||||
|
@ -17,5 +17,12 @@ module Travis::API::V3
|
|||
User.find_by_email(email)
|
||||
end
|
||||
end
|
||||
|
||||
def sync(user)
|
||||
raise AlreadySyncing if user.is_syncing?
|
||||
perform_async(:user_sync, user.id)
|
||||
user.update_column(:is_syncing, true)
|
||||
user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,7 @@ module Travis::API::V3
|
|||
route '/user'
|
||||
get :current
|
||||
get :find, '/{user.id}'
|
||||
post :sync, '/{user.id}/sync'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
12
lib/travis/api/v3/services/user/sync.rb
Normal file
12
lib/travis/api/v3/services/user/sync.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module Travis::API::V3
|
||||
class Services::User::Sync < Service
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless user = find(:user)
|
||||
access_control.permissions(user).sync!
|
||||
|
||||
query.sync(user)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user