summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-10-23 16:46:21 -0700
committerStan Hu <stanhu@gmail.com>2016-10-24 22:40:08 -0700
commitddafea060d4b607cd3f5c29e947cdbf6483dcd5d (patch)
tree18228dce12f544994f1c77d448a76a18fd8eb7d2
parentadd3a2c4431f29ca84c956f5604769505f0f0904 (diff)
downloadgitlab-ce-ddafea060d4b607cd3f5c29e947cdbf6483dcd5d.tar.gz
Fix bug where labels would be assigned to issues that were moved
If you attempt to move an issue from one project to another and leave labels blank, LabelsFinder would assign all labels in the new project to that issue. The issue is that :title is passed along to the Finder, but since it appears empty no filtering is done. As a result, all labels in the group are returned. This fix handles that case. Closes #23668
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/finders/labels_finder.rb4
-rw-r--r--spec/finders/labels_finder_spec.rb6
3 files changed, 11 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86878e5af6c..1e2150b9ca7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Refactor email, use setter method instead AR callbacks for email attribute (Semyon Pupkov)
## 8.13.1 (unreleased)
+ - Fix bug where labels would be assigned to issues that were moved
- Fix error in generating labels
- Fix reply-by-email not working due to queue name mismatch
- Fixed hidden pipeline graph on commit and MR page !6895
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 6ace14a4bb5..2291c64b84d 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -35,6 +35,10 @@ class LabelsFinder < UnionFinder
end
def with_title(items)
+ # Match no labels if an empty title is supplied to avoid matching all
+ # labels (e.g. when an issue is moved)
+ return Label.none if params[:title] && params[:title].empty?
+
items = items.where(title: title) if title
items
end
diff --git a/spec/finders/labels_finder_spec.rb b/spec/finders/labels_finder_spec.rb
index 27acc464ea2..114399ea3dc 100644
--- a/spec/finders/labels_finder_spec.rb
+++ b/spec/finders/labels_finder_spec.rb
@@ -64,6 +64,12 @@ describe LabelsFinder do
expect(finder.execute).to eq [group_label_2]
end
+
+ it 'returns no labels if empty titles are supplied' do
+ finder = described_class.new(user, title: [])
+
+ expect(finder.execute).to be_empty
+ end
end
end
end