summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDylan Griffith <dyl.griffith@gmail.com>2018-05-11 12:03:40 +0200
committerDylan Griffith <dyl.griffith@gmail.com>2018-05-31 10:46:19 +0200
commitab489d293d6ee3e30673817ce4652c7b413988c0 (patch)
treee197ccd80fefd1f4ae610e96efeebf139c69b302 /app
parentec1d3e104afddf7c8a5f6f5d8bf1ffee99a8f551 (diff)
downloadgitlab-ce-ab489d293d6ee3e30673817ce4652c7b413988c0.tar.gz
Improve runner_type validations for Ci::Runner
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/runner.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 530eacf4be0..2119b70c18c 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -56,7 +56,9 @@ module Ci
end
validate :tag_constraints
- validate :either_projects_or_group
+ validate :no_projects, unless: :project_type?
+ validate :no_groups, unless: :group_type?
+ validate :only_one_group, if: :group_type?
validates :access_level, presence: true
validates :runner_type, presence: true
@@ -253,13 +255,21 @@ module Ci
self.class.owned_or_shared(project_id).where(id: self.id).any?
end
- def either_projects_or_group
- if groups.many?
- errors.add(:runner, 'can only be assigned to one group')
+ def no_projects
+ if projects.any?
+ errors.add(:runner, 'cannot assign project to a non-project runner')
+ end
+ end
+
+ def no_groups
+ if groups.any?
+ errors.add(:runner, 'cannot assign group to a non-group runner')
end
+ end
- if assigned_to_group? && assigned_to_project?
- errors.add(:runner, 'can only be assigned either to projects or to a group')
+ def only_one_group
+ if groups.many?
+ errors.add(:runner, 'can only be assigned to one group')
end
end