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 54 additions and 0 deletions
Loading
Loading
@@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController
 
layout 'project'
 
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_builds = project.builds.relevant
Loading
Loading
@@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController
])
@builds = @builds.page(params[:page]).per(30).without_count
end
# rubocop: enable CodeReuse/ActiveRecord
 
def cancel_all
return access_denied! unless can?(current_user, :update_build, project)
Loading
Loading
@@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController
redirect_to project_jobs_path(project)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def show
@pipeline = @build.pipeline
@builds = @pipeline.builds
Loading
Loading
@@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def trace
build.trace.read do |stream|
Loading
Loading
Loading
Loading
@@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def set_priorities
Label.transaction do
available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
Loading
Loading
@@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController
format.json { render json: { message: 'success' } }
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def promote
promote_service = Labels::PromoteService.new(@project, @current_user)
Loading
Loading
Loading
Loading
@@ -41,11 +41,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController
params[:operation] == 'upload'
end
 
# rubocop: disable CodeReuse/ActiveRecord
def existing_oids
@existing_oids ||= begin
project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid)
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def download_objects!
objects.each do |object|
Loading
Loading
Loading
Loading
@@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
params[:size].to_i
end
 
# rubocop: disable CodeReuse/ActiveRecord
def store_file!(oid, size)
object = LfsObject.find_by(oid: oid, size: size)
unless object&.file&.exists?
Loading
Loading
@@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
 
link_to_project!(object)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def create_file!(oid, size)
uploaded_file = UploadedFile.from_params(
Loading
Loading
@@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
LfsObject.create!(oid: oid, size: size, file: uploaded_file)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def link_to_project!(object)
if object && !object.projects.exists?(storage_project.id)
object.lfs_objects_projects.create!(project: storage_project)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -5,9 +5,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
 
private
 
# rubocop: disable CodeReuse/ActiveRecord
def merge_request
@issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def merge_request_params
params.require(:merge_request).permit(merge_request_params_attributes)
Loading
Loading
Loading
Loading
@@ -109,6 +109,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
set_pipeline_variables
end
 
# rubocop: disable CodeReuse/ActiveRecord
def selected_target_project
if @project.id.to_s == params[:target_project_id] || !@project.forked?
@project
Loading
Loading
@@ -119,6 +120,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
@project.forked_from_project
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384')
Loading
Loading
Loading
Loading
@@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@diffs = @compare.diffs(diff_options)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def commit
return nil unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commits.exists?(sha: commit_id)
 
@commit ||= @project.commit(commit_id)
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_diff_compare
@merge_request_diff =
if diff_id = params[:diff_id].presence
Loading
Loading
@@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@merge_request_diff
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def additional_attributes
{
Loading
Loading
Loading
Loading
@@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def milestone
@milestone ||= @project.milestones.find_by!(iid: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
 
def authorize_admin_milestone!
return render_404 unless can?(current_user, :admin_milestone, @project)
Loading
Loading
Loading
Loading
@@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController
before_action :authorize_read_pages!, only: [:show]
before_action :authorize_update_pages!, except: [:show]
 
# rubocop: disable CodeReuse/ActiveRecord
def show
@domains = @project.pages_domains.order(:domain)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def destroy
project.remove_pages
Loading
Loading
Loading
Loading
@@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController
params.require(:pages_domain).permit(:key, :certificate)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def domain
@domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play]
before_action :authorize_admin_pipeline_schedule!, only: [:destroy]
 
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_schedules = PipelineSchedulesFinder.new(@project).execute
@schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope])
.includes(:last_pipeline)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def new
@schedule = project.pipeline_schedules.new
Loading
Loading
Loading
Loading
@@ -159,6 +159,7 @@ class Projects::PipelinesController < Projects::ApplicationController
params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value])
end
 
# rubocop: disable CodeReuse/ActiveRecord
def pipeline
@pipeline ||= project
.pipelines
Loading
Loading
@@ -166,6 +167,7 @@ class Projects::PipelinesController < Projects::ApplicationController
.find_by!(id: params[:id])
.present(current_user: current_user)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def whitelist_query_limiting
# Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
# Authorize
before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access]
 
# rubocop: disable CodeReuse/ActiveRecord
def index
@sort = params[:sort].presence || sort_value_name
@group_links = @project.project_group_links
Loading
Loading
@@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user))
@project_member = @project.project_members.new
end
# rubocop: enable CodeReuse/ActiveRecord
 
def import
@projects = current_user.authorized_projects.order_id_desc
Loading
Loading
Loading
Loading
@@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController
@tag ||= @repository.find_tag(params[:tag_id])
end
 
# rubocop: disable CodeReuse/ActiveRecord
def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def release_params
params.require(:release).permit(:description)
Loading
Loading
Loading
Loading
@@ -31,6 +31,7 @@ module Projects
render 'show'
end
 
# rubocop: disable CodeReuse/ActiveRecord
def define_protected_refs
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
@protected_tags = @project.protected_tags.order(:name).page(params[:page])
Loading
Loading
@@ -42,6 +43,7 @@ module Projects
 
load_gon_index
end
# rubocop: enable CodeReuse/ActiveRecord
 
def remote_mirror
@remote_mirror = project.remote_mirrors.first_or_initialize
Loading
Loading
Loading
Loading
@@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController
before_action :authorize_push_code!, only: [:new, :create]
before_action :authorize_admin_project!, only: [:destroy]
 
# rubocop: disable CodeReuse/ActiveRecord
def index
params[:sort] = params[:sort].presence || sort_value_recently_updated
 
Loading
Loading
@@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController
format.atom { render layout: 'xml.atom' }
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
# rubocop: disable CodeReuse/ActiveRecord
def show
@tag = @repository.find_tag(params[:id])
 
Loading
Loading
@@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController
@release = @project.releases.find_or_initialize_by(tag: @tag.name)
@commit = @repository.commit(@tag.dereferenced_target)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def create
result = Tags::CreateService.new(@project, current_user)
Loading
Loading
Loading
Loading
@@ -25,12 +25,14 @@ class ProjectsController < Projects::ApplicationController
redirect_to(current_user ? root_path : explore_root_path)
end
 
# rubocop: disable CodeReuse/ActiveRecord
def new
namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id]
return access_denied! if namespace && !can?(current_user, :create_projects, namespace)
 
@project = Project.new(namespace_id: namespace&.id)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def edit
@badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id))
Loading
Loading
@@ -75,6 +77,7 @@ class ProjectsController < Projects::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def transfer
return access_denied! unless can?(current_user, :change_namespace, @project)
 
Loading
Loading
@@ -85,6 +88,7 @@ class ProjectsController < Projects::ApplicationController
flash[:alert] = @project.errors[:new_namespace].first
end
end
# rubocop: enable CodeReuse/ActiveRecord
 
def remove_fork
return access_denied! unless can?(current_user, :remove_fork_project, @project)
Loading
Loading
@@ -231,6 +235,7 @@ class ProjectsController < Projects::ApplicationController
}
end
 
# rubocop: disable CodeReuse/ActiveRecord
def refs
find_refs = params['find']
 
Loading
Loading
@@ -265,6 +270,7 @@ class ProjectsController < Projects::ApplicationController
 
render json: options.to_json
end
# rubocop: enable CodeReuse/ActiveRecord
 
# Render project landing depending of which features are available
# So if page is not availble in the list it renders the next page
Loading
Loading
@@ -303,6 +309,7 @@ class ProjectsController < Projects::ApplicationController
end
end
 
# rubocop: disable CodeReuse/ActiveRecord
def load_events
projects = Project.where(id: @project.id)
 
Loading
Loading
@@ -312,6 +319,7 @@ class ProjectsController < Projects::ApplicationController
 
Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
end
# rubocop: enable CodeReuse/ActiveRecord
 
def project_params
params.require(:project)
Loading
Loading
Loading
Loading
@@ -31,6 +31,7 @@ class SearchController < ApplicationController
check_single_commit_result
end
 
# rubocop: disable CodeReuse/ActiveRecord
def autocomplete
term = params[:term]
 
Loading
Loading
@@ -43,6 +44,7 @@ class SearchController < ApplicationController
 
render json: search_autocomplete_opts(term).to_json
end
# rubocop: enable CodeReuse/ActiveRecord
 
private
 
Loading
Loading
Loading
Loading
@@ -107,6 +107,7 @@ class SessionsController < Devise::SessionsController
 
# Handle an "initial setup" state, where there's only one user, it's an admin,
# and they require a password change.
# rubocop: disable CodeReuse/ActiveRecord
def check_initial_setup
return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one
 
Loading
Loading
@@ -121,6 +122,7 @@ class SessionsController < Devise::SessionsController
redirect_to edit_user_password_path(reset_password_token: @token),
notice: "Please create a password for your new account."
end
# rubocop: enable CodeReuse/ActiveRecord
 
def user_params
params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response)
Loading
Loading
Loading
Loading
@@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController
nil
end
 
# rubocop: disable CodeReuse/ActiveRecord
def snippet
PersonalSnippet.find_by(id: params[:snippet_id])
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :snippet
 
def note_params
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