Skip to content
Snippets Groups Projects
Unverified Commit 2039c828 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

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.
parent 91c40973
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Showing
with 129 additions and 7 deletions
Loading
Loading
@@ -24,6 +24,7 @@ class SnippetsController < ApplicationController
layout 'snippets'
respond_to :html
 
# rubocop: disable CodeReuse/ActiveRecord
def index
if params[:username].present?
@user = User.find_by(username: params[:username])
Loading
Loading
@@ -38,6 +39,7 @@ class SnippetsController < ApplicationController
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def new
@snippet = PersonalSnippet.new
Loading
Loading
@@ -94,9 +96,11 @@ class SnippetsController < ApplicationController
 
protected
 
# rubocop: disable CodeReuse/ActiveRecord
def snippet
@snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
 
alias_method :awardable, :snippet
alias_method :spammable, :snippet
Loading
Loading
Loading
Loading
@@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController
 
private
 
# rubocop: disable CodeReuse/ActiveRecord
def ensure_callout
current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def feature_name
params.require(:feature_name)
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ class Admin::ProjectsFinder
@current_user = current_user
end
 
# rubocop: disable CodeReuse/ActiveRecord
def execute
items = Project.without_deleted.with_statistics.with_route
items = by_namespace_id(items)
Loading
Loading
@@ -19,6 +20,7 @@ class Admin::ProjectsFinder
items = items.includes(namespace: [:owner, :route])
sort(items).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
@@ -26,9 +28,11 @@ class Admin::ProjectsFinder
params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items
end
 
# rubocop: disable CodeReuse/ActiveRecord
def by_visibilty_level(items)
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
end
# rubocop: enable CodeReuse/ActiveRecord
 
def by_with_push(items)
params[:with_push].present? ? items.with_push : items
Loading
Loading
@@ -38,9 +42,11 @@ class Admin::ProjectsFinder
params[:abandoned].present? ? items.abandoned : items
end
 
# rubocop: disable CodeReuse/ActiveRecord
def by_last_repository_check_failed(items)
params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items
end
# rubocop: enable CodeReuse/ActiveRecord
 
def by_archived(items)
if params[:archived] == 'only'
Loading
Loading
Loading
Loading
@@ -44,6 +44,7 @@ module Autocomplete
# Returns the users based on the input parameters, as an Array.
#
# This method is separate so it is easier to extend in EE.
# rubocop: disable CodeReuse/ActiveRecord
def limited_users
# When changing the order of these method calls, make sure that
# reorder_by_name() is called _before_ optionally_search(), otherwise
Loading
Loading
@@ -61,6 +62,7 @@ module Autocomplete
.limit(LIMIT)
.to_a
end
# rubocop: enable CodeReuse/ActiveRecord
 
def prepend_current_user?
filter_by_current_user.present? && current_user
Loading
Loading
@@ -70,6 +72,7 @@ module Autocomplete
author_id.present? && current_user
end
 
# rubocop: disable CodeReuse/ActiveRecord
def find_users
if project
project.authorized_users.union_with_user(author_id)
Loading
Loading
@@ -81,5 +84,6 @@ module Autocomplete
User.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
module CustomAttributesFilter
# rubocop: disable CodeReuse/ActiveRecord
def by_custom_attributes(items)
return items unless params[:custom_attributes].is_a?(Hash)
return items unless Ability.allowed?(current_user, :read_custom_attribute)
Loading
Loading
@@ -17,4 +18,5 @@ module CustomAttributesFilter
scope.where('EXISTS (?)', custom_attributes.where(key: key, value: value))
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
module FinderMethods
# rubocop: disable CodeReuse/ActiveRecord
def find_by!(*args)
raise_not_found_unless_authorized execute.find_by!(*args)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def find_by(*args)
if_authorized execute.find_by(*args)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def find(*args)
raise_not_found_unless_authorized model.find(*args)
Loading
Loading
Loading
Loading
@@ -14,6 +14,7 @@ module FinderWithCrossProjectAccess
end
 
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(*args)
check = Gitlab::CrossProjectAccess.find_check(self)
original = super
Loading
Loading
@@ -27,6 +28,7 @@ module FinderWithCrossProjectAccess
original
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
# We can skip the cross project check for finding indivitual records.
# this would be handled by the `can?(:read_*, result)` call in `FinderMethods`
Loading
Loading
Loading
Loading
@@ -10,11 +10,13 @@ class ContributedProjectsFinder < UnionFinder
# visible by this user.
#
# Returns an ActiveRecord::Relation.
# rubocop: disable CodeReuse/ActiveRecord
def execute(current_user = nil)
segments = all_projects(current_user)
 
find_union(segments, Project).includes(:namespace).order_id_desc
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
Loading
Loading
@@ -5,6 +5,7 @@ class EnvironmentsFinder
@project, @current_user, @params = project, current_user, params
end
 
# rubocop: disable CodeReuse/ActiveRecord
def execute
deployments = project.deployments
deployments =
Loading
Loading
@@ -42,6 +43,7 @@ class EnvironmentsFinder
 
environments
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
Loading
Loading
@@ -36,32 +36,42 @@ class EventsFinder
 
private
 
# rubocop: disable CodeReuse/ActiveRecord
def by_current_user_access(events)
events.merge(ProjectsFinder.new(current_user: current_user).execute)
events.merge(ProjectsFinder.new(current_user: current_user).execute) # rubocop: disable CodeReuse/Finder
.joins(:project)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def by_action(events)
return events unless Event::ACTIONS[params[:action]]
 
events.where(action: Event::ACTIONS[params[:action]])
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def by_target_type(events)
return events unless Event::TARGET_TYPES[params[:target_type]]
 
events.where(target_type: Event::TARGET_TYPES[params[:target_type]])
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_before(events)
return events unless params[:before]
 
events.where('events.created_at < ?', params[:before].beginning_of_day)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_after(events)
return events unless params[:after]
 
events.where('events.created_at > ?', params[:after].end_of_day)
end
# rubocop: enable CodeReuse/ActiveRecord
end
class ForkProjectsFinder < ProjectsFinder
# rubocop: disable CodeReuse/ActiveRecord
def initialize(project, params: {}, current_user: nil)
project_ids = project.forks.includes(:creator).select(:id)
super(params: params, current_user: current_user, project_ids_relation: project_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -61,12 +61,16 @@ class GroupDescendantsFinder
end
 
def direct_child_groups
# rubocop: disable CodeReuse/Finder
GroupsFinder.new(current_user,
parent: parent_group,
all_available: true).execute
# rubocop: enable CodeReuse/Finder
end
 
# rubocop: disable CodeReuse/ActiveRecord
def all_visible_descendant_groups
# rubocop: disable CodeReuse/Finder
groups_table = Group.arel_table
visible_to_user = groups_table[:visibility_level]
.in(Gitlab::VisibilityLevel.levels_for_user(current_user))
Loading
Loading
@@ -84,7 +88,9 @@ class GroupDescendantsFinder
hierarchy_for_parent
.descendants
.where(visible_to_user)
# rubocop: enable CodeReuse/Finder
end
# rubocop: enable CodeReuse/ActiveRecord
 
def subgroups_matching_filter
all_visible_descendant_groups
Loading
Loading
@@ -101,24 +107,29 @@ class GroupDescendantsFinder
#
# So when searching 'project', on the 'subgroup' page we want to preload
# 'nested-group' but not 'subgroup' or 'root'
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_groups(base_for_ancestors)
group_ids = base_for_ancestors.except(:select, :sort).select(:id)
Gitlab::GroupHierarchy.new(Group.where(id: group_ids))
.base_and_ancestors(upto: parent_group.id)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_filtered_projects
projects_to_load_ancestors_of = projects.where.not(namespace: parent_group)
groups_to_load_ancestors_of = Group.where(id: projects_to_load_ancestors_of.select(:namespace_id))
ancestors_of_groups(groups_to_load_ancestors_of)
.with_selects_for_list(archived: params[:archived])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def ancestors_of_filtered_subgroups
ancestors_of_groups(subgroups)
.with_selects_for_list(archived: params[:archived])
end
 
# rubocop: disable CodeReuse/ActiveRecord
def subgroups
return Group.none unless Group.supports_nested_groups?
 
Loading
Loading
@@ -132,22 +143,29 @@ class GroupDescendantsFinder
 
groups.with_selects_for_list(archived: params[:archived]).order_by(sort)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/Finder
def direct_child_projects
GroupProjectsFinder.new(group: parent_group, current_user: current_user, params: params, options: { only_owned: true })
.execute
end
# rubocop: enable CodeReuse/Finder
 
# Finds all projects nested under `parent_group` or any of its descendant
# groups
# rubocop: disable CodeReuse/ActiveRecord
def projects_matching_filter
# rubocop: disable CodeReuse/Finder
projects_nested_in_group = Project.where(namespace_id: hierarchy_for_parent.base_and_descendants.select(:id))
params_with_search = params.merge(search: params[:filter])
 
ProjectsFinder.new(params: params_with_search,
current_user: current_user,
project_ids_relation: projects_nested_in_group).execute
# rubocop: enable CodeReuse/Finder
end
# rubocop: enable CodeReuse/ActiveRecord
 
def projects
projects = if params[:filter]
Loading
Loading
@@ -163,7 +181,9 @@ class GroupDescendantsFinder
params.fetch(:sort, 'id_asc')
end
 
# rubocop: disable CodeReuse/ActiveRecord
def hierarchy_for_parent
@hierarchy ||= Gitlab::GroupHierarchy.new(Group.where(id: parent_group.id))
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -5,6 +5,7 @@ class GroupFinder
@current_user = current_user
end
 
# rubocop: disable CodeReuse/ActiveRecord
def execute(*params)
group = Group.find_by(*params)
 
Loading
Loading
@@ -14,4 +15,5 @@ class GroupFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -3,6 +3,7 @@ class GroupMembersFinder
@group = group
end
 
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false)
group_members = @group.members
wheres = []
Loading
Loading
@@ -29,4 +30,5 @@ class GroupMembersFinder
 
GroupMember.where(wheres.join(' OR '))
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -82,6 +82,7 @@ class GroupProjectsFinder < ProjectsFinder
options.fetch(:include_subgroups, false)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def owned_projects
if include_subgroups?
Project.where(namespace_id: group.self_and_descendants.select(:id))
Loading
Loading
@@ -89,6 +90,7 @@ class GroupProjectsFinder < ProjectsFinder
group.projects
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def shared_projects
group.shared_projects
Loading
Loading
Loading
Loading
@@ -38,6 +38,7 @@ class GroupsFinder < UnionFinder
 
attr_reader :current_user, :params
 
# rubocop: disable CodeReuse/ActiveRecord
def all_groups
return [owned_groups] if params[:owned]
return [groups_with_min_access_level] if min_access_level?
Loading
Loading
@@ -49,6 +50,7 @@ class GroupsFinder < UnionFinder
groups << Group.none if groups.empty?
groups
end
# rubocop: enable CodeReuse/ActiveRecord
 
def groups_for_ancestors
current_user.authorized_groups
Loading
Loading
@@ -58,6 +60,7 @@ class GroupsFinder < UnionFinder
current_user.groups
end
 
# rubocop: disable CodeReuse/ActiveRecord
def groups_with_min_access_level
groups = current_user
.groups
Loading
Loading
@@ -67,16 +70,21 @@ class GroupsFinder < UnionFinder
.new(groups)
.base_and_descendants
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def by_parent(groups)
return groups unless params[:parent]
 
groups.where(parent: params[:parent])
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def owned_groups
current_user&.owned_groups || Group.none
end
# rubocop: enable CodeReuse/ActiveRecord
 
def include_public_groups?
current_user.nil? || all_available?
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
@@ -132,6 +133,7 @@ class IssuableFinder
 
counts.with_indifferent_access
end
# rubocop: enable CodeReuse/ActiveRecord
 
def group
return @group if defined?(@group)
Loading
Loading
@@ -157,6 +159,7 @@ class IssuableFinder
@project = project
end
 
# rubocop: disable CodeReuse/ActiveRecord
def projects(items = nil)
return @projects = project if project?
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
 
Loading
Loading
@@ -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?
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
 
Loading
Loading
@@ -250,6 +259,7 @@ class IssuableFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def author_id?
params[:author_id].present? && params[:author_id] != NONE
Loading
Loading
@@ -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)
 
Loading
Loading
@@ -276,6 +287,7 @@ class IssuableFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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?
Loading
Loading
@@ -303,6 +317,7 @@ class IssuableFinder
items
end
 
# rubocop: disable CodeReuse/ActiveRecord
def by_state(items)
case params[:state].to_s
when 'closed'
Loading
Loading
@@ -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?
Loading
Loading
@@ -335,6 +352,7 @@ class IssuableFinder
 
items
end
# rubocop: enable CodeReuse/ActiveRecord
 
def use_cte_for_search?
return false unless search
Loading
Loading
@@ -343,6 +361,7 @@ class IssuableFinder
params[:use_cte_for_search]
end
 
# rubocop: disable CodeReuse/ActiveRecord
def by_search(items)
return items unless search
 
Loading
Loading
@@ -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)
Loading
Loading
@@ -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)
Loading
Loading
@@ -389,6 +416,7 @@ class IssuableFinder
 
items
end
# rubocop: enable CodeReuse/ActiveRecord
 
def filter_by_upcoming_milestone?
params[:milestone_title] == Milestone::Upcoming.name
Loading
Loading
@@ -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?
Loading
Loading
@@ -414,6 +443,7 @@ class IssuableFinder
 
items
end
# rubocop: enable CodeReuse/ActiveRecord
 
def by_label(items)
return items unless labels?
Loading
Loading
Loading
Loading
@@ -29,10 +29,13 @@ class IssuesFinder < IssuableFinder
@scalar_params ||= super + [:due_date]
end
 
# rubocop: disable CodeReuse/ActiveRecord
def klass
Issue.includes(:author)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def with_confidentiality_access_check
return Issue.all if user_can_see_all_confidential_issues?
return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues?
Loading
Loading
@@ -46,6 +49,7 @@ class IssuesFinder < IssuableFinder
user_id: current_user.id,
project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id))
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
@@ -125,6 +129,7 @@ class IssuesFinder < IssuableFinder
current_user.blank?
end
 
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items)
if assignee
items.assigned_to(assignee)
Loading
Loading
@@ -136,4 +141,5 @@ class IssuesFinder < IssuableFinder
items
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -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
Loading
Loading
@@ -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 = []
 
Loading
Loading
@@ -52,17 +55,22 @@ class LabelsFinder < UnionFinder
 
label_ids
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def sort(items)
items.reorder(title: :asc)
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?
Loading
Loading
@@ -134,13 +142,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?
Loading
Loading
@@ -149,6 +158,7 @@ class LabelsFinder < UnionFinder
 
@projects
end
# rubocop: enable CodeReuse/ActiveRecord
 
def authorized_to_read_labels?(label_parent)
return true if skip_authorization
Loading
Loading
Loading
Loading
@@ -7,12 +7,13 @@ class MembersFinder
@group = project.group
end
 
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false)
project_members = project.project_members
project_members = project_members.non_invite unless can?(current_user, :admin_project, project)
 
if group
group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants)
group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants) # rubocop: disable CodeReuse/Finder
group_members = group_members.non_invite
 
union = Gitlab::SQL::Union.new([project_members, group_members], remove_duplicates: false)
Loading
Loading
@@ -24,6 +25,7 @@ class MembersFinder
project_members
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def can?(*args)
Ability.allowed?(*args)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment