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
......@@ -30,6 +30,7 @@ def report_params
))
end
# rubocop: disable CodeReuse/ActiveRecord
def set_user
@user = User.find_by(id: params[:user_id])
......@@ -39,4 +40,5 @@ def set_user
redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked."
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
class Admin::AbuseReportsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@abuse_reports = AbuseReport.order(id: :desc).page(params[:page])
@abuse_reports.includes(:reporter, :user)
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
abuse_report = AbuseReport.find(params[:id])
......
......@@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController
before_action :set_application, only: [:show, :edit, :update, :destroy]
before_action :load_scopes, only: [:new, :create, :edit, :update]
# rubocop: disable CodeReuse/ActiveRecord
def index
@applications = Doorkeeper::Application.where("owner_id IS NULL")
end
# rubocop: enable CodeReuse/ActiveRecord
def show
end
......@@ -45,9 +47,11 @@ def destroy
private
# rubocop: disable CodeReuse/ActiveRecord
def set_application
@application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
# Only allow a trusted parameter "white list" through.
def application_params
......
......@@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
before_action :finder, only: [:edit, :update, :destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index
@broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page])
@broadcast_message = BroadcastMessage.new
end
# rubocop: enable CodeReuse/ActiveRecord
def edit
end
......
......@@ -4,10 +4,12 @@ class Admin::DashboardController < Admin::ApplicationController
COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest,
Note, Snippet, Key, Milestone].freeze
# rubocop: disable CodeReuse/ActiveRecord
def index
@counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS)
@projects = Project.order_id_desc.without_deleted.with_route.limit(10)
@users = User.order_id_desc.limit(10)
@groups = Group.order_id_desc.with_route.limit(10)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -10,6 +10,7 @@ def index
@groups = @groups.page(params[:page])
end
# rubocop: disable CodeReuse/ActiveRecord
def show
@group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id])
@members = present_members(
......@@ -18,6 +19,7 @@ def show
AccessRequestsFinder.new(@group).execute(current_user))
@projects = @group.projects.with_statistics.page(params[:projects_page])
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@group = Group.new
......
......@@ -44,9 +44,11 @@ def destroy
protected
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def identity
@identity ||= user.identities.find(params[:id])
......
......@@ -30,9 +30,11 @@ def revoke
private
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def finder(options = {})
PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options))
......@@ -42,6 +44,7 @@ def impersonation_token_params
params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: [])
end
# rubocop: disable CodeReuse/ActiveRecord
def set_index_vars
@scopes = Gitlab::Auth.available_scopes(current_user)
......@@ -49,4 +52,5 @@ def set_index_vars
@inactive_impersonation_tokens = finder(state: 'inactive').execute
@active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at)
end
# rubocop: enable CodeReuse/ActiveRecord
end
class Admin::JobsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_builds = Ci::Build
......@@ -16,6 +17,7 @@ def index
end
@builds = @builds.page(params[:page]).per(30)
end
# rubocop: enable CodeReuse/ActiveRecord
def cancel_all
Ci::Build.running_or_pending.each(&:cancel)
......
......@@ -24,9 +24,11 @@ def destroy
protected
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def key_params
params.require(:user_id, :id)
......
......@@ -19,6 +19,7 @@ def index
end
end
# rubocop: disable CodeReuse/ActiveRecord
def show
if @group
@group_members = present_members(
......@@ -30,7 +31,9 @@ def show
@requesters = present_members(
AccessRequestsFinder.new(@project).execute(current_user))
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def transfer
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
......@@ -38,6 +41,7 @@ def transfer
@project.reload
redirect_to admin_project_path(@project)
end
# rubocop: enable CodeReuse/ActiveRecord
def repository_check
RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id)
......
class Admin::RunnersController < Admin::ApplicationController
before_action :runner, except: :index
# rubocop: disable CodeReuse/ActiveRecord
def index
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
@runners = Ci::Runner.order(sort)
......@@ -8,6 +9,7 @@ def index
@runners = @runners.page(params[:page]).per(30)
@active_runners_cnt = Ci::Runner.online.count
end
# rubocop: enable CodeReuse/ActiveRecord
def show
assign_builds_and_projects
......@@ -57,6 +59,7 @@ def runner_params
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
end
# rubocop: disable CodeReuse/ActiveRecord
def assign_builds_and_projects
@builds = runner.builds.order('id DESC').first(30)
@projects =
......@@ -69,4 +72,5 @@ def assign_builds_and_projects
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
@projects = @projects.page(params[:page]).per(30)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -30,16 +30,20 @@ def update
private
# rubocop: disable CodeReuse/ActiveRecord
def services_templates
Service.available_services_names.map do |service_name|
service_template = "#{service_name}_service".camelize.constantize
service_template.where(template: true).first_or_create
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service
@service ||= Service.where(id: params[:id], template: true).first
end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430')
......
class Admin::SpamLogsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@spam_logs = SpamLog.order(id: :desc).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
spam_log = SpamLog.find(params[:id])
......
......@@ -174,9 +174,11 @@ def changing_own_password?
user == current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_back_or_admin_user(options = {})
redirect_back_or_default(default: default_route, options: options)
......
......@@ -11,6 +11,7 @@ class IssuesController < Boards::ApplicationController
before_action :authorize_update_issue, only: [:update]
skip_before_action :authenticate_user!, only: [:index]
# rubocop: disable CodeReuse/ActiveRecord
def index
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = list_service.execute
......@@ -25,6 +26,7 @@ def index
render_issues(issues, list_service.metadata)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params)
......
......@@ -88,6 +88,7 @@ def authenticate_with_two_factor_via_u2f(user)
# Setup in preparation of communication with a U2F (universal 2nd factor) device
# Actual communication is performed using a Javascript API
# rubocop: disable CodeReuse/ActiveRecord
def setup_u2f_authentication(user)
key_handles = user.u2f_registrations.pluck(:key_handle)
u2f = U2F::U2F.new(u2f_app_id)
......@@ -99,4 +100,5 @@ def setup_u2f_authentication(user)
sign_requests: sign_requests })
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -99,6 +99,7 @@ def existing_merge_request_path
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def merge_request_exists?
strong_memoize(:merge_request) do
MergeRequestsFinder.new(current_user, project_id: @project.id)
......@@ -110,6 +111,7 @@ def merge_request_exists?
target_branch: @start_branch)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def different_project?
......
......@@ -24,6 +24,7 @@ def two_factor_authentication_required?
current_user.try(:require_two_factor_authentication_from_group?)
end
# rubocop: disable CodeReuse/ActiveRecord
def two_factor_authentication_reason(global: -> {}, group: -> {})
if two_factor_authentication_required?
if Gitlab::CurrentSettings.require_two_factor_authentication?
......@@ -34,6 +35,7 @@ def two_factor_authentication_reason(global: -> {}, group: -> {})
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def two_factor_grace_period
periods = [Gitlab::CurrentSettings.two_factor_grace_period]
......
module GroupTree
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_group_tree(groups)
groups = groups.sort_by_attribute(@sort = params[:sort])
......@@ -23,7 +24,9 @@ def render_group_tree(groups)
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def filtered_groups_with_ancestors(groups)
filtered_groups = groups.search(params[:filter]).page(params[:page])
......@@ -40,4 +43,5 @@ def filtered_groups_with_ancestors(groups)
filtered_groups
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment