summaryrefslogtreecommitdiff
path: root/app/models/project_label.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-14 18:51:34 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:27 -0200
commit99e928f103182b58156edb107b55344eaafc6772 (patch)
tree744fdb8be884826e861090821675476d26a496fd /app/models/project_label.rb
parent67314e95ae836365fa1989439a6379aac781a0b4 (diff)
downloadgitlab-ce-99e928f103182b58156edb107b55344eaafc6772.tar.gz
Add restriction to number of permitted priorities per project label
Diffstat (limited to 'app/models/project_label.rb')
-rw-r--r--app/models/project_label.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/project_label.rb b/app/models/project_label.rb
index 5b739bcdadf..f863d442c21 100644
--- a/app/models/project_label.rb
+++ b/app/models/project_label.rb
@@ -1,8 +1,11 @@
class ProjectLabel < Label
+ NUMBER_OF_PRIORITIES = 1
+
belongs_to :project
validates :project, presence: true
+ validate :permitted_numbers_of_priorities
validate :title_must_not_exist_at_group_level
delegate :group, to: :project, allow_nil: true
@@ -20,4 +23,10 @@ class ProjectLabel < Label
errors.add(:title, :label_already_exists_at_group_level, group: group.name)
end
end
+
+ def permitted_numbers_of_priorities
+ if priorities && priorities.size >= NUMBER_OF_PRIORITIES
+ errors.add(:priorities, 'Number of permitted priorities exceeded')
+ end
+ end
end