v3: avoid handing repository back to the query
This commit is contained in:
parent
b6186890c4
commit
dece76ce5b
|
@ -369,6 +369,3 @@ DEPENDENCIES
|
||||||
travis-yaml!
|
travis-yaml!
|
||||||
unicorn
|
unicorn
|
||||||
yard-sinatra!
|
yard-sinatra!
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.10.6
|
|
||||||
|
|
|
@ -3,18 +3,18 @@ module Travis::API::V3
|
||||||
params :id, :slug
|
params :id, :slug
|
||||||
|
|
||||||
def find
|
def find
|
||||||
return by_slug if slug
|
@find ||= find!
|
||||||
return Models::Repository.find_by_id(id) if id
|
|
||||||
raise WrongParams, 'missing repository.id'.freeze
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def star(repository, current_user)
|
def star(current_user)
|
||||||
|
repository = find
|
||||||
starred = Models::Star.where(repository_id: repository.id, user_id: current_user.id).first
|
starred = Models::Star.where(repository_id: repository.id, user_id: current_user.id).first
|
||||||
Models::Star.create(repository_id: repository.id, user_id: current_user.id) unless starred
|
Models::Star.create(repository_id: repository.id, user_id: current_user.id) unless starred
|
||||||
repository
|
repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def unstar(repository, current_user)
|
def unstar(current_user)
|
||||||
|
repository = find
|
||||||
starred = Models::Star.where(repository_id: repository.id, user_id: current_user.id).first
|
starred = Models::Star.where(repository_id: repository.id, user_id: current_user.id).first
|
||||||
starred.delete if starred
|
starred.delete if starred
|
||||||
repository
|
repository
|
||||||
|
@ -22,6 +22,12 @@ module Travis::API::V3
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def find!
|
||||||
|
return by_slug if slug
|
||||||
|
return Models::Repository.find_by_id(id) if id
|
||||||
|
raise WrongParams, 'missing repository.id'.freeze
|
||||||
|
end
|
||||||
|
|
||||||
def by_slug
|
def by_slug
|
||||||
owner_name, name = slug.split('/')
|
owner_name, name = slug.split('/')
|
||||||
Models::Repository.where(owner_name: owner_name, name: name, invalidated_at: nil).first
|
Models::Repository.where(owner_name: owner_name, name: name, invalidated_at: nil).first
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Travis::API::V3
|
||||||
raise NotFound unless repository = find(:repository)
|
raise NotFound unless repository = find(:repository)
|
||||||
check_access(repository)
|
check_access(repository)
|
||||||
current_user = access_control.user
|
current_user = access_control.user
|
||||||
query.star(repository, current_user)
|
query.star(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_access(repository)
|
def check_access(repository)
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Travis::API::V3
|
||||||
raise NotFound unless repository = find(:repository)
|
raise NotFound unless repository = find(:repository)
|
||||||
check_access(repository)
|
check_access(repository)
|
||||||
current_user = access_control.user
|
current_user = access_control.user
|
||||||
query.unstar(repository, current_user)
|
query.unstar(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_access(repository)
|
def check_access(repository)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user