summaryrefslogtreecommitdiff
path: root/app/finders/labels_finder.rb
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-09-13 14:53:05 +0000
committerRobert Speicher <robert@gitlab.com>2018-09-13 14:53:05 +0000
commitc7d1eef671dbf598814a6c2ff1f81b924583ae8a (patch)
tree23988df1d29e933943858a66821ba7f493976b3e /app/finders/labels_finder.rb
parentff5d8b635f234241441009e41af7b61f5804b2c2 (diff)
parent2039c8280db1646845c33d6c5a74e5f23ca6f4de (diff)
downloadgitlab-ce-c7d1eef671dbf598814a6c2ff1f81b924583ae8a.tar.gz
Merge branch 'rubocop-code-reuse' into 'master'
Add RuboCop cops to enforce code reusing rules See merge request gitlab-org/gitlab-ce!21391
Diffstat (limited to 'app/finders/labels_finder.rb')
-rw-r--r--app/finders/labels_finder.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 8418577dab2..17c55f8db50 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -10,6 +10,7 @@ class LabelsFinder < UnionFinder
@params = params
end
+ # rubocop: disable CodeReuse/ActiveRecord
def execute(skip_authorization: false)
@skip_authorization = skip_authorization
items = find_union(label_ids, Label) || Label.none
@@ -17,11 +18,13 @@ class LabelsFinder < UnionFinder
items = by_search(items)
sort(items)
end
+ # rubocop: enable CodeReuse/ActiveRecord
private
attr_reader :current_user, :params, :skip_authorization
+ # rubocop: disable CodeReuse/ActiveRecord
def label_ids
label_ids = []
@@ -52,7 +55,9 @@ class LabelsFinder < UnionFinder
label_ids
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def sort(items)
if params[:sort]
items.order_by(params[:sort])
@@ -60,13 +65,16 @@ class LabelsFinder < UnionFinder
items.reorder(title: :asc)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def with_title(items)
return items if title.nil?
return items.none if title.blank?
items.where(title: title)
end
+ # rubocop: enable CodeReuse/ActiveRecord
def by_search(labels)
return labels unless search?
@@ -138,13 +146,14 @@ class LabelsFinder < UnionFinder
@project
end
+ # rubocop: disable CodeReuse/ActiveRecord
def projects
return @projects if defined?(@projects)
@projects = if skip_authorization
Project.all
else
- ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute
+ ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute # rubocop: disable CodeReuse/Finder
end
@projects = @projects.in_namespace(params[:group_id]) if group?
@@ -153,6 +162,7 @@ class LabelsFinder < UnionFinder
@projects
end
+ # rubocop: enable CodeReuse/ActiveRecord
def authorized_to_read_labels?(label_parent)
return true if skip_authorization