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 60 additions and 0 deletions
Loading
Loading
@@ -89,6 +89,7 @@ module IssuableActions
render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" }
end
 
# rubocop: disable CodeReuse/ActiveRecord
def discussions
notes = issuable.discussion_notes
.inc_relations_for_view
Loading
Loading
@@ -103,6 +104,7 @@ module IssuableActions
 
render json: discussion_serializer.represent(discussions, context: self)
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
Loading
Loading
@@ -48,9 +48,11 @@ module IssuableCollections
false
end
 
# rubocop: disable CodeReuse/ActiveRecord
def issuables_collection
finder.execute.preload(preload_for_collection)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def redirect_out_of_range(total_pages)
return false if total_pages.nil? || total_pages.zero?
Loading
Loading
@@ -81,6 +83,7 @@ module IssuableCollections
end
 
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def filter_params
set_sort_order_from_cookie
set_default_state
Loading
Loading
@@ -101,6 +104,7 @@ module IssuableCollections
 
@filter_params.permit(finder_type.valid_params)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
 
def set_default_state
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ module IssuesCalendar
extend ActiveSupport::Concern
 
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_issues_calendar(issuables)
@issues = issuables
.non_archived
Loading
Loading
@@ -20,5 +21,6 @@ module IssuesCalendar
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
Loading
Loading
@@ -10,10 +10,12 @@ module MembersPresentation
).fabricate!
end
 
# rubocop: disable CodeReuse/ActiveRecord
def preload_associations(members)
ActiveRecord::Associations::Preloader.new.preload(members, :user)
ActiveRecord::Associations::Preloader.new.preload(members, :source)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations)
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -57,6 +57,7 @@ module MembershipActions
redirect_to members_page_url
end
 
# rubocop: disable CodeReuse/ActiveRecord
def leave
member = membershipable.members_and_requesters.find_by!(user_id: current_user.id)
Members::DestroyService.new(current_user).execute(member)
Loading
Loading
@@ -77,6 +78,7 @@ module MembershipActions
format.json { render json: { notice: notice } }
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def resend_invite
member = membershipable.members.find(params[:id])
Loading
Loading
Loading
Loading
@@ -13,6 +13,7 @@ module RendersMemberAccess
 
private
 
# rubocop: disable CodeReuse/ActiveRecord
def preload_max_member_access_for_collection(klass, collection)
return if !current_user || collection.blank?
 
Loading
Loading
@@ -20,4 +21,5 @@ module RendersMemberAccess
 
current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -20,9 +20,11 @@ module RendersNotes
project.team.max_member_access_for_user_ids(user_ids)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def preload_noteable_for_regular_notes(notes)
ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def preload_first_time_contribution_for_authors(noteable, notes)
return unless noteable.is_a?(Issuable) && noteable.first_contribution?
Loading
Loading
@@ -30,7 +32,9 @@ module RendersNotes
notes.each {|n| n.specialize_for_first_contribution!(noteable)}
end
 
# rubocop: disable CodeReuse/ActiveRecord
def preload_author_status(notes)
ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status })
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -89,6 +89,7 @@ module UploadsActions
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def build_uploader_from_upload
return unless uploader = build_uploader
 
Loading
Loading
@@ -96,6 +97,7 @@ module UploadsActions
upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths)
upload&.build_uploader
end
# rubocop: enable CodeReuse/ActiveRecord
 
def build_uploader_from_params
return unless uploader = build_uploader
Loading
Loading
Loading
Loading
@@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def starred
@projects = load_projects(params.merge(starred: true))
.includes(:forked_from_project, :tags)
Loading
Loading
@@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
@@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@sort = params[:sort]
end
 
# rubocop: disable CodeReuse/ActiveRecord
def load_projects(finder_params)
projects = ProjectsFinder
.new(params: finder_params, current_user: current_user)
Loading
Loading
@@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
 
prepare_projects_for_rendering(projects)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def load_events
projects = load_projects(params.merge(non_public: true))
Loading
Loading
Loading
Loading
@@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def redirect_out_of_range(todos)
total_pages =
if todo_params.except(:sort, :page).empty?
Loading
Loading
@@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController
 
out_of_range
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def starred
@projects = load_projects.reorder('star_count DESC')
 
Loading
Loading
@@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
# rubocop: disable CodeReuse/ActiveRecord
def load_projects
projects = ProjectsFinder.new(current_user: current_user, params: params)
.execute
Loading
Loading
@@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController
 
prepare_projects_for_rendering(projects)
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -97,6 +97,7 @@ class GroupsController < Groups::ApplicationController
redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion."
end
 
# rubocop: disable CodeReuse/ActiveRecord
def transfer
parent_group = Group.find_by(id: params[:new_parent_group_id])
service = ::Groups::TransferService.new(@group, current_user)
Loading
Loading
@@ -109,9 +110,11 @@ class GroupsController < Groups::ApplicationController
render :edit
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
protected
 
# rubocop: disable CodeReuse/ActiveRecord
def authorize_create_group!
allowed = if params[:parent_id].present?
parent = Group.find_by(id: params[:parent_id])
Loading
Loading
@@ -122,6 +125,7 @@ class GroupsController < Groups::ApplicationController
 
render_404 unless allowed
end
# rubocop: enable CodeReuse/ActiveRecord
 
def determine_layout
if [:new, :create].include?(action_name.to_sym)
Loading
Loading
@@ -156,6 +160,7 @@ class GroupsController < Groups::ApplicationController
]
end
 
# rubocop: disable CodeReuse/ActiveRecord
def load_events
params[:sort] ||= 'latest_activity_desc'
 
Loading
Loading
@@ -175,6 +180,7 @@ class GroupsController < Groups::ApplicationController
.new(current_user)
.execute(@events, atom_request: request.format.atom?)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def user_actions
if current_user
Loading
Loading
class Import::BaseController < ApplicationController
private
 
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects(import_type)
current_user.created_projects.where(import_type: import_type).includes(:import_state)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def find_jobs(import_type)
current_user.created_projects
.includes(:import_state)
.where(import_type: import_type)
.to_json(only: [:id], methods: [:import_status])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def find_or_create_namespace(names, owner)
names = params[:target_namespace].presence || names
Loading
Loading
Loading
Loading
@@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController
redirect_to status_import_bitbucket_url
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
bitbucket_client = Bitbucket::Client.new(credentials)
repos = bitbucket_client.repos
Loading
Loading
@@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController
 
@repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) }
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs('bitbucket')
Loading
Loading
Loading
Loading
@@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController
redirect_to status_import_bitbucket_server_path
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
repos = bitbucket_client.repos
 
Loading
Loading
@@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController
clear_session_data
redirect_to new_import_bitbucket_server_path
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs('bitbucket_server')
Loading
Loading
Loading
Loading
@@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController
redirect_to status_import_fogbugz_path
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
unless client.valid?
return redirect_to new_import_fogbugz_path
Loading
Loading
@@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController
 
@repos.reject! { |repo| already_added_projects_names.include? repo.name }
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs('fogbugz')
Loading
Loading
Loading
Loading
@@ -22,6 +22,7 @@ class Import::GithubController < Import::BaseController
redirect_to status_import_url
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
@repos = client.repos
@already_added_projects = find_already_added_projects(provider)
Loading
Loading
@@ -29,6 +30,7 @@ class Import::GithubController < Import::BaseController
 
@repos.reject! { |repo| already_added_projects_names.include? repo.full_name }
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs(provider)
Loading
Loading
@@ -104,9 +106,11 @@ class Import::GithubController < Import::BaseController
:github
end
 
# rubocop: disable CodeReuse/ActiveRecord
def logged_in_with_provider?
current_user.identities.exists?(provider: provider)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def provider_auth
if session[access_token_key].blank?
Loading
Loading
Loading
Loading
@@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController
redirect_to status_import_gitlab_url
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
@repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS)
 
Loading
Loading
@@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController
 
@repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] }
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs('gitlab')
Loading
Loading
Loading
Loading
@@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController
redirect_to status_import_google_code_path
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
unless client.valid?
return redirect_to new_import_google_code_path
Loading
Loading
@@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController
 
@repos.reject! { |repo| already_added_projects_names.include? repo.name }
end
# rubocop: enable CodeReuse/ActiveRecord
 
def jobs
render json: find_jobs('google_code')
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController
def new
end
 
# rubocop: disable CodeReuse/ActiveRecord
def status
@already_added_projects = find_already_added_projects
already_added_import_urls = @already_added_projects.pluck(:import_url)
Loading
Loading
@@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController
already_added_import_urls.include?(repository[:url])
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def upload
group = Group.find(params[:group_id])
Loading
Loading
@@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def group
@group ||= Group.find_by(id: session[:manifest_import_group_id])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def repositories
@repositories ||= session[:manifest_import_repositories]
Loading
Loading
@@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController
find_already_added_projects.to_json(only: [:id], methods: [:import_status])
end
 
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects
group.all_projects
.where(import_type: 'manifest')
.where(creator_id: current_user)
.includes(:import_state)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def verify_import_enabled
render_404 unless manifest_import_enabled?
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