Check for repository owner instead of current user to validate feature flag
This commit is contained in:
parent
cf5ea374d4
commit
69cc2eef7d
|
@ -22,9 +22,10 @@ class Travis::Api::App
|
||||||
post '/:id/cancel' do
|
post '/:id/cancel' do
|
||||||
Metriks.meter("api.request.cancel_build").mark
|
Metriks.meter("api.request.cancel_build").mark
|
||||||
|
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, current_user)
|
service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] })
|
||||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] })
|
repository_owner = service.target.repository.owner
|
||||||
else
|
|
||||||
|
if !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||||
service = self.service(:cancel_build, params.merge(source: 'api'))
|
service = self.service(:cancel_build, params.merge(source: 'api'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,10 +61,11 @@ class Travis::Api::App
|
||||||
|
|
||||||
post '/:id/restart' do
|
post '/:id/restart' do
|
||||||
Metriks.meter("api.request.restart_build").mark
|
Metriks.meter("api.request.restart_build").mark
|
||||||
service = if Travis::Features.owner_active?(:enqueue_to_hub, current_user)
|
service = Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id])
|
||||||
Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id])
|
repository_owner = service.target.repository.owner
|
||||||
else
|
|
||||||
self.service(:reset_model, build_id: params[:id])
|
if !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||||
|
service = self.service(:reset_model, build_id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
result = if !service.accept?
|
result = if !service.accept?
|
||||||
|
|
|
@ -29,9 +29,9 @@ class Travis::Api::App
|
||||||
post '/:id/cancel' do
|
post '/:id/cancel' do
|
||||||
Metriks.meter("api.request.cancel_job").mark
|
Metriks.meter("api.request.cancel_job").mark
|
||||||
|
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, current_user)
|
service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] })
|
||||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] })
|
repository_owner = service.target.repository.owner
|
||||||
else
|
if !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||||
service = self.service(:cancel_job, params.merge(source: 'api'))
|
service = self.service(:cancel_job, params.merge(source: 'api'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ class Travis::Api::App
|
||||||
post '/:id/restart' do
|
post '/:id/restart' do
|
||||||
Metriks.meter("api.request.restart_job").mark
|
Metriks.meter("api.request.restart_job").mark
|
||||||
|
|
||||||
service = if Travis::Features.owner_active?(:enqueue_to_hub, current_user)
|
service = Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] })
|
||||||
Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] })
|
repository_owner = service.target.repository.owner
|
||||||
else
|
if !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||||
self.service(:reset_model, job_id: params[:id])
|
service = self.service(:reset_model, job_id: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
result = if !service.accept?
|
result = if !service.accept?
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Travis::API::V3
|
||||||
def cancel(user)
|
def cancel(user)
|
||||||
raise BuildNotCancelable if %w(passed failed canceled errored).include? find.state
|
raise BuildNotCancelable if %w(passed failed canceled errored).include? find.state
|
||||||
payload = { id: id, user_id: user.id, source: 'api' }
|
payload = { id: id, user_id: user.id, source: 'api' }
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, user)
|
if Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||||
service = Travis::Enqueue::Services::CancelModel.new(user, { build_id: id })
|
service = Travis::Enqueue::Services::CancelModel.new(user, { build_id: id })
|
||||||
service.push("build:cancel", payload)
|
service.push("build:cancel", payload)
|
||||||
else
|
else
|
||||||
|
@ -24,7 +24,7 @@ module Travis::API::V3
|
||||||
|
|
||||||
def restart(user)
|
def restart(user)
|
||||||
raise BuildAlreadyRunning if %w(received queued started).include? find.state
|
raise BuildAlreadyRunning if %w(received queued started).include? find.state
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, user)
|
if Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||||
service = Travis::Enqueue::Services::RestartModel.new(user, { build_id: id })
|
service = Travis::Enqueue::Services::RestartModel.new(user, { build_id: id })
|
||||||
payload = { id: id, user_id: user.id }
|
payload = { id: id, user_id: user.id }
|
||||||
service.push("build:restart", payload)
|
service.push("build:restart", payload)
|
||||||
|
|
|
@ -13,7 +13,8 @@ module Travis::API::V3
|
||||||
def cancel(user)
|
def cancel(user)
|
||||||
raise JobNotCancelable if %w(passed failed canceled errored).include? find.state
|
raise JobNotCancelable if %w(passed failed canceled errored).include? find.state
|
||||||
payload = { id: id, user_id: user.id, source: 'api' }
|
payload = { id: id, user_id: user.id, source: 'api' }
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, user)
|
#look for repo.owner instead and look if the user belongs to the repo, instead of using user for the feature flag
|
||||||
|
if Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||||
service = Travis::Enqueue::Services::CancelModel.new(user, { job_id: id })
|
service = Travis::Enqueue::Services::CancelModel.new(user, { job_id: id })
|
||||||
service.push("job:cancel", payload)
|
service.push("job:cancel", payload)
|
||||||
else
|
else
|
||||||
|
@ -25,7 +26,7 @@ module Travis::API::V3
|
||||||
def restart(user)
|
def restart(user)
|
||||||
raise JobAlreadyRunning if %w(received queued started).include? find.state
|
raise JobAlreadyRunning if %w(received queued started).include? find.state
|
||||||
|
|
||||||
if Travis::Features.owner_active?(:enqueue_to_hub, user)
|
if Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||||
service = Travis::Enqueue::Services::RestartModel.new(user, { job_id: id })
|
service = Travis::Enqueue::Services::RestartModel.new(user, { job_id: id })
|
||||||
payload = { id: id, user_id: user.id }
|
payload = { id: id, user_id: user.id }
|
||||||
service.push("job:restart", payload)
|
service.push("job:restart", payload)
|
||||||
|
|
|
@ -13,7 +13,6 @@ module Travis
|
||||||
user = User.find(data['user_id'])
|
user = User.find(data['user_id'])
|
||||||
Travis.service(:cancel_job, user, { id: data['id'], source: data['source'] }).run
|
Travis.service(:cancel_job, user, { id: data['id'], source: data['source'] }).run
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user