replace cond. assignment by default param value

This commit is contained in:
Alexis Reigel 2018-09-12 20:14:49 +02:00
parent 03890558b4
commit b4e2cc4421
No known key found for this signature in database
GPG Key ID: 55ADA7C7B683B329
1 changed files with 3 additions and 5 deletions

View File

@ -14,7 +14,7 @@ module API
use :pagination use :pagination
end end
get do get do
runners = filter_runners(current_user.ci_owned_runners, params[:scope], only: Ci::Runner::AVAILABLE_STATUSES) runners = filter_runners(current_user.ci_owned_runners, params[:scope], allowed_scopes: Ci::Runner::AVAILABLE_STATUSES)
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Runner
end end
@ -158,12 +158,10 @@ module API
end end
helpers do helpers do
def filter_runners(runners, scope, only: nil) def filter_runners(runners, scope, allowed_scopes: ::Ci::Runner::AVAILABLE_SCOPES)
return runners unless scope.present? return runners unless scope.present?
available_scopes = only || ::Ci::Runner::AVAILABLE_SCOPES unless allowed_scopes.include?(scope)
unless available_scopes.include?(scope)
render_api_error!('Scope contains invalid value', 400) render_api_error!('Scope contains invalid value', 400)
end end