Commit 36e7ffea authored by Tomasz Maczukin's avatar Tomasz Maczukin

Fix runners filtering

parent 97c88966
...@@ -9,7 +9,7 @@ module API ...@@ -9,7 +9,7 @@ module API
# Example Request: # Example Request:
# GET /runners # GET /runners
get do get do
runners = filter_runners(current_user.ci_authorized_runners, params[:scope]) runners = filter_runners(current_user.ci_authorized_runners, params[:scope], without: ['specific', 'shared'])
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Runner
end end
...@@ -124,10 +124,14 @@ module API ...@@ -124,10 +124,14 @@ module API
end end
helpers do helpers do
def filter_runners(runners, scope) def filter_runners(runners, scope, options = {})
return runners unless scope.present? return runners unless scope.present?
available_scopes = ::Ci::Runner::AVAILABLE_SCOPES available_scopes = ::Ci::Runner::AVAILABLE_SCOPES
if options[:without]
available_scopes = available_scopes - options[:without]
end
if (available_scopes & [scope]).empty? if (available_scopes & [scope]).empty?
render_api_error!('Scope contains invalid value', 400) render_api_error!('Scope contains invalid value', 400)
end end
......
...@@ -33,7 +33,7 @@ describe API::API, api: true do ...@@ -33,7 +33,7 @@ describe API::API, api: true do
end end
it 'should filter runners by scope' do it 'should filter runners by scope' do
get api('/runners?scope=specific', user) get api('/runners?scope=active', user)
shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr} shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr}
expect(response.status).to eq(200) expect(response.status).to eq(200)
...@@ -78,7 +78,7 @@ describe API::API, api: true do ...@@ -78,7 +78,7 @@ describe API::API, api: true do
end end
it 'should filter runners by scope' do it 'should filter runners by scope' do
get api('/runners?scope=specific', admin) get api('/runners/all?scope=specific', admin)
shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr} shared = false || json_response.map{ |r| r['is_shared'] }.inject{ |sum, shr| sum || shr}
expect(response.status).to eq(200) expect(response.status).to eq(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment