diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-27 17:31:01 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-09-11 17:32:00 +0200 |
commit | 2039c8280db1646845c33d6c5a74e5f23ca6f4de (patch) | |
tree | e2b3cd3012d9711cda7c6afb962ae4228d59521a /app/finders/issuable_finder.rb | |
parent | 91c40973dc620430b173ea2df968587d2a708dff (diff) | |
download | gitlab-ce-2039c8280db1646845c33d6c5a74e5f23ca6f4de.tar.gz |
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
Diffstat (limited to 'app/finders/issuable_finder.rb')
-rw-r--r-- | app/finders/issuable_finder.rb | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 372e2a96c2c..3308fd6d697 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -109,6 +109,7 @@ class IssuableFinder # (even if that query is slower than any of the individual state queries) and # grouping and counting within that query. # + # rubocop: disable CodeReuse/ActiveRecord def count_by_state count_params = params.merge(state: nil, sort: nil) finder = self.class.new(current_user, count_params) @@ -132,6 +133,7 @@ class IssuableFinder counts.with_indifferent_access end + # rubocop: enable CodeReuse/ActiveRecord def group return @group if defined?(@group) @@ -157,6 +159,7 @@ class IssuableFinder @project = project end + # rubocop: disable CodeReuse/ActiveRecord def projects(items = nil) return @projects = project if project? @@ -165,13 +168,14 @@ class IssuableFinder current_user.authorized_projects elsif group finder_options = { include_subgroups: params[:include_subgroups], only_owned: true } - GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute + GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute # rubocop: disable CodeReuse/Finder else - ProjectsFinder.new(current_user: current_user).execute + ProjectsFinder.new(current_user: current_user).execute # rubocop: disable CodeReuse/Finder end @projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil) end + # rubocop: enable CodeReuse/ActiveRecord def search params[:search].presence @@ -185,6 +189,7 @@ class IssuableFinder milestones? && params[:milestone_title] == Milestone::None.title end + # rubocop: disable CodeReuse/ActiveRecord def milestones return @milestones if defined?(@milestones) @@ -200,11 +205,12 @@ class IssuableFinder search_params = { title: params[:milestone_title], project_ids: project_id, group_ids: group_id } - MilestonesFinder.new(search_params).execute + MilestonesFinder.new(search_params).execute # rubocop: disable CodeReuse/Finder else Milestone.none end end + # rubocop: enable CodeReuse/ActiveRecord def labels? params[:label_name].present? @@ -214,16 +220,18 @@ class IssuableFinder labels? && params[:label_name].include?(Label::None.title) end + # rubocop: disable CodeReuse/ActiveRecord def labels return @labels if defined?(@labels) @labels = if labels? && !filter_by_no_label? - LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true) + LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true) # rubocop: disable CodeReuse/Finder else Label.none end end + # rubocop: enable CodeReuse/ActiveRecord def assignee_id? params[:assignee_id].present? && params[:assignee_id] != NONE @@ -238,6 +246,7 @@ class IssuableFinder params[:assignee_id] == NONE || params[:assignee_username] == NONE end + # rubocop: disable CodeReuse/ActiveRecord def assignee return @assignee if defined?(@assignee) @@ -250,6 +259,7 @@ class IssuableFinder nil end end + # rubocop: enable CodeReuse/ActiveRecord def author_id? params[:author_id].present? && params[:author_id] != NONE @@ -264,6 +274,7 @@ class IssuableFinder params[:author_id] == NONE || params[:author_username] == NONE end + # rubocop: disable CodeReuse/ActiveRecord def author return @author if defined?(@author) @@ -276,6 +287,7 @@ class IssuableFinder nil end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -283,6 +295,7 @@ class IssuableFinder klass.all end + # rubocop: disable CodeReuse/ActiveRecord def by_scope(items) return items.none if current_user_related? && !current_user @@ -295,6 +308,7 @@ class IssuableFinder items end end + # rubocop: enable CodeReuse/ActiveRecord def by_updated_at(items) items = items.updated_after(params[:updated_after]) if params[:updated_after].present? @@ -303,6 +317,7 @@ class IssuableFinder items end + # rubocop: disable CodeReuse/ActiveRecord def by_state(items) case params[:state].to_s when 'closed' @@ -317,12 +332,14 @@ class IssuableFinder items end end + # rubocop: enable CodeReuse/ActiveRecord def by_group(items) # Selection by group is already covered by `by_project` and `projects` items end + # rubocop: disable CodeReuse/ActiveRecord def by_project(items) items = if project? @@ -335,6 +352,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def use_cte_for_search? return false unless search @@ -343,6 +361,7 @@ class IssuableFinder params[:use_cte_for_search] end + # rubocop: disable CodeReuse/ActiveRecord def by_search(items) return items unless search @@ -355,17 +374,23 @@ class IssuableFinder items.full_search(search) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_iids(items) params[:iids].present? ? items.where(iid: params[:iids]) : items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def sort(items) # Ensure we always have an explicit sort order (instead of inheriting # multiple orders when combining ActiveRecord::Relation objects). params[:sort] ? items.sort_by_attribute(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_assignee(items) if assignee items = items.where(assignee_id: assignee.id) @@ -377,7 +402,9 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def by_author(items) if author items = items.where(author_id: author.id) @@ -389,6 +416,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def filter_by_upcoming_milestone? params[:milestone_title] == Milestone::Upcoming.name @@ -398,6 +426,7 @@ class IssuableFinder params[:milestone_title] == Milestone::Started.name end + # rubocop: disable CodeReuse/ActiveRecord def by_milestone(items) if milestones? if filter_by_no_milestone? @@ -414,6 +443,7 @@ class IssuableFinder items end + # rubocop: enable CodeReuse/ActiveRecord def by_label(items) return items unless labels? |