Commit f13ac937 authored by Nourdin el Bacha's avatar Nourdin el Bacha

Restrict Runner.locked to project runners

This commit introduces a Presentable, which adds the following:
- `locked` for GraphQL vue component
- `locked?` for haml component
And the specs are refactored, using TableSyntax

Changelog: fixed
parent 0ef98c4a
...@@ -5,6 +5,7 @@ module Types ...@@ -5,6 +5,7 @@ module Types
class RunnerType < BaseObject class RunnerType < BaseObject
graphql_name 'CiRunner' graphql_name 'CiRunner'
authorize :read_runner authorize :read_runner
present_using ::Ci::RunnerPresenter
JOB_COUNT_LIMIT = 1000 JOB_COUNT_LIMIT = 1000
......
...@@ -11,6 +11,7 @@ module Ci ...@@ -11,6 +11,7 @@ module Ci
include FeatureGate include FeatureGate
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include TaggableQueries include TaggableQueries
include Presentable
add_authentication_token_field :token, encrypted: :optional add_authentication_token_field :token, encrypted: :optional
......
# frozen_string_literal: true
module Ci
class RunnerPresenter < Gitlab::View::Presenter::Delegated
presents :runner
def locked?
read_attribute(:locked) && project_type?
end
alias_method :locked, :locked?
end
end
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
.table-section.section-10{ role: 'rowheader' } .table-section.section-10{ role: 'rowheader' }
- @group_runners.each do |runner| - @group_runners.each do |runner|
- runner = runner.present(current_user: current_user)
= render 'groups/runners/runner', runner: runner = render 'groups/runners/runner', runner: runner
= paginate @group_runners, theme: 'gitlab', :params => { :anchor => 'runners-settings' } = paginate @group_runners, theme: 'gitlab', :params => { :anchor => 'runners-settings' }
- else - else
......
...@@ -52,14 +52,14 @@ RSpec.describe 'Query.runner(id)' do ...@@ -52,14 +52,14 @@ RSpec.describe 'Query.runner(id)' do
'version' => runner.version, 'version' => runner.version,
'shortSha' => runner.short_sha, 'shortSha' => runner.short_sha,
'revision' => runner.revision, 'revision' => runner.revision,
'locked' => runner.locked, 'locked' => false,
'active' => runner.active, 'active' => runner.active,
'status' => runner.status.to_s.upcase, 'status' => runner.status.to_s.upcase,
'maximumTimeout' => runner.maximum_timeout, 'maximumTimeout' => runner.maximum_timeout,
'accessLevel' => runner.access_level.to_s.upcase, 'accessLevel' => runner.access_level.to_s.upcase,
'runUntagged' => runner.run_untagged, 'runUntagged' => runner.run_untagged,
'ipAddress' => runner.ip_address, 'ipAddress' => runner.ip_address,
'runnerType' => 'INSTANCE_TYPE', 'runnerType' => runner.instance_type? ? 'INSTANCE_TYPE' : 'PROJECT_TYPE',
'jobCount' => 0, 'jobCount' => 0,
'projectCount' => nil 'projectCount' => nil
) )
...@@ -109,6 +109,40 @@ RSpec.describe 'Query.runner(id)' do ...@@ -109,6 +109,40 @@ RSpec.describe 'Query.runner(id)' do
end end
end end
describe 'for project runner' do
using RSpec::Parameterized::TableSyntax
where(is_locked: [true, false])
with_them do
let(:project_runner) do
create(:ci_runner, :project, description: 'Runner 3', contacted_at: 1.day.ago, active: false, locked: is_locked,
version: 'adfe157', revision: 'b', ip_address: '10.10.10.10', access_level: 1, run_untagged: true)
end
let(:query) do
wrap_fields(query_graphql_path(query_path, all_graphql_fields_for('CiRunner')))
end
let(:query_path) do
[
[:runner, { id: project_runner.to_global_id.to_s }]
]
end
it 'retrieves correct locked value' do
post_graphql(query, current_user: user)
runner_data = graphql_data_at(:runner)
expect(runner_data).to match a_hash_including(
'id' => "gid://gitlab/Ci::Runner/#{project_runner.id}",
'locked' => is_locked
)
end
end
end
describe 'for inactive runner' do describe 'for inactive runner' do
it_behaves_like 'runner details fetch', :inactive_instance_runner it_behaves_like 'runner details fetch', :inactive_instance_runner
end end
......
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