Commit 67856357 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-rubocop-code-reuse' into 'master'

EE: Add RuboCop cops to enforce code reusing rules

See merge request gitlab-org/gitlab-ee!7229
parents ba37a5ae cd7b816e
...@@ -30,6 +30,7 @@ class AbuseReportsController < ApplicationController ...@@ -30,6 +30,7 @@ class AbuseReportsController < ApplicationController
)) ))
end end
# rubocop: disable CodeReuse/ActiveRecord
def set_user def set_user
@user = User.find_by(id: params[:user_id]) @user = User.find_by(id: params[:user_id])
...@@ -39,4 +40,5 @@ class AbuseReportsController < ApplicationController ...@@ -39,4 +40,5 @@ class AbuseReportsController < ApplicationController
redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked." redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked."
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
class Admin::AbuseReportsController < Admin::ApplicationController class Admin::AbuseReportsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@abuse_reports = AbuseReport.order(id: :desc).page(params[:page]) @abuse_reports = AbuseReport.order(id: :desc).page(params[:page])
@abuse_reports.includes(:reporter, :user) @abuse_reports.includes(:reporter, :user)
end end
# rubocop: enable CodeReuse/ActiveRecord
def destroy def destroy
abuse_report = AbuseReport.find(params[:id]) abuse_report = AbuseReport.find(params[:id])
......
...@@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController
before_action :set_application, only: [:show, :edit, :update, :destroy] before_action :set_application, only: [:show, :edit, :update, :destroy]
before_action :load_scopes, only: [:new, :create, :edit, :update] before_action :load_scopes, only: [:new, :create, :edit, :update]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@applications = Doorkeeper::Application.where("owner_id IS NULL") @applications = Doorkeeper::Application.where("owner_id IS NULL")
end end
# rubocop: enable CodeReuse/ActiveRecord
def show def show
end end
...@@ -45,9 +47,11 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -45,9 +47,11 @@ class Admin::ApplicationsController < Admin::ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def set_application def set_application
@application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id]) @application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def application_params def application_params
......
...@@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController ...@@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
before_action :finder, only: [:edit, :update, :destroy] before_action :finder, only: [:edit, :update, :destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page]) @broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page])
@broadcast_message = BroadcastMessage.new @broadcast_message = BroadcastMessage.new
end end
# rubocop: enable CodeReuse/ActiveRecord
def edit def edit
end end
......
...@@ -6,10 +6,12 @@ class Admin::DashboardController < Admin::ApplicationController ...@@ -6,10 +6,12 @@ class Admin::DashboardController < Admin::ApplicationController
COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest, COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest,
Note, Snippet, Key, Milestone].freeze Note, Snippet, Key, Milestone].freeze
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS) @counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS)
@projects = Project.order_id_desc.without_deleted.with_route.limit(10) @projects = Project.order_id_desc.without_deleted.with_route.limit(10)
@users = User.order_id_desc.limit(10) @users = User.order_id_desc.limit(10)
@groups = Group.order_id_desc.with_route.limit(10) @groups = Group.order_id_desc.with_route.limit(10)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -12,6 +12,7 @@ class Admin::GroupsController < Admin::ApplicationController ...@@ -12,6 +12,7 @@ class Admin::GroupsController < Admin::ApplicationController
@groups = @groups.page(params[:page]) @groups = @groups.page(params[:page])
end end
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id]) @group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id])
@members = present_members( @members = present_members(
...@@ -20,6 +21,7 @@ class Admin::GroupsController < Admin::ApplicationController ...@@ -20,6 +21,7 @@ class Admin::GroupsController < Admin::ApplicationController
AccessRequestsFinder.new(@group).execute(current_user)) AccessRequestsFinder.new(@group).execute(current_user))
@projects = @group.projects.with_statistics.page(params[:projects_page]) @projects = @group.projects.with_statistics.page(params[:projects_page])
end end
# rubocop: enable CodeReuse/ActiveRecord
def new def new
@group = Group.new @group = Group.new
......
...@@ -44,9 +44,11 @@ class Admin::IdentitiesController < Admin::ApplicationController ...@@ -44,9 +44,11 @@ class Admin::IdentitiesController < Admin::ApplicationController
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def user def user
@user ||= User.find_by!(username: params[:user_id]) @user ||= User.find_by!(username: params[:user_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def identity def identity
@identity ||= user.identities.find(params[:id]) @identity ||= user.identities.find(params[:id])
......
...@@ -30,9 +30,11 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController ...@@ -30,9 +30,11 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def user def user
@user ||= User.find_by!(username: params[:user_id]) @user ||= User.find_by!(username: params[:user_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def finder(options = {}) def finder(options = {})
PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options)) PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options))
...@@ -42,6 +44,7 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController ...@@ -42,6 +44,7 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: []) params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: [])
end end
# rubocop: disable CodeReuse/ActiveRecord
def set_index_vars def set_index_vars
@scopes = Gitlab::Auth.available_scopes(current_user) @scopes = Gitlab::Auth.available_scopes(current_user)
...@@ -49,4 +52,5 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController ...@@ -49,4 +52,5 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
@inactive_impersonation_tokens = finder(state: 'inactive').execute @inactive_impersonation_tokens = finder(state: 'inactive').execute
@active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at) @active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
class Admin::JobsController < Admin::ApplicationController class Admin::JobsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@scope = params[:scope] @scope = params[:scope]
@all_builds = Ci::Build @all_builds = Ci::Build
...@@ -16,6 +17,7 @@ class Admin::JobsController < Admin::ApplicationController ...@@ -16,6 +17,7 @@ class Admin::JobsController < Admin::ApplicationController
end end
@builds = @builds.page(params[:page]).per(30) @builds = @builds.page(params[:page]).per(30)
end end
# rubocop: enable CodeReuse/ActiveRecord
def cancel_all def cancel_all
Ci::Build.running_or_pending.each(&:cancel) Ci::Build.running_or_pending.each(&:cancel)
......
...@@ -24,9 +24,11 @@ class Admin::KeysController < Admin::ApplicationController ...@@ -24,9 +24,11 @@ class Admin::KeysController < Admin::ApplicationController
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def user def user
@user ||= User.find_by!(username: params[:user_id]) @user ||= User.find_by!(username: params[:user_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def key_params def key_params
params.require(:user_id, :id) params.require(:user_id, :id)
......
...@@ -19,6 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -19,6 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def show def show
if @group if @group
@group_members = present_members( @group_members = present_members(
...@@ -30,7 +31,9 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -30,7 +31,9 @@ class Admin::ProjectsController < Admin::ApplicationController
@requesters = present_members( @requesters = present_members(
AccessRequestsFinder.new(@project).execute(current_user)) AccessRequestsFinder.new(@project).execute(current_user))
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def transfer def transfer
namespace = Namespace.find_by(id: params[:new_namespace_id]) namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace) ::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
...@@ -38,6 +41,7 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -38,6 +41,7 @@ class Admin::ProjectsController < Admin::ApplicationController
@project.reload @project.reload
redirect_to admin_project_path(@project) redirect_to admin_project_path(@project)
end end
# rubocop: enable CodeReuse/ActiveRecord
def repository_check def repository_check
RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id) RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id)
......
class Admin::RunnersController < Admin::ApplicationController class Admin::RunnersController < Admin::ApplicationController
before_action :runner, except: :index before_action :runner, except: :index
# rubocop: disable CodeReuse/ActiveRecord
def index def index
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc } sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
@runners = Ci::Runner.order(sort) @runners = Ci::Runner.order(sort)
...@@ -8,6 +9,7 @@ class Admin::RunnersController < Admin::ApplicationController ...@@ -8,6 +9,7 @@ class Admin::RunnersController < Admin::ApplicationController
@runners = @runners.page(params[:page]).per(30) @runners = @runners.page(params[:page]).per(30)
@active_runners_cnt = Ci::Runner.online.count @active_runners_cnt = Ci::Runner.online.count
end end
# rubocop: enable CodeReuse/ActiveRecord
def show def show
assign_builds_and_projects assign_builds_and_projects
...@@ -57,6 +59,7 @@ class Admin::RunnersController < Admin::ApplicationController ...@@ -57,6 +59,7 @@ class Admin::RunnersController < Admin::ApplicationController
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE) params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
end end
# rubocop: disable CodeReuse/ActiveRecord
def assign_builds_and_projects def assign_builds_and_projects
@builds = runner.builds.order('id DESC').first(30) @builds = runner.builds.order('id DESC').first(30)
@projects = @projects =
...@@ -69,4 +72,5 @@ class Admin::RunnersController < Admin::ApplicationController ...@@ -69,4 +72,5 @@ class Admin::RunnersController < Admin::ApplicationController
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any? @projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
@projects = @projects.page(params[:page]).per(30) @projects = @projects.page(params[:page]).per(30)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -30,16 +30,20 @@ class Admin::ServicesController < Admin::ApplicationController ...@@ -30,16 +30,20 @@ class Admin::ServicesController < Admin::ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def services_templates def services_templates
Service.available_services_names.map do |service_name| Service.available_services_names.map do |service_name|
service_template = "#{service_name}_service".camelize.constantize service_template = "#{service_name}_service".camelize.constantize
service_template.where(template: true).first_or_create service_template.where(template: true).first_or_create
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service def service
@service ||= Service.where(id: params[:id], template: true).first @service ||= Service.where(id: params[:id], template: true).first
end end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430')
......
class Admin::SpamLogsController < Admin::ApplicationController class Admin::SpamLogsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@spam_logs = SpamLog.order(id: :desc).page(params[:page]) @spam_logs = SpamLog.order(id: :desc).page(params[:page])
end end
# rubocop: enable CodeReuse/ActiveRecord
def destroy def destroy
spam_log = SpamLog.find(params[:id]) spam_log = SpamLog.find(params[:id])
......
...@@ -176,9 +176,11 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -176,9 +176,11 @@ class Admin::UsersController < Admin::ApplicationController
user == current_user user == current_user
end end
# rubocop: disable CodeReuse/ActiveRecord
def user def user
@user ||= User.find_by!(username: params[:id]) @user ||= User.find_by!(username: params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_back_or_admin_user(options = {}) def redirect_back_or_admin_user(options = {})
redirect_back_or_default(default: default_route, options: options) redirect_back_or_default(default: default_route, options: options)
......
...@@ -11,6 +11,7 @@ module Boards ...@@ -11,6 +11,7 @@ module Boards
before_action :authorize_update_issue, only: [:update] before_action :authorize_update_issue, only: [:update]
skip_before_action :authenticate_user!, only: [:index] skip_before_action :authenticate_user!, only: [:index]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params) list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = list_service.execute issues = list_service.execute
...@@ -25,6 +26,7 @@ module Boards ...@@ -25,6 +26,7 @@ module Boards
render_issues(issues, list_service.metadata) render_issues(issues, list_service.metadata)
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params) service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params)
......
...@@ -88,6 +88,7 @@ module AuthenticatesWithTwoFactor ...@@ -88,6 +88,7 @@ module AuthenticatesWithTwoFactor
# Setup in preparation of communication with a U2F (universal 2nd factor) device # Setup in preparation of communication with a U2F (universal 2nd factor) device
# Actual communication is performed using a Javascript API # Actual communication is performed using a Javascript API
# rubocop: disable CodeReuse/ActiveRecord
def setup_u2f_authentication(user) def setup_u2f_authentication(user)
key_handles = user.u2f_registrations.pluck(:key_handle) key_handles = user.u2f_registrations.pluck(:key_handle)
u2f = U2F::U2F.new(u2f_app_id) u2f = U2F::U2F.new(u2f_app_id)
...@@ -99,4 +100,5 @@ module AuthenticatesWithTwoFactor ...@@ -99,4 +100,5 @@ module AuthenticatesWithTwoFactor
sign_requests: sign_requests }) sign_requests: sign_requests })
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -99,6 +99,7 @@ module CreatesCommit ...@@ -99,6 +99,7 @@ module CreatesCommit
end end
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def merge_request_exists? def merge_request_exists?
strong_memoize(:merge_request) do strong_memoize(:merge_request) do
MergeRequestsFinder.new(current_user, project_id: @project.id) MergeRequestsFinder.new(current_user, project_id: @project.id)
...@@ -110,6 +111,7 @@ module CreatesCommit ...@@ -110,6 +111,7 @@ module CreatesCommit
target_branch: @start_branch) target_branch: @start_branch)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def different_project? def different_project?
......
...@@ -24,6 +24,7 @@ module EnforcesTwoFactorAuthentication ...@@ -24,6 +24,7 @@ module EnforcesTwoFactorAuthentication
current_user.try(:require_two_factor_authentication_from_group?) current_user.try(:require_two_factor_authentication_from_group?)
end end
# rubocop: disable CodeReuse/ActiveRecord
def two_factor_authentication_reason(global: -> {}, group: -> {}) def two_factor_authentication_reason(global: -> {}, group: -> {})
if two_factor_authentication_required? if two_factor_authentication_required?
if Gitlab::CurrentSettings.require_two_factor_authentication? if Gitlab::CurrentSettings.require_two_factor_authentication?
...@@ -34,6 +35,7 @@ module EnforcesTwoFactorAuthentication ...@@ -34,6 +35,7 @@ module EnforcesTwoFactorAuthentication
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def two_factor_grace_period def two_factor_grace_period
periods = [Gitlab::CurrentSettings.two_factor_grace_period] periods = [Gitlab::CurrentSettings.two_factor_grace_period]
......
module GroupTree module GroupTree
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_group_tree(groups) def render_group_tree(groups)
groups = groups.sort_by_attribute(@sort = params[:sort]) groups = groups.sort_by_attribute(@sort = params[:sort])
...@@ -23,7 +24,9 @@ module GroupTree ...@@ -23,7 +24,9 @@ module GroupTree
end end
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def filtered_groups_with_ancestors(groups) def filtered_groups_with_ancestors(groups)
filtered_groups = groups.search(params[:filter]).page(params[:page]) filtered_groups = groups.search(params[:filter]).page(params[:page])
...@@ -40,4 +43,5 @@ module GroupTree ...@@ -40,4 +43,5 @@ module GroupTree
filtered_groups filtered_groups
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -90,6 +90,7 @@ module IssuableActions ...@@ -90,6 +90,7 @@ module IssuableActions
render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" } render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" }
end end
# rubocop: disable CodeReuse/ActiveRecord
def discussions def discussions
notes = issuable.discussion_notes notes = issuable.discussion_notes
.inc_relations_for_view .inc_relations_for_view
...@@ -104,6 +105,7 @@ module IssuableActions ...@@ -104,6 +105,7 @@ module IssuableActions
render json: discussion_serializer.represent(discussions, context: self) render json: discussion_serializer.represent(discussions, context: self)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -49,9 +49,11 @@ module IssuableCollections ...@@ -49,9 +49,11 @@ module IssuableCollections
false false
end end
# rubocop: disable CodeReuse/ActiveRecord
def issuables_collection def issuables_collection
finder.execute.preload(preload_for_collection) finder.execute.preload(preload_for_collection)
end end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_out_of_range(total_pages) def redirect_out_of_range(total_pages)
return false if total_pages.nil? || total_pages.zero? return false if total_pages.nil? || total_pages.zero?
...@@ -82,6 +84,7 @@ module IssuableCollections ...@@ -82,6 +84,7 @@ module IssuableCollections
end end
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def filter_params def filter_params
set_sort_order_from_cookie set_sort_order_from_cookie
set_default_state set_default_state
...@@ -102,6 +105,7 @@ module IssuableCollections ...@@ -102,6 +105,7 @@ module IssuableCollections
@filter_params.permit(finder_type.valid_params) @filter_params.permit(finder_type.valid_params)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def set_default_state def set_default_state
......
...@@ -2,6 +2,7 @@ module IssuesCalendar ...@@ -2,6 +2,7 @@ module IssuesCalendar
extend ActiveSupport::Concern extend ActiveSupport::Concern
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_issues_calendar(issuables) def render_issues_calendar(issuables)
@issues = issuables @issues = issuables
.non_archived .non_archived
...@@ -20,5 +21,6 @@ module IssuesCalendar ...@@ -20,5 +21,6 @@ module IssuesCalendar
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
...@@ -10,10 +10,12 @@ module MembersPresentation ...@@ -10,10 +10,12 @@ module MembersPresentation
).fabricate! ).fabricate!
end end
# rubocop: disable CodeReuse/ActiveRecord
def preload_associations(members) def preload_associations(members)
ActiveRecord::Associations::Preloader.new.preload(members, :user) ActiveRecord::Associations::Preloader.new.preload(members, :user)
ActiveRecord::Associations::Preloader.new.preload(members, :source) ActiveRecord::Associations::Preloader.new.preload(members, :source)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -57,6 +57,7 @@ module MembershipActions ...@@ -57,6 +57,7 @@ module MembershipActions
redirect_to members_page_url redirect_to members_page_url
end end
# rubocop: disable CodeReuse/ActiveRecord
def leave def leave
member = membershipable.members_and_requesters.find_by!(user_id: current_user.id) member = membershipable.members_and_requesters.find_by!(user_id: current_user.id)
Members::DestroyService.new(current_user).execute(member) Members::DestroyService.new(current_user).execute(member)
...@@ -77,6 +78,7 @@ module MembershipActions ...@@ -77,6 +78,7 @@ module MembershipActions
format.json { render json: { notice: notice } } format.json { render json: { notice: notice } }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def resend_invite def resend_invite
member = membershipable.members.find(params[:id]) member = membershipable.members.find(params[:id])
......
...@@ -13,6 +13,7 @@ module RendersMemberAccess ...@@ -13,6 +13,7 @@ module RendersMemberAccess
private private
# rubocop: disable CodeReuse/ActiveRecord
def preload_max_member_access_for_collection(klass, collection) def preload_max_member_access_for_collection(klass, collection)
return if !current_user || collection.blank? return if !current_user || collection.blank?
...@@ -20,4 +21,5 @@ module RendersMemberAccess ...@@ -20,4 +21,5 @@ module RendersMemberAccess
current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -20,9 +20,11 @@ module RendersNotes ...@@ -20,9 +20,11 @@ module RendersNotes
project.team.max_member_access_for_user_ids(user_ids) project.team.max_member_access_for_user_ids(user_ids)
end end
# rubocop: disable CodeReuse/ActiveRecord
def preload_noteable_for_regular_notes(notes) def preload_noteable_for_regular_notes(notes)
ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable)
end end
# rubocop: enable CodeReuse/ActiveRecord
def preload_first_time_contribution_for_authors(noteable, notes) def preload_first_time_contribution_for_authors(noteable, notes)
return unless noteable.is_a?(Issuable) && noteable.first_contribution? return unless noteable.is_a?(Issuable) && noteable.first_contribution?
...@@ -30,7 +32,9 @@ module RendersNotes ...@@ -30,7 +32,9 @@ module RendersNotes
notes.each {|n| n.specialize_for_first_contribution!(noteable)} notes.each {|n| n.specialize_for_first_contribution!(noteable)}
end end
# rubocop: disable CodeReuse/ActiveRecord
def preload_author_status(notes) def preload_author_status(notes)
ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status }) ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status })
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -89,6 +89,7 @@ module UploadsActions ...@@ -89,6 +89,7 @@ module UploadsActions
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def build_uploader_from_upload def build_uploader_from_upload
return unless uploader = build_uploader return unless uploader = build_uploader
...@@ -96,6 +97,7 @@ module UploadsActions ...@@ -96,6 +97,7 @@ module UploadsActions
upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths) upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths)
upload&.build_uploader upload&.build_uploader
end end
# rubocop: enable CodeReuse/ActiveRecord
def build_uploader_from_params def build_uploader_from_params
return unless uploader = build_uploader return unless uploader = build_uploader
......
...@@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def starred def starred
@projects = load_projects(params.merge(starred: true)) @projects = load_projects(params.merge(starred: true))
.includes(:forked_from_project, :tags) .includes(:forked_from_project, :tags)
...@@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@sort = params[:sort] @sort = params[:sort]
end end
# rubocop: disable CodeReuse/ActiveRecord
def load_projects(finder_params) def load_projects(finder_params)
projects = ProjectsFinder projects = ProjectsFinder
.new(params: finder_params, current_user: current_user) .new(params: finder_params, current_user: current_user)
...@@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
prepare_projects_for_rendering(projects) prepare_projects_for_rendering(projects)
end end
# rubocop: enable CodeReuse/ActiveRecord
def load_events def load_events
projects = load_projects(params.merge(non_public: true)) projects = load_projects(params.merge(non_public: true))
......
...@@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id) params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id)
end end
# rubocop: disable CodeReuse/ActiveRecord
def redirect_out_of_range(todos) def redirect_out_of_range(todos)
total_pages = total_pages =
if todo_params.except(:sort, :page).empty? if todo_params.except(:sort, :page).empty?
...@@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController
out_of_range out_of_range
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def starred def starred
@projects = load_projects.reorder('star_count DESC') @projects = load_projects.reorder('star_count DESC')
...@@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# rubocop: disable CodeReuse/ActiveRecord
def load_projects def load_projects
projects = ProjectsFinder.new(current_user: current_user, params: params) projects = ProjectsFinder.new(current_user: current_user, params: params)
.execute .execute
...@@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController ...@@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController
prepare_projects_for_rendering(projects) prepare_projects_for_rendering(projects)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -98,6 +98,7 @@ class GroupsController < Groups::ApplicationController ...@@ -98,6 +98,7 @@ class GroupsController < Groups::ApplicationController
redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion." redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion."
end end
# rubocop: disable CodeReuse/ActiveRecord
def transfer def transfer
parent_group = Group.find_by(id: params[:new_parent_group_id]) parent_group = Group.find_by(id: params[:new_parent_group_id])
service = ::Groups::TransferService.new(@group, current_user) service = ::Groups::TransferService.new(@group, current_user)
...@@ -110,9 +111,11 @@ class GroupsController < Groups::ApplicationController ...@@ -110,9 +111,11 @@ class GroupsController < Groups::ApplicationController
render :edit render :edit
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def authorize_create_group! def authorize_create_group!
allowed = if params[:parent_id].present? allowed = if params[:parent_id].present?
parent = Group.find_by(id: params[:parent_id]) parent = Group.find_by(id: params[:parent_id])
...@@ -123,6 +126,7 @@ class GroupsController < Groups::ApplicationController ...@@ -123,6 +126,7 @@ class GroupsController < Groups::ApplicationController
render_404 unless allowed render_404 unless allowed
end end
# rubocop: enable CodeReuse/ActiveRecord
def determine_layout def determine_layout
if [:new, :create].include?(action_name.to_sym) if [:new, :create].include?(action_name.to_sym)
...@@ -157,6 +161,7 @@ class GroupsController < Groups::ApplicationController ...@@ -157,6 +161,7 @@ class GroupsController < Groups::ApplicationController
] ]
end end
# rubocop: disable CodeReuse/ActiveRecord
def load_events def load_events
params[:sort] ||= 'latest_activity_desc' params[:sort] ||= 'latest_activity_desc'
...@@ -176,6 +181,7 @@ class GroupsController < Groups::ApplicationController ...@@ -176,6 +181,7 @@ class GroupsController < Groups::ApplicationController
.new(current_user) .new(current_user)
.execute(@events, atom_request: request.format.atom?) .execute(@events, atom_request: request.format.atom?)
end end
# rubocop: enable CodeReuse/ActiveRecord
def user_actions def user_actions
if current_user if current_user
......
class Import::BaseController < ApplicationController class Import::BaseController < ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects(import_type) def find_already_added_projects(import_type)
current_user.created_projects.where(import_type: import_type).includes(:import_state) current_user.created_projects.where(import_type: import_type).includes(:import_state)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_jobs(import_type) def find_jobs(import_type)
current_user.created_projects current_user.created_projects
.includes(:import_state) .includes(:import_state)
.where(import_type: import_type) .where(import_type: import_type)
.to_json(only: [:id], methods: [:import_status]) .to_json(only: [:id], methods: [:import_status])
end end
# rubocop: enable CodeReuse/ActiveRecord
def find_or_create_namespace(names, owner) def find_or_create_namespace(names, owner)
names = params[:target_namespace].presence || names names = params[:target_namespace].presence || names
......
...@@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController ...@@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController
redirect_to status_import_bitbucket_url redirect_to status_import_bitbucket_url
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
bitbucket_client = Bitbucket::Client.new(credentials) bitbucket_client = Bitbucket::Client.new(credentials)
repos = bitbucket_client.repos repos = bitbucket_client.repos
...@@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController ...@@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController
@repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) } @repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) }
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs('bitbucket') render json: find_jobs('bitbucket')
......
...@@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController
redirect_to status_import_bitbucket_server_path redirect_to status_import_bitbucket_server_path
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
repos = bitbucket_client.repos repos = bitbucket_client.repos
...@@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController ...@@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController
clear_session_data clear_session_data
redirect_to new_import_bitbucket_server_path redirect_to new_import_bitbucket_server_path
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs('bitbucket_server') render json: find_jobs('bitbucket_server')
......
...@@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController ...@@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController
redirect_to status_import_fogbugz_path redirect_to status_import_fogbugz_path
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
unless client.valid? unless client.valid?
return redirect_to new_import_fogbugz_path return redirect_to new_import_fogbugz_path
...@@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController ...@@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.name } @repos.reject! { |repo| already_added_projects_names.include? repo.name }
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs('fogbugz') render json: find_jobs('fogbugz')
......
...@@ -24,6 +24,7 @@ class Import::GithubController < Import::BaseController ...@@ -24,6 +24,7 @@ class Import::GithubController < Import::BaseController
redirect_to status_import_url redirect_to status_import_url
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
@repos = client.repos @repos = client.repos
@already_added_projects = find_already_added_projects(provider) @already_added_projects = find_already_added_projects(provider)
...@@ -31,6 +32,7 @@ class Import::GithubController < Import::BaseController ...@@ -31,6 +32,7 @@ class Import::GithubController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.full_name } @repos.reject! { |repo| already_added_projects_names.include? repo.full_name }
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs(provider) render json: find_jobs(provider)
...@@ -106,9 +108,11 @@ class Import::GithubController < Import::BaseController ...@@ -106,9 +108,11 @@ class Import::GithubController < Import::BaseController
:github :github
end end
# rubocop: disable CodeReuse/ActiveRecord
def logged_in_with_provider? def logged_in_with_provider?
current_user.identities.exists?(provider: provider) current_user.identities.exists?(provider: provider)
end end
# rubocop: enable CodeReuse/ActiveRecord
def provider_auth def provider_auth
if session[access_token_key].blank? if session[access_token_key].blank?
......
...@@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController ...@@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController
redirect_to status_import_gitlab_url redirect_to status_import_gitlab_url
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
@repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS) @repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS)
...@@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController ...@@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController
@repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] } @repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] }
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs('gitlab') render json: find_jobs('gitlab')
......
...@@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController ...@@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController
redirect_to status_import_google_code_path redirect_to status_import_google_code_path
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
unless client.valid? unless client.valid?
return redirect_to new_import_google_code_path return redirect_to new_import_google_code_path
...@@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController ...@@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.name } @repos.reject! { |repo| already_added_projects_names.include? repo.name }
end end
# rubocop: enable CodeReuse/ActiveRecord
def jobs def jobs
render json: find_jobs('google_code') render json: find_jobs('google_code')
......
...@@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController ...@@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController
def new def new
end end
# rubocop: disable CodeReuse/ActiveRecord
def status def status
@already_added_projects = find_already_added_projects @already_added_projects = find_already_added_projects
already_added_import_urls = @already_added_projects.pluck(:import_url) already_added_import_urls = @already_added_projects.pluck(:import_url)
...@@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController ...@@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController
already_added_import_urls.include?(repository[:url]) already_added_import_urls.include?(repository[:url])
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def upload def upload
group = Group.find(params[:group_id]) group = Group.find(params[:group_id])
...@@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController ...@@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def group def group
@group ||= Group.find_by(id: session[:manifest_import_group_id]) @group ||= Group.find_by(id: session[:manifest_import_group_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def repositories def repositories
@repositories ||= session[:manifest_import_repositories] @repositories ||= session[:manifest_import_repositories]
...@@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController ...@@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController
find_already_added_projects.to_json(only: [:id], methods: [:import_status]) find_already_added_projects.to_json(only: [:id], methods: [:import_status])
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects def find_already_added_projects
group.all_projects group.all_projects
.where(import_type: 'manifest') .where(import_type: 'manifest')
.where(creator_id: current_user) .where(creator_id: current_user)
.includes(:import_state) .includes(:import_state)
end end
# rubocop: enable CodeReuse/ActiveRecord
def verify_import_enabled def verify_import_enabled
render_404 unless manifest_import_enabled? render_404 unless manifest_import_enabled?
......
# frozen_string_literal: true # frozen_string_literal: true
class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present @metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -7,6 +7,7 @@ class PasswordsController < Devise::PasswordsController ...@@ -7,6 +7,7 @@ class PasswordsController < Devise::PasswordsController
prepend EE::PasswordsController prepend EE::PasswordsController
# rubocop: disable CodeReuse/ActiveRecord
def edit def edit
super super
reset_password_token = Devise.token_generator.digest( reset_password_token = Devise.token_generator.digest(
...@@ -26,6 +27,7 @@ class PasswordsController < Devise::PasswordsController ...@@ -26,6 +27,7 @@ class PasswordsController < Devise::PasswordsController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def update def update
super do |resource| super do |resource|
......
...@@ -5,6 +5,7 @@ class Profiles::AccountsController < Profiles::ApplicationController ...@@ -5,6 +5,7 @@ class Profiles::AccountsController < Profiles::ApplicationController
@user = current_user @user = current_user
end end
# rubocop: disable CodeReuse/ActiveRecord
def unlink def unlink
provider = params[:provider] provider = params[:provider]
identity = current_user.identities.find_by(provider: provider) identity = current_user.identities.find_by(provider: provider)
...@@ -19,4 +20,5 @@ class Profiles::AccountsController < Profiles::ApplicationController ...@@ -19,4 +20,5 @@ class Profiles::AccountsController < Profiles::ApplicationController
redirect_to profile_account_path redirect_to profile_account_path
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
class Profiles::NotificationsController < Profiles::ApplicationController class Profiles::NotificationsController < Profiles::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@user = current_user @user = current_user
@group_notifications = current_user.notification_settings.for_groups.order(:id) @group_notifications = current_user.notification_settings.for_groups.order(:id)
@project_notifications = current_user.notification_settings.for_projects.order(:id) @project_notifications = current_user.notification_settings.for_projects.order(:id)
@global_notification_setting = current_user.global_notification_setting @global_notification_setting = current_user.global_notification_setting
end end
# rubocop: enable CodeReuse/ActiveRecord
def update def update
result = Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute result = Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute
......
...@@ -38,6 +38,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -38,6 +38,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
params.require(:personal_access_token).permit(:name, :expires_at, scopes: []) params.require(:personal_access_token).permit(:name, :expires_at, scopes: [])
end end
# rubocop: disable CodeReuse/ActiveRecord
def set_index_vars def set_index_vars
@scopes = Gitlab::Auth.available_scopes(current_user) @scopes = Gitlab::Auth.available_scopes(current_user)
...@@ -46,4 +47,5 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController ...@@ -46,4 +47,5 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
@new_personal_access_token = PersonalAccessToken.redis_getdel(current_user.id) @new_personal_access_token = PersonalAccessToken.redis_getdel(current_user.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -44,11 +44,13 @@ class ProfilesController < Profiles::ApplicationController ...@@ -44,11 +44,13 @@ class ProfilesController < Profiles::ApplicationController
redirect_to profile_personal_access_tokens_path redirect_to profile_personal_access_tokens_path
end end
# rubocop: disable CodeReuse/ActiveRecord
def audit_log def audit_log
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id) @events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
.order("created_at DESC") .order("created_at DESC")
.page(params[:page]) .page(params[:page])
end end
# rubocop: enable CodeReuse/ActiveRecord
def update_username def update_username
result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute
......
...@@ -82,16 +82,20 @@ class Projects::ArtifactsController < Projects::ApplicationController ...@@ -82,16 +82,20 @@ class Projects::ArtifactsController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def build_from_id def build_from_id
project.builds.find_by(id: params[:job_id]) if params[:job_id] project.builds.find_by(id: params[:job_id]) if params[:job_id]
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def build_from_ref def build_from_ref
return unless @ref_name return unless @ref_name
builds = project.latest_successful_builds_for(@ref_name) builds = project.latest_successful_builds_for(@ref_name)
builds.find_by(name: params[:job]) builds.find_by(name: params[:job])
end end
# rubocop: enable CodeReuse/ActiveRecord
def artifacts_file def artifacts_file
@artifacts_file ||= build.artifacts_file @artifacts_file ||= build.artifacts_file
......
...@@ -177,6 +177,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -177,6 +177,7 @@ class Projects::BlobController < Projects::ApplicationController
render_404 render_404
end end
# rubocop: disable CodeReuse/ActiveRecord
def after_edit_path def after_edit_path
from_merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:from_merge_request_iid]) from_merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:from_merge_request_iid])
if from_merge_request && @branch_name == @ref if from_merge_request && @branch_name == @ref
...@@ -186,6 +187,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -186,6 +187,7 @@ class Projects::BlobController < Projects::ApplicationController
project_blob_path(@project, File.join(@branch_name, @path)) project_blob_path(@project, File.join(@branch_name, @path))
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def editor_variables def editor_variables
@branch_name = params[:branch_name] @branch_name = params[:branch_name]
......
...@@ -48,6 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -48,6 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController
@branches = @repository.recent_branches @branches = @repository.recent_branches
end end
# rubocop: disable CodeReuse/ActiveRecord
def create def create
branch_name = sanitize(strip_tags(params[:branch_name])) branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name) branch_name = Addressable::URI.unescape(branch_name)
...@@ -88,6 +89,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -88,6 +89,7 @@ class Projects::BranchesController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def destroy def destroy
@branch_name = Addressable::URI.unescape(params[:id]) @branch_name = Addressable::URI.unescape(params[:id])
......
...@@ -42,14 +42,18 @@ class Projects::BuildArtifactsController < Projects::ApplicationController ...@@ -42,14 +42,18 @@ class Projects::BuildArtifactsController < Projects::ApplicationController
@job ||= job_from_id || job_from_ref @job ||= job_from_id || job_from_ref
end end
# rubocop: disable CodeReuse/ActiveRecord
def job_from_id def job_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id] project.builds.find_by(id: params[:build_id]) if params[:build_id]
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def job_from_ref def job_from_ref
return unless @ref_name return unless @ref_name
jobs = project.latest_successful_builds_for(@ref_name) jobs = project.latest_successful_builds_for(@ref_name)
jobs.find_by(name: params[:job]) jobs.find_by(name: params[:job])
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -4,6 +4,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll ...@@ -4,6 +4,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
before_action :authorize_read_cluster! before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:create] before_action :authorize_create_cluster!, only: [:create]
# rubocop: disable CodeReuse/ActiveRecord
def create def create
application = @application_class.find_or_initialize_by(cluster: @cluster) application = @application_class.find_or_initialize_by(cluster: @cluster)
...@@ -23,6 +24,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll ...@@ -23,6 +24,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
rescue StandardError rescue StandardError
head :bad_request head :bad_request
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -38,6 +38,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -38,6 +38,7 @@ class Projects::CommitController < Projects::ApplicationController
render_diff_for_path(@commit.diffs(diff_options)) render_diff_for_path(@commit.diffs(diff_options))
end end
# rubocop: disable CodeReuse/ActiveRecord
def pipelines def pipelines
@pipelines = @commit.pipelines.order(id: :desc) @pipelines = @commit.pipelines.order(id: :desc)
@pipelines = @pipelines.where(ref: params[:ref]) if params[:ref] @pipelines = @pipelines.where(ref: params[:ref]) if params[:ref]
...@@ -58,6 +59,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -58,6 +59,7 @@ class Projects::CommitController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def merge_requests def merge_requests
@merge_requests = @commit.merge_requests.map do |mr| @merge_requests = @commit.merge_requests.map do |mr|
...@@ -144,6 +146,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -144,6 +146,7 @@ class Projects::CommitController < Projects::ApplicationController
@environment = EnvironmentsFinder.new(@project, current_user, commit: @commit).execute.last @environment = EnvironmentsFinder.new(@project, current_user, commit: @commit).execute.last
end end
# rubocop: disable CodeReuse/ActiveRecord
def define_note_vars def define_note_vars
@noteable = @commit @noteable = @commit
@note = @project.build_commit_note(commit) @note = @project.build_commit_note(commit)
...@@ -176,6 +179,7 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -176,6 +179,7 @@ class Projects::CommitController < Projects::ApplicationController
@notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes) @notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes)
@notes = prepare_notes_for_rendering(@notes, @commit) @notes = prepare_notes_for_rendering(@notes, @commit)
end end
# rubocop: enable CodeReuse/ActiveRecord
def assign_change_commit_vars def assign_change_commit_vars
@start_branch = params[:start_branch] @start_branch = params[:start_branch]
......
...@@ -15,6 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -15,6 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController
redirect_to project_commits_path(@project, @project.default_branch) redirect_to project_commits_path(@project, @project.default_branch)
end end
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref) .find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
...@@ -32,6 +33,7 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -32,6 +33,7 @@ class Projects::CommitsController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def signatures def signatures
respond_to do |format| respond_to do |format|
......
...@@ -96,8 +96,10 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -96,8 +96,10 @@ class Projects::CompareController < Projects::ApplicationController
@diff_notes_disabled = compare.present? @diff_notes_disabled = compare.present?
end end
# rubocop: disable CodeReuse/ActiveRecord
def merge_request def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: head_ref, target_branch: start_ref) .find_by(source_project: @project, source_branch: head_ref, target_branch: start_ref)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -56,6 +56,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -56,6 +56,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def disable def disable
deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id]) deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id])
return render_404 unless deploy_key_project return render_404 unless deploy_key_project
...@@ -69,6 +70,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -69,6 +70,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
format.json { head :ok } format.json { head :ok }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
protected protected
......
...@@ -2,6 +2,7 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -2,6 +2,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
before_action :authorize_read_environment! before_action :authorize_read_environment!
before_action :authorize_read_deployment! before_action :authorize_read_deployment!
# rubocop: disable CodeReuse/ActiveRecord
def index def index
deployments = environment.deployments.reorder(created_at: :desc) deployments = environment.deployments.reorder(created_at: :desc)
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
...@@ -9,6 +10,7 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -9,6 +10,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
render json: { deployments: DeploymentSerializer.new(project: project) render json: { deployments: DeploymentSerializer.new(project: project)
.represent_concise(deployments) } .represent_concise(deployments) }
end end
# rubocop: enable CodeReuse/ActiveRecord
def metrics def metrics
return render_404 unless deployment.has_metrics? return render_404 unless deployment.has_metrics?
...@@ -41,9 +43,11 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -41,9 +43,11 @@ class Projects::DeploymentsController < Projects::ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def deployment def deployment
@deployment ||= environment.deployments.find_by(iid: params[:id]) @deployment ||= environment.deployments.find_by(iid: params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def environment def environment
@environment ||= project.environments.find(params[:environment_id]) @environment ||= project.environments.find(params[:environment_id])
......
...@@ -50,9 +50,11 @@ class Projects::DiscussionsController < Projects::ApplicationController ...@@ -50,9 +50,11 @@ class Projects::DiscussionsController < Projects::ApplicationController
} }
end end
# rubocop: disable CodeReuse/ActiveRecord
def merge_request def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id]) @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def discussion def discussion
@discussion ||= @merge_request.find_discussion(params[:id]) || render_404 @discussion ||= @merge_request.find_discussion(params[:id]) || render_404
......
...@@ -33,6 +33,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -33,6 +33,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def folder def folder
folder_environments = project.environments.where(environment_type: params[:id]) folder_environments = project.environments.where(environment_type: params[:id])
@environments = folder_environments.with_state(params[:scope] || :available) @environments = folder_environments.with_state(params[:scope] || :available)
...@@ -53,10 +54,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -53,10 +54,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@deployments = environment.deployments.order(id: :desc).page(params[:page]) @deployments = environment.deployments.order(id: :desc).page(params[:page])
end end
# rubocop: enable CodeReuse/ActiveRecord
def new def new
@environment = project.environments.new @environment = project.environments.new
......
...@@ -7,6 +7,7 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -7,6 +7,7 @@ class Projects::ForksController < Projects::ApplicationController
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :authenticate_user!, only: [:new, :create] before_action :authenticate_user!, only: [:new, :create]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
base_query = project.forks.includes(:creator) base_query = project.forks.includes(:creator)
...@@ -27,12 +28,14 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -27,12 +28,14 @@ class Projects::ForksController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def new def new
@namespaces = current_user.manageable_namespaces @namespaces = current_user.manageable_namespaces
@namespaces.delete(@project.namespace) @namespaces.delete(@project.namespace)
end end
# rubocop: disable CodeReuse/ActiveRecord
def create def create
namespace = Namespace.find(params[:namespace_key]) namespace = Namespace.find(params[:namespace_key])
...@@ -55,6 +58,7 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -55,6 +58,7 @@ class Projects::ForksController < Projects::ApplicationController
render :error render :error
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335')
......
...@@ -165,6 +165,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -165,6 +165,7 @@ class Projects::IssuesController < Projects::ApplicationController
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def issue def issue
return @issue if defined?(@issue) return @issue if defined?(@issue)
...@@ -176,6 +177,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -176,6 +177,7 @@ class Projects::IssuesController < Projects::ApplicationController
@issue @issue
end end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :subscribable_resource, :issue alias_method :subscribable_resource, :issue
alias_method :issuable, :issue alias_method :issuable, :issue
alias_method :awardable, :issue alias_method :awardable, :issue
......
...@@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController
layout 'project' layout 'project'
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@scope = params[:scope] @scope = params[:scope]
@all_builds = project.builds.relevant @all_builds = project.builds.relevant
...@@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController
]) ])
@builds = @builds.page(params[:page]).per(30).without_count @builds = @builds.page(params[:page]).per(30).without_count
end end
# rubocop: enable CodeReuse/ActiveRecord
def cancel_all def cancel_all
return access_denied! unless can?(current_user, :update_build, project) return access_denied! unless can?(current_user, :update_build, project)
...@@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController
redirect_to project_jobs_path(project) redirect_to project_jobs_path(project)
end end
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@pipeline = @build.pipeline @pipeline = @build.pipeline
@builds = @pipeline.builds @builds = @pipeline.builds
...@@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController ...@@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def trace def trace
build.trace.read do |stream| build.trace.read do |stream|
......
...@@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def set_priorities def set_priorities
Label.transaction do Label.transaction do
available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id) available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
...@@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController
format.json { render json: { message: 'success' } } format.json { render json: { message: 'success' } }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def promote def promote
promote_service = Labels::PromoteService.new(@project, @current_user) promote_service = Labels::PromoteService.new(@project, @current_user)
......
...@@ -46,11 +46,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController ...@@ -46,11 +46,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController
params[:operation] == 'upload' params[:operation] == 'upload'
end end
# rubocop: disable CodeReuse/ActiveRecord
def existing_oids def existing_oids
@existing_oids ||= begin @existing_oids ||= begin
project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid) project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def download_objects! def download_objects!
objects.each do |object| objects.each do |object|
......
...@@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController ...@@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
params[:size].to_i params[:size].to_i
end end
# rubocop: disable CodeReuse/ActiveRecord
def store_file!(oid, size) def store_file!(oid, size)
object = LfsObject.find_by(oid: oid, size: size) object = LfsObject.find_by(oid: oid, size: size)
unless object&.file&.exists? unless object&.file&.exists?
...@@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController ...@@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
link_to_project!(object) link_to_project!(object)
end end
# rubocop: enable CodeReuse/ActiveRecord
def create_file!(oid, size) def create_file!(oid, size)
uploaded_file = UploadedFile.from_params( uploaded_file = UploadedFile.from_params(
...@@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController ...@@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
LfsObject.create!(oid: oid, size: size, file: uploaded_file) LfsObject.create!(oid: oid, size: size, file: uploaded_file)
end end
# rubocop: disable CodeReuse/ActiveRecord
def link_to_project!(object) def link_to_project!(object)
if object && !object.projects.exists?(storage_project.id) if object && !object.projects.exists?(storage_project.id)
object.lfs_objects_projects.create!(project: storage_project) object.lfs_objects_projects.create!(project: storage_project)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -7,9 +7,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont ...@@ -7,9 +7,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
private private
# rubocop: disable CodeReuse/ActiveRecord
def merge_request def merge_request
@issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id]) @issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def merge_request_params def merge_request_params
params.require(:merge_request).permit(merge_request_params_attributes) params.require(:merge_request).permit(merge_request_params_attributes)
......
...@@ -111,6 +111,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap ...@@ -111,6 +111,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
set_pipeline_variables set_pipeline_variables
end end
# rubocop: disable CodeReuse/ActiveRecord
def selected_target_project def selected_target_project
if @project.id.to_s == params[:target_project_id] || !@project.forked? if @project.id.to_s == params[:target_project_id] || !@project.forked?
@project @project
...@@ -121,6 +122,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap ...@@ -121,6 +122,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
@project.forked_from_project @project.forked_from_project
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384')
......
...@@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@diffs = @compare.diffs(diff_options) @diffs = @compare.diffs(diff_options)
end end
# rubocop: disable CodeReuse/ActiveRecord
def commit def commit
return nil unless commit_id = params[:commit_id].presence return nil unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commits.exists?(sha: commit_id) return nil unless @merge_request.all_commits.exists?(sha: commit_id)
@commit ||= @project.commit(commit_id) @commit ||= @project.commit(commit_id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_diff_compare def find_merge_request_diff_compare
@merge_request_diff = @merge_request_diff =
if diff_id = params[:diff_id].presence if diff_id = params[:diff_id].presence
...@@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@merge_request_diff @merge_request_diff
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def additional_attributes def additional_attributes
{ {
......
...@@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def milestone def milestone
@milestone ||= @project.milestones.find_by!(iid: params[:id]) @milestone ||= @project.milestones.find_by!(iid: params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
def authorize_admin_milestone! def authorize_admin_milestone!
return render_404 unless can?(current_user, :admin_milestone, @project) return render_404 unless can?(current_user, :admin_milestone, @project)
......
...@@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController ...@@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController
before_action :authorize_read_pages!, only: [:show] before_action :authorize_read_pages!, only: [:show]
before_action :authorize_update_pages!, except: [:show] before_action :authorize_update_pages!, except: [:show]
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@domains = @project.pages_domains.order(:domain) @domains = @project.pages_domains.order(:domain)
end end
# rubocop: enable CodeReuse/ActiveRecord
def destroy def destroy
project.remove_pages project.remove_pages
......
...@@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController ...@@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController
params.require(:pages_domain).permit(:key, :certificate) params.require(:pages_domain).permit(:key, :certificate)
end end
# rubocop: disable CodeReuse/ActiveRecord
def domain def domain
@domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s) @domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController ...@@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play] before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play]
before_action :authorize_admin_pipeline_schedule!, only: [:destroy] before_action :authorize_admin_pipeline_schedule!, only: [:destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@scope = params[:scope] @scope = params[:scope]
@all_schedules = PipelineSchedulesFinder.new(@project).execute @all_schedules = PipelineSchedulesFinder.new(@project).execute
@schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope]) @schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope])
.includes(:last_pipeline) .includes(:last_pipeline)
end end
# rubocop: enable CodeReuse/ActiveRecord
def new def new
@schedule = project.pipeline_schedules.new @schedule = project.pipeline_schedules.new
......
...@@ -161,6 +161,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -161,6 +161,7 @@ class Projects::PipelinesController < Projects::ApplicationController
params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value]) params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value])
end end
# rubocop: disable CodeReuse/ActiveRecord
def pipeline def pipeline
@pipeline ||= project @pipeline ||= project
.pipelines .pipelines
...@@ -168,6 +169,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -168,6 +169,7 @@ class Projects::PipelinesController < Projects::ApplicationController
.find_by!(id: params[:id]) .find_by!(id: params[:id])
.present(current_user: current_user) .present(current_user: current_user)
end end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting def whitelist_query_limiting
# Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343 # Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343
......
...@@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
# Authorize # Authorize
before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access] before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@sort = params[:sort].presence || sort_value_name @sort = params[:sort].presence || sort_value_name
@group_links = @project.project_group_links @group_links = @project.project_group_links
...@@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user)) @requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user))
@project_member = @project.project_members.new @project_member = @project.project_members.new
end end
# rubocop: enable CodeReuse/ActiveRecord
def import def import
@projects = current_user.authorized_projects.order_id_desc @projects = current_user.authorized_projects.order_id_desc
......
...@@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController
@tag ||= @repository.find_tag(params[:tag_id]) @tag ||= @repository.find_tag(params[:tag_id])
end end
# rubocop: disable CodeReuse/ActiveRecord
def release def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name) @release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end end
# rubocop: enable CodeReuse/ActiveRecord
def release_params def release_params
params.require(:release).permit(:description) params.require(:release).permit(:description)
......
...@@ -33,6 +33,7 @@ module Projects ...@@ -33,6 +33,7 @@ module Projects
render 'show' render 'show'
end end
# rubocop: disable CodeReuse/ActiveRecord
def define_protected_refs def define_protected_refs
@protected_branches = @project.protected_branches.order(:name).page(params[:page]) @protected_branches = @project.protected_branches.order(:name).page(params[:page])
@protected_tags = @project.protected_tags.order(:name).page(params[:page]) @protected_tags = @project.protected_tags.order(:name).page(params[:page])
...@@ -44,6 +45,7 @@ module Projects ...@@ -44,6 +45,7 @@ module Projects
load_gon_index load_gon_index
end end
# rubocop: enable CodeReuse/ActiveRecord
def remote_mirror def remote_mirror
@remote_mirror = project.remote_mirrors.first_or_initialize @remote_mirror = project.remote_mirrors.first_or_initialize
......
...@@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController
before_action :authorize_push_code!, only: [:new, :create] before_action :authorize_push_code!, only: [:new, :create]
before_action :authorize_admin_project!, only: [:destroy] before_action :authorize_admin_project!, only: [:destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index def index
params[:sort] = params[:sort].presence || sort_value_recently_updated params[:sort] = params[:sort].presence || sort_value_recently_updated
...@@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController
format.atom { render layout: 'xml.atom' } format.atom { render layout: 'xml.atom' }
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def show def show
@tag = @repository.find_tag(params[:id]) @tag = @repository.find_tag(params[:id])
...@@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController ...@@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController
@release = @project.releases.find_or_initialize_by(tag: @tag.name) @release = @project.releases.find_or_initialize_by(tag: @tag.name)
@commit = @repository.commit(@tag.dereferenced_target) @commit = @repository.commit(@tag.dereferenced_target)
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
result = Tags::CreateService.new(@project, current_user) result = Tags::CreateService.new(@project, current_user)
......
...@@ -27,12 +27,14 @@ class ProjectsController < Projects::ApplicationController ...@@ -27,12 +27,14 @@ class ProjectsController < Projects::ApplicationController
redirect_to(current_user ? root_path : explore_root_path) redirect_to(current_user ? root_path : explore_root_path)
end end
# rubocop: disable CodeReuse/ActiveRecord
def new def new
namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id] namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id]
return access_denied! if namespace && !can?(current_user, :create_projects, namespace) return access_denied! if namespace && !can?(current_user, :create_projects, namespace)
@project = Project.new(namespace_id: namespace&.id) @project = Project.new(namespace_id: namespace&.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
def edit def edit
@badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id)) @badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id))
...@@ -77,6 +79,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -77,6 +79,7 @@ class ProjectsController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def transfer def transfer
return access_denied! unless can?(current_user, :change_namespace, @project) return access_denied! unless can?(current_user, :change_namespace, @project)
...@@ -87,6 +90,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -87,6 +90,7 @@ class ProjectsController < Projects::ApplicationController
flash[:alert] = @project.errors[:new_namespace].first flash[:alert] = @project.errors[:new_namespace].first
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def remove_fork def remove_fork
return access_denied! unless can?(current_user, :remove_fork_project, @project) return access_denied! unless can?(current_user, :remove_fork_project, @project)
...@@ -233,6 +237,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -233,6 +237,7 @@ class ProjectsController < Projects::ApplicationController
} }
end end
# rubocop: disable CodeReuse/ActiveRecord
def refs def refs
find_refs = params['find'] find_refs = params['find']
...@@ -267,6 +272,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -267,6 +272,7 @@ class ProjectsController < Projects::ApplicationController
render json: options.to_json render json: options.to_json
end end
# rubocop: enable CodeReuse/ActiveRecord
# Render project landing depending of which features are available # Render project landing depending of which features are available
# So if page is not availble in the list it renders the next page # So if page is not availble in the list it renders the next page
...@@ -305,6 +311,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -305,6 +311,7 @@ class ProjectsController < Projects::ApplicationController
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def load_events def load_events
projects = Project.where(id: @project.id) projects = Project.where(id: @project.id)
...@@ -314,6 +321,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -314,6 +321,7 @@ class ProjectsController < Projects::ApplicationController
Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?) Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
end end
# rubocop: enable CodeReuse/ActiveRecord
def project_params def project_params
params.require(:project) params.require(:project)
......
...@@ -31,6 +31,7 @@ class SearchController < ApplicationController ...@@ -31,6 +31,7 @@ class SearchController < ApplicationController
check_single_commit_result check_single_commit_result
end end
# rubocop: disable CodeReuse/ActiveRecord
def autocomplete def autocomplete
term = params[:term] term = params[:term]
...@@ -43,6 +44,7 @@ class SearchController < ApplicationController ...@@ -43,6 +44,7 @@ class SearchController < ApplicationController
render json: search_autocomplete_opts(term).to_json render json: search_autocomplete_opts(term).to_json
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -108,6 +108,7 @@ class SessionsController < Devise::SessionsController ...@@ -108,6 +108,7 @@ class SessionsController < Devise::SessionsController
# Handle an "initial setup" state, where there's only one user, it's an admin, # Handle an "initial setup" state, where there's only one user, it's an admin,
# and they require a password change. # and they require a password change.
# rubocop: disable CodeReuse/ActiveRecord
def check_initial_setup def check_initial_setup
return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one
...@@ -122,6 +123,7 @@ class SessionsController < Devise::SessionsController ...@@ -122,6 +123,7 @@ class SessionsController < Devise::SessionsController
redirect_to edit_user_password_path(reset_password_token: @token), redirect_to edit_user_password_path(reset_password_token: @token),
notice: "Please create a password for your new account." notice: "Please create a password for your new account."
end end
# rubocop: enable CodeReuse/ActiveRecord
def user_params def user_params
params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response) params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response)
......
...@@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController ...@@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController
nil nil
end end
# rubocop: disable CodeReuse/ActiveRecord
def snippet def snippet
PersonalSnippet.find_by(id: params[:snippet_id]) PersonalSnippet.find_by(id: params[:snippet_id])
end end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :snippet alias_method :noteable, :snippet
def note_params def note_params
......
...@@ -24,6 +24,7 @@ class SnippetsController < ApplicationController ...@@ -24,6 +24,7 @@ class SnippetsController < ApplicationController
layout 'snippets' layout 'snippets'
respond_to :html respond_to :html
# rubocop: disable CodeReuse/ActiveRecord
def index def index
if params[:username].present? if params[:username].present?
@user = User.find_by(username: params[:username]) @user = User.find_by(username: params[:username])
...@@ -38,6 +39,7 @@ class SnippetsController < ApplicationController ...@@ -38,6 +39,7 @@ class SnippetsController < ApplicationController
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path) redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def new def new
@snippet = PersonalSnippet.new @snippet = PersonalSnippet.new
...@@ -94,9 +96,11 @@ class SnippetsController < ApplicationController ...@@ -94,9 +96,11 @@ class SnippetsController < ApplicationController
protected protected
# rubocop: disable CodeReuse/ActiveRecord
def snippet def snippet
@snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id]) @snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id])
end end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :awardable, :snippet alias_method :awardable, :snippet
alias_method :spammable, :snippet alias_method :spammable, :snippet
......
...@@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController ...@@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController
private private
# rubocop: disable CodeReuse/ActiveRecord
def ensure_callout def ensure_callout
current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name]) current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name])
end end
# rubocop: enable CodeReuse/ActiveRecord
def feature_name def feature_name
params.require(:feature_name) params.require(:feature_name)
......
...@@ -6,6 +6,7 @@ class Admin::ProjectsFinder ...@@ -6,6 +6,7 @@ class Admin::ProjectsFinder
@current_user = current_user @current_user = current_user
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
items = Project.without_deleted.with_statistics.with_route items = Project.without_deleted.with_statistics.with_route
items = by_namespace_id(items) items = by_namespace_id(items)
...@@ -19,6 +20,7 @@ class Admin::ProjectsFinder ...@@ -19,6 +20,7 @@ class Admin::ProjectsFinder
items = items.includes(namespace: [:owner, :route]) items = items.includes(namespace: [:owner, :route])
sort(items).page(params[:page]) sort(items).page(params[:page])
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -26,9 +28,11 @@ class Admin::ProjectsFinder ...@@ -26,9 +28,11 @@ class Admin::ProjectsFinder
params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_visibilty_level(items) def by_visibilty_level(items)
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_with_push(items) def by_with_push(items)
params[:with_push].present? ? items.with_push : items params[:with_push].present? ? items.with_push : items
...@@ -38,9 +42,11 @@ class Admin::ProjectsFinder ...@@ -38,9 +42,11 @@ class Admin::ProjectsFinder
params[:abandoned].present? ? items.abandoned : items params[:abandoned].present? ? items.abandoned : items
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_last_repository_check_failed(items) def by_last_repository_check_failed(items)
params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_archived(items) def by_archived(items)
if params[:archived] == 'only' if params[:archived] == 'only'
......
...@@ -46,6 +46,7 @@ module Autocomplete ...@@ -46,6 +46,7 @@ module Autocomplete
# Returns the users based on the input parameters, as an Array. # Returns the users based on the input parameters, as an Array.
# #
# This method is separate so it is easier to extend in EE. # This method is separate so it is easier to extend in EE.
# rubocop: disable CodeReuse/ActiveRecord
def limited_users def limited_users
# When changing the order of these method calls, make sure that # When changing the order of these method calls, make sure that
# reorder_by_name() is called _before_ optionally_search(), otherwise # reorder_by_name() is called _before_ optionally_search(), otherwise
...@@ -63,6 +64,7 @@ module Autocomplete ...@@ -63,6 +64,7 @@ module Autocomplete
.limit(LIMIT) .limit(LIMIT)
.to_a .to_a
end end
# rubocop: enable CodeReuse/ActiveRecord
def prepend_current_user? def prepend_current_user?
filter_by_current_user.present? && current_user filter_by_current_user.present? && current_user
...@@ -72,6 +74,7 @@ module Autocomplete ...@@ -72,6 +74,7 @@ module Autocomplete
author_id.present? && current_user author_id.present? && current_user
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_users def find_users
if project if project
project.authorized_users.union_with_user(author_id) project.authorized_users.union_with_user(author_id)
...@@ -83,5 +86,6 @@ module Autocomplete ...@@ -83,5 +86,6 @@ module Autocomplete
User.none User.none
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
module CustomAttributesFilter module CustomAttributesFilter
# rubocop: disable CodeReuse/ActiveRecord
def by_custom_attributes(items) def by_custom_attributes(items)
return items unless params[:custom_attributes].is_a?(Hash) return items unless params[:custom_attributes].is_a?(Hash)
return items unless Ability.allowed?(current_user, :read_custom_attribute) return items unless Ability.allowed?(current_user, :read_custom_attribute)
...@@ -17,4 +18,5 @@ module CustomAttributesFilter ...@@ -17,4 +18,5 @@ module CustomAttributesFilter
scope.where('EXISTS (?)', custom_attributes.where(key: key, value: value)) scope.where('EXISTS (?)', custom_attributes.where(key: key, value: value))
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
module FinderMethods module FinderMethods
# rubocop: disable CodeReuse/ActiveRecord
def find_by!(*args) def find_by!(*args)
raise_not_found_unless_authorized execute.find_by!(*args) raise_not_found_unless_authorized execute.find_by!(*args)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_by(*args) def find_by(*args)
if_authorized execute.find_by(*args) if_authorized execute.find_by(*args)
end end
# rubocop: enable CodeReuse/ActiveRecord
def find(*args) def find(*args)
raise_not_found_unless_authorized model.find(*args) raise_not_found_unless_authorized model.find(*args)
......
...@@ -14,6 +14,7 @@ module FinderWithCrossProjectAccess ...@@ -14,6 +14,7 @@ module FinderWithCrossProjectAccess
end end
override :execute override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(*args) def execute(*args)
check = Gitlab::CrossProjectAccess.find_check(self) check = Gitlab::CrossProjectAccess.find_check(self)
original = super original = super
...@@ -27,6 +28,7 @@ module FinderWithCrossProjectAccess ...@@ -27,6 +28,7 @@ module FinderWithCrossProjectAccess
original original
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# We can skip the cross project check for finding indivitual records. # We can skip the cross project check for finding indivitual records.
# this would be handled by the `can?(:read_*, result)` call in `FinderMethods` # this would be handled by the `can?(:read_*, result)` call in `FinderMethods`
......
...@@ -10,11 +10,13 @@ class ContributedProjectsFinder < UnionFinder ...@@ -10,11 +10,13 @@ class ContributedProjectsFinder < UnionFinder
# visible by this user. # visible by this user.
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
# rubocop: disable CodeReuse/ActiveRecord
def execute(current_user = nil) def execute(current_user = nil)
segments = all_projects(current_user) segments = all_projects(current_user)
find_union(segments, Project).includes(:namespace).order_id_desc find_union(segments, Project).includes(:namespace).order_id_desc
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -5,6 +5,7 @@ class EnvironmentsFinder ...@@ -5,6 +5,7 @@ class EnvironmentsFinder
@project, @current_user, @params = project, current_user, params @project, @current_user, @params = project, current_user, params
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute def execute
deployments = project.deployments deployments = project.deployments
deployments = deployments =
...@@ -42,6 +43,7 @@ class EnvironmentsFinder ...@@ -42,6 +43,7 @@ class EnvironmentsFinder
environments environments
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -36,32 +36,42 @@ class EventsFinder ...@@ -36,32 +36,42 @@ class EventsFinder
private private
# rubocop: disable CodeReuse/ActiveRecord
def by_current_user_access(events) 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) .joins(:project)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_action(events) def by_action(events)
return events unless Event::ACTIONS[params[:action]] return events unless Event::ACTIONS[params[:action]]
events.where(action: Event::ACTIONS[params[:action]]) events.where(action: Event::ACTIONS[params[:action]])
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_target_type(events) def by_target_type(events)
return events unless Event::TARGET_TYPES[params[:target_type]] return events unless Event::TARGET_TYPES[params[:target_type]]
events.where(target_type: Event::TARGET_TYPES[params[:target_type]]) events.where(target_type: Event::TARGET_TYPES[params[:target_type]])
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_before(events) def by_created_at_before(events)
return events unless params[:before] return events unless params[:before]
events.where('events.created_at < ?', params[:before].beginning_of_day) events.where('events.created_at < ?', params[:before].beginning_of_day)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_after(events) def by_created_at_after(events)
return events unless params[:after] return events unless params[:after]
events.where('events.created_at > ?', params[:after].end_of_day) events.where('events.created_at > ?', params[:after].end_of_day)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
class ForkProjectsFinder < ProjectsFinder class ForkProjectsFinder < ProjectsFinder
# rubocop: disable CodeReuse/ActiveRecord
def initialize(project, params: {}, current_user: nil) def initialize(project, params: {}, current_user: nil)
project_ids = project.forks.includes(:creator).select(:id) project_ids = project.forks.includes(:creator).select(:id)
super(params: params, current_user: current_user, project_ids_relation: project_ids) super(params: params, current_user: current_user, project_ids_relation: project_ids)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -61,12 +61,16 @@ class GroupDescendantsFinder ...@@ -61,12 +61,16 @@ class GroupDescendantsFinder
end end
def direct_child_groups def direct_child_groups
# rubocop: disable CodeReuse/Finder
GroupsFinder.new(current_user, GroupsFinder.new(current_user,
parent: parent_group, parent: parent_group,
all_available: true).execute all_available: true).execute
# rubocop: enable CodeReuse/Finder
end end
# rubocop: disable CodeReuse/ActiveRecord
def all_visible_descendant_groups def all_visible_descendant_groups
# rubocop: disable CodeReuse/Finder
groups_table = Group.arel_table groups_table = Group.arel_table
visible_to_user = groups_table[:visibility_level] visible_to_user = groups_table[:visibility_level]
.in(Gitlab::VisibilityLevel.levels_for_user(current_user)) .in(Gitlab::VisibilityLevel.levels_for_user(current_user))
...@@ -84,7 +88,9 @@ class GroupDescendantsFinder ...@@ -84,7 +88,9 @@ class GroupDescendantsFinder
hierarchy_for_parent hierarchy_for_parent
.descendants .descendants
.where(visible_to_user) .where(visible_to_user)
# rubocop: enable CodeReuse/Finder
end end
# rubocop: enable CodeReuse/ActiveRecord
def subgroups_matching_filter def subgroups_matching_filter
all_visible_descendant_groups all_visible_descendant_groups
...@@ -101,24 +107,29 @@ class GroupDescendantsFinder ...@@ -101,24 +107,29 @@ class GroupDescendantsFinder
# #
# So when searching 'project', on the 'subgroup' page we want to preload # So when searching 'project', on the 'subgroup' page we want to preload
# 'nested-group' but not 'subgroup' or 'root' # 'nested-group' but not 'subgroup' or 'root'
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_groups(base_for_ancestors) def ancestors_of_groups(base_for_ancestors)
group_ids = base_for_ancestors.except(:select, :sort).select(:id) group_ids = base_for_ancestors.except(:select, :sort).select(:id)
Gitlab::GroupHierarchy.new(Group.where(id: group_ids)) Gitlab::GroupHierarchy.new(Group.where(id: group_ids))
.base_and_ancestors(upto: parent_group.id) .base_and_ancestors(upto: parent_group.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_filtered_projects def ancestors_of_filtered_projects
projects_to_load_ancestors_of = projects.where.not(namespace: parent_group) 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)) groups_to_load_ancestors_of = Group.where(id: projects_to_load_ancestors_of.select(:namespace_id))
ancestors_of_groups(groups_to_load_ancestors_of) ancestors_of_groups(groups_to_load_ancestors_of)
.with_selects_for_list(archived: params[:archived]) .with_selects_for_list(archived: params[:archived])
end end
# rubocop: enable CodeReuse/ActiveRecord
def ancestors_of_filtered_subgroups def ancestors_of_filtered_subgroups
ancestors_of_groups(subgroups) ancestors_of_groups(subgroups)
.with_selects_for_list(archived: params[:archived]) .with_selects_for_list(archived: params[:archived])
end end
# rubocop: disable CodeReuse/ActiveRecord
def subgroups def subgroups
return Group.none unless Group.supports_nested_groups? return Group.none unless Group.supports_nested_groups?
...@@ -132,22 +143,29 @@ class GroupDescendantsFinder ...@@ -132,22 +143,29 @@ class GroupDescendantsFinder
groups.with_selects_for_list(archived: params[:archived]).order_by(sort) groups.with_selects_for_list(archived: params[:archived]).order_by(sort)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/Finder
def direct_child_projects def direct_child_projects
GroupProjectsFinder.new(group: parent_group, current_user: current_user, params: params, options: { only_owned: true }) GroupProjectsFinder.new(group: parent_group, current_user: current_user, params: params, options: { only_owned: true })
.execute .execute
end end
# rubocop: enable CodeReuse/Finder
# Finds all projects nested under `parent_group` or any of its descendant # Finds all projects nested under `parent_group` or any of its descendant
# groups # groups
# rubocop: disable CodeReuse/ActiveRecord
def projects_matching_filter def projects_matching_filter
# rubocop: disable CodeReuse/Finder
projects_nested_in_group = Project.where(namespace_id: hierarchy_for_parent.base_and_descendants.select(:id)) projects_nested_in_group = Project.where(namespace_id: hierarchy_for_parent.base_and_descendants.select(:id))
params_with_search = params.merge(search: params[:filter]) params_with_search = params.merge(search: params[:filter])
ProjectsFinder.new(params: params_with_search, ProjectsFinder.new(params: params_with_search,
current_user: current_user, current_user: current_user,
project_ids_relation: projects_nested_in_group).execute project_ids_relation: projects_nested_in_group).execute
# rubocop: enable CodeReuse/Finder
end end
# rubocop: enable CodeReuse/ActiveRecord
def projects def projects
projects = if params[:filter] projects = if params[:filter]
...@@ -163,7 +181,9 @@ class GroupDescendantsFinder ...@@ -163,7 +181,9 @@ class GroupDescendantsFinder
params.fetch(:sort, 'id_asc') params.fetch(:sort, 'id_asc')
end end
# rubocop: disable CodeReuse/ActiveRecord
def hierarchy_for_parent def hierarchy_for_parent
@hierarchy ||= Gitlab::GroupHierarchy.new(Group.where(id: parent_group.id)) @hierarchy ||= Gitlab::GroupHierarchy.new(Group.where(id: parent_group.id))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -5,6 +5,7 @@ class GroupFinder ...@@ -5,6 +5,7 @@ class GroupFinder
@current_user = current_user @current_user = current_user
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute(*params) def execute(*params)
group = Group.find_by(*params) group = Group.find_by(*params)
...@@ -14,4 +15,5 @@ class GroupFinder ...@@ -14,4 +15,5 @@ class GroupFinder
nil nil
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -3,6 +3,7 @@ class GroupMembersFinder ...@@ -3,6 +3,7 @@ class GroupMembersFinder
@group = group @group = group
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false) def execute(include_descendants: false)
group_members = @group.members group_members = @group.members
wheres = [] wheres = []
...@@ -29,4 +30,5 @@ class GroupMembersFinder ...@@ -29,4 +30,5 @@ class GroupMembersFinder
GroupMember.where(wheres.join(' OR ')) GroupMember.where(wheres.join(' OR '))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -82,6 +82,7 @@ class GroupProjectsFinder < ProjectsFinder ...@@ -82,6 +82,7 @@ class GroupProjectsFinder < ProjectsFinder
options.fetch(:include_subgroups, false) options.fetch(:include_subgroups, false)
end end
# rubocop: disable CodeReuse/ActiveRecord
def owned_projects def owned_projects
if include_subgroups? if include_subgroups?
Project.where(namespace_id: group.self_and_descendants.select(:id)) Project.where(namespace_id: group.self_and_descendants.select(:id))
...@@ -89,6 +90,7 @@ class GroupProjectsFinder < ProjectsFinder ...@@ -89,6 +90,7 @@ class GroupProjectsFinder < ProjectsFinder
group.projects group.projects
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def shared_projects def shared_projects
group.shared_projects group.shared_projects
......
...@@ -38,6 +38,7 @@ class GroupsFinder < UnionFinder ...@@ -38,6 +38,7 @@ class GroupsFinder < UnionFinder
attr_reader :current_user, :params attr_reader :current_user, :params
# rubocop: disable CodeReuse/ActiveRecord
def all_groups def all_groups
return [owned_groups] if params[:owned] return [owned_groups] if params[:owned]
return [groups_with_min_access_level] if min_access_level? return [groups_with_min_access_level] if min_access_level?
...@@ -49,6 +50,7 @@ class GroupsFinder < UnionFinder ...@@ -49,6 +50,7 @@ class GroupsFinder < UnionFinder
groups << Group.none if groups.empty? groups << Group.none if groups.empty?
groups groups
end end
# rubocop: enable CodeReuse/ActiveRecord
def groups_for_ancestors def groups_for_ancestors
current_user.authorized_groups current_user.authorized_groups
...@@ -58,6 +60,7 @@ class GroupsFinder < UnionFinder ...@@ -58,6 +60,7 @@ class GroupsFinder < UnionFinder
current_user.groups current_user.groups
end end
# rubocop: disable CodeReuse/ActiveRecord
def groups_with_min_access_level def groups_with_min_access_level
groups = current_user groups = current_user
.groups .groups
...@@ -67,16 +70,21 @@ class GroupsFinder < UnionFinder ...@@ -67,16 +70,21 @@ class GroupsFinder < UnionFinder
.new(groups) .new(groups)
.base_and_descendants .base_and_descendants
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_parent(groups) def by_parent(groups)
return groups unless params[:parent] return groups unless params[:parent]
groups.where(parent: params[:parent]) groups.where(parent: params[:parent])
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def owned_groups def owned_groups
current_user&.owned_groups || Group.none current_user&.owned_groups || Group.none
end end
# rubocop: enable CodeReuse/ActiveRecord
def include_public_groups? def include_public_groups?
current_user.nil? || all_available? current_user.nil? || all_available?
......
...@@ -109,6 +109,7 @@ class IssuableFinder ...@@ -109,6 +109,7 @@ class IssuableFinder
# (even if that query is slower than any of the individual state queries) and # (even if that query is slower than any of the individual state queries) and
# grouping and counting within that query. # grouping and counting within that query.
# #
# rubocop: disable CodeReuse/ActiveRecord
def count_by_state def count_by_state
count_params = params.merge(state: nil, sort: nil) count_params = params.merge(state: nil, sort: nil)
finder = self.class.new(current_user, count_params) finder = self.class.new(current_user, count_params)
...@@ -132,6 +133,7 @@ class IssuableFinder ...@@ -132,6 +133,7 @@ class IssuableFinder
counts.with_indifferent_access counts.with_indifferent_access
end end
# rubocop: enable CodeReuse/ActiveRecord
def group def group
return @group if defined?(@group) return @group if defined?(@group)
...@@ -157,6 +159,7 @@ class IssuableFinder ...@@ -157,6 +159,7 @@ class IssuableFinder
@project = project @project = project
end end
# rubocop: disable CodeReuse/ActiveRecord
def projects(items = nil) def projects(items = nil)
return @projects = project if project? return @projects = project if project?
...@@ -165,13 +168,14 @@ class IssuableFinder ...@@ -165,13 +168,14 @@ class IssuableFinder
current_user.authorized_projects current_user.authorized_projects
elsif group elsif group
finder_options = { include_subgroups: params[:include_subgroups], only_owned: true } 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 else
ProjectsFinder.new(current_user: current_user).execute ProjectsFinder.new(current_user: current_user).execute # rubocop: disable CodeReuse/Finder
end end
@projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil) @projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil)
end end
# rubocop: enable CodeReuse/ActiveRecord
def search def search
params[:search].presence params[:search].presence
...@@ -185,6 +189,7 @@ class IssuableFinder ...@@ -185,6 +189,7 @@ class IssuableFinder
milestones? && params[:milestone_title] == Milestone::None.title milestones? && params[:milestone_title] == Milestone::None.title
end end
# rubocop: disable CodeReuse/ActiveRecord
def milestones def milestones
return @milestones if defined?(@milestones) return @milestones if defined?(@milestones)
...@@ -200,11 +205,12 @@ class IssuableFinder ...@@ -200,11 +205,12 @@ class IssuableFinder
search_params = search_params =
{ title: params[:milestone_title], project_ids: project_id, group_ids: group_id } { 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 else
Milestone.none Milestone.none
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def labels? def labels?
params[:label_name].present? params[:label_name].present?
...@@ -214,16 +220,18 @@ class IssuableFinder ...@@ -214,16 +220,18 @@ class IssuableFinder
labels? && params[:label_name].include?(Label::None.title) labels? && params[:label_name].include?(Label::None.title)
end end
# rubocop: disable CodeReuse/ActiveRecord
def labels def labels
return @labels if defined?(@labels) return @labels if defined?(@labels)
@labels = @labels =
if labels? && !filter_by_no_label? 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 else
Label.none Label.none
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def assignee_id? def assignee_id?
params[:assignee_id].present? && params[:assignee_id] != NONE params[:assignee_id].present? && params[:assignee_id] != NONE
...@@ -238,6 +246,7 @@ class IssuableFinder ...@@ -238,6 +246,7 @@ class IssuableFinder
params[:assignee_id] == NONE || params[:assignee_username] == NONE params[:assignee_id] == NONE || params[:assignee_username] == NONE
end end
# rubocop: disable CodeReuse/ActiveRecord
def assignee def assignee
return @assignee if defined?(@assignee) return @assignee if defined?(@assignee)
...@@ -250,6 +259,7 @@ class IssuableFinder ...@@ -250,6 +259,7 @@ class IssuableFinder
nil nil
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def author_id? def author_id?
params[:author_id].present? && params[:author_id] != NONE params[:author_id].present? && params[:author_id] != NONE
...@@ -264,6 +274,7 @@ class IssuableFinder ...@@ -264,6 +274,7 @@ class IssuableFinder
params[:author_id] == NONE || params[:author_username] == NONE params[:author_id] == NONE || params[:author_username] == NONE
end end
# rubocop: disable CodeReuse/ActiveRecord
def author def author
return @author if defined?(@author) return @author if defined?(@author)
...@@ -276,6 +287,7 @@ class IssuableFinder ...@@ -276,6 +287,7 @@ class IssuableFinder
nil nil
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -283,6 +295,7 @@ class IssuableFinder ...@@ -283,6 +295,7 @@ class IssuableFinder
klass.all klass.all
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_scope(items) def by_scope(items)
return items.none if current_user_related? && !current_user return items.none if current_user_related? && !current_user
...@@ -295,6 +308,7 @@ class IssuableFinder ...@@ -295,6 +308,7 @@ class IssuableFinder
items items
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_updated_at(items) def by_updated_at(items)
items = items.updated_after(params[:updated_after]) if params[:updated_after].present? items = items.updated_after(params[:updated_after]) if params[:updated_after].present?
...@@ -303,6 +317,7 @@ class IssuableFinder ...@@ -303,6 +317,7 @@ class IssuableFinder
items items
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_state(items) def by_state(items)
case params[:state].to_s case params[:state].to_s
when 'closed' when 'closed'
...@@ -317,12 +332,14 @@ class IssuableFinder ...@@ -317,12 +332,14 @@ class IssuableFinder
items items
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_group(items) def by_group(items)
# Selection by group is already covered by `by_project` and `projects` # Selection by group is already covered by `by_project` and `projects`
items items
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_project(items) def by_project(items)
items = items =
if project? if project?
...@@ -335,6 +352,7 @@ class IssuableFinder ...@@ -335,6 +352,7 @@ class IssuableFinder
items items
end end
# rubocop: enable CodeReuse/ActiveRecord
def use_cte_for_search? def use_cte_for_search?
return false unless search return false unless search
...@@ -343,6 +361,7 @@ class IssuableFinder ...@@ -343,6 +361,7 @@ class IssuableFinder
params[:use_cte_for_search] params[:use_cte_for_search]
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_search(items) def by_search(items)
return items unless search return items unless search
...@@ -355,17 +374,23 @@ class IssuableFinder ...@@ -355,17 +374,23 @@ class IssuableFinder
items.full_search(search) items.full_search(search)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_iids(items) def by_iids(items)
params[:iids].present? ? items.where(iid: params[:iids]) : items params[:iids].present? ? items.where(iid: params[:iids]) : items
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def sort(items) def sort(items)
# Ensure we always have an explicit sort order (instead of inheriting # Ensure we always have an explicit sort order (instead of inheriting
# multiple orders when combining ActiveRecord::Relation objects). # multiple orders when combining ActiveRecord::Relation objects).
params[:sort] ? items.sort_by_attribute(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc) params[:sort] ? items.sort_by_attribute(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items) def by_assignee(items)
if assignee if assignee
items = items.where(assignee_id: assignee.id) items = items.where(assignee_id: assignee.id)
...@@ -377,7 +402,9 @@ class IssuableFinder ...@@ -377,7 +402,9 @@ class IssuableFinder
items items
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_author(items) def by_author(items)
if author if author
items = items.where(author_id: author.id) items = items.where(author_id: author.id)
...@@ -389,6 +416,7 @@ class IssuableFinder ...@@ -389,6 +416,7 @@ class IssuableFinder
items items
end end
# rubocop: enable CodeReuse/ActiveRecord
def filter_by_upcoming_milestone? def filter_by_upcoming_milestone?
params[:milestone_title] == Milestone::Upcoming.name params[:milestone_title] == Milestone::Upcoming.name
...@@ -398,6 +426,7 @@ class IssuableFinder ...@@ -398,6 +426,7 @@ class IssuableFinder
params[:milestone_title] == Milestone::Started.name params[:milestone_title] == Milestone::Started.name
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_milestone(items) def by_milestone(items)
if milestones? if milestones?
if filter_by_no_milestone? if filter_by_no_milestone?
...@@ -414,6 +443,7 @@ class IssuableFinder ...@@ -414,6 +443,7 @@ class IssuableFinder
items items
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_label(items) def by_label(items)
return items unless labels? return items unless labels?
......
...@@ -31,10 +31,13 @@ class IssuesFinder < IssuableFinder ...@@ -31,10 +31,13 @@ class IssuesFinder < IssuableFinder
@scalar_params ||= super + [:due_date] @scalar_params ||= super + [:due_date]
end end
# rubocop: disable CodeReuse/ActiveRecord
def klass def klass
Issue.includes(:author) Issue.includes(:author)
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def with_confidentiality_access_check def with_confidentiality_access_check
return Issue.all if user_can_see_all_confidential_issues? return Issue.all if user_can_see_all_confidential_issues?
return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues? return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues?
...@@ -48,6 +51,7 @@ class IssuesFinder < IssuableFinder ...@@ -48,6 +51,7 @@ class IssuesFinder < IssuableFinder
user_id: current_user.id, user_id: current_user.id,
project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id)) project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id))
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -127,6 +131,7 @@ class IssuesFinder < IssuableFinder ...@@ -127,6 +131,7 @@ class IssuesFinder < IssuableFinder
current_user.blank? current_user.blank?
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items) def by_assignee(items)
if assignee if assignee
items.assigned_to(assignee) items.assigned_to(assignee)
...@@ -138,4 +143,5 @@ class IssuesFinder < IssuableFinder ...@@ -138,4 +143,5 @@ class IssuesFinder < IssuableFinder
items items
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -10,6 +10,7 @@ class LabelsFinder < UnionFinder ...@@ -10,6 +10,7 @@ class LabelsFinder < UnionFinder
@params = params @params = params
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute(skip_authorization: false) def execute(skip_authorization: false)
@skip_authorization = skip_authorization @skip_authorization = skip_authorization
items = find_union(label_ids, Label) || Label.none items = find_union(label_ids, Label) || Label.none
...@@ -17,11 +18,13 @@ class LabelsFinder < UnionFinder ...@@ -17,11 +18,13 @@ class LabelsFinder < UnionFinder
items = by_search(items) items = by_search(items)
sort(items) sort(items)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
attr_reader :current_user, :params, :skip_authorization attr_reader :current_user, :params, :skip_authorization
# rubocop: disable CodeReuse/ActiveRecord
def label_ids def label_ids
label_ids = [] label_ids = []
...@@ -52,7 +55,9 @@ class LabelsFinder < UnionFinder ...@@ -52,7 +55,9 @@ class LabelsFinder < UnionFinder
label_ids label_ids
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def sort(items) def sort(items)
if params[:sort] if params[:sort]
items.order_by(params[:sort]) items.order_by(params[:sort])
...@@ -60,13 +65,16 @@ class LabelsFinder < UnionFinder ...@@ -60,13 +65,16 @@ class LabelsFinder < UnionFinder
items.reorder(title: :asc) items.reorder(title: :asc)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def with_title(items) def with_title(items)
return items if title.nil? return items if title.nil?
return items.none if title.blank? return items.none if title.blank?
items.where(title: title) items.where(title: title)
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_search(labels) def by_search(labels)
return labels unless search? return labels unless search?
...@@ -138,13 +146,14 @@ class LabelsFinder < UnionFinder ...@@ -138,13 +146,14 @@ class LabelsFinder < UnionFinder
@project @project
end end
# rubocop: disable CodeReuse/ActiveRecord
def projects def projects
return @projects if defined?(@projects) return @projects if defined?(@projects)
@projects = if skip_authorization @projects = if skip_authorization
Project.all Project.all
else 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 end
@projects = @projects.in_namespace(params[:group_id]) if group? @projects = @projects.in_namespace(params[:group_id]) if group?
...@@ -153,6 +162,7 @@ class LabelsFinder < UnionFinder ...@@ -153,6 +162,7 @@ class LabelsFinder < UnionFinder
@projects @projects
end end
# rubocop: enable CodeReuse/ActiveRecord
def authorized_to_read_labels?(label_parent) def authorized_to_read_labels?(label_parent)
return true if skip_authorization return true if skip_authorization
......
...@@ -7,12 +7,13 @@ class MembersFinder ...@@ -7,12 +7,13 @@ class MembersFinder
@group = project.group @group = project.group
end end
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false) def execute(include_descendants: false)
project_members = project.project_members project_members = project.project_members
project_members = project_members.non_invite unless can?(current_user, :admin_project, project) project_members = project_members.non_invite unless can?(current_user, :admin_project, project)
if group 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 group_members = group_members.non_invite
union = Gitlab::SQL::Union.new([project_members, group_members], remove_duplicates: false) union = Gitlab::SQL::Union.new([project_members, group_members], remove_duplicates: false)
...@@ -24,6 +25,7 @@ class MembersFinder ...@@ -24,6 +25,7 @@ class MembersFinder
project_members project_members
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def can?(*args) def can?(*args)
Ability.allowed?(*args) Ability.allowed?(*args)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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