Fix Issuable#add_labels_by_names to validate if label exists on group

parent b654229d
...@@ -235,9 +235,19 @@ module Issuable ...@@ -235,9 +235,19 @@ module Issuable
end end
def add_labels_by_names(label_names) def add_labels_by_names(label_names)
label_ids = []
label_ids << project.group.labels.select(:id) if project.group.present?
label_ids << project.labels.select(:id)
union = Gitlab::SQL::Union.new(label_ids)
available_labels = Label.where("labels.id IN (#{union.to_sql})")
label_names.each do |label_name| label_names.each do |label_name|
label = project.labels.create_with(color: Label::DEFAULT_COLOR). title = label_name.strip
find_or_create_by(title: label_name.strip) label = available_labels.find_by(title: title)
label = project.labels.build(title: title, color: Label::DEFAULT_COLOR) if label.nil?
self.labels << label self.labels << label
end end
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