diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-09-21 17:47:58 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 14:58:24 -0200 |
commit | e28058c4107ce454a84b3e3b5750f936dace7db1 (patch) | |
tree | 8eb12341289e76b94907a12067ad8dc85b07f71e /app/models/project_label.rb | |
parent | cfedd42badc6b84457d1de35cb31988777462d5a (diff) | |
download | gitlab-ce-e28058c4107ce454a84b3e3b5750f936dace7db1.tar.gz |
Validate if project label title does not exist at group level
Diffstat (limited to 'app/models/project_label.rb')
-rw-r--r-- | app/models/project_label.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/project_label.rb b/app/models/project_label.rb index 3e41113e340..1171aa2dbb3 100644 --- a/app/models/project_label.rb +++ b/app/models/project_label.rb @@ -2,4 +2,18 @@ class ProjectLabel < Label belongs_to :project validates :project, presence: true + + validate :title_must_not_exist_at_group_level + + delegate :group, to: :project, allow_nil: true + + private + + def title_must_not_exist_at_group_level + return unless group.present? + + if group.labels.with_title(self.title).exists? + errors.add(:title, :label_already_exists_at_group_level, group: group.name) + end + end end |