diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-27 17:31:01 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-09-11 17:32:00 +0200 |
commit | 2039c8280db1646845c33d6c5a74e5f23ca6f4de (patch) | |
tree | e2b3cd3012d9711cda7c6afb962ae4228d59521a /app/controllers | |
parent | 91c40973dc620430b173ea2df968587d2a708dff (diff) | |
download | gitlab-ce-2039c8280db1646845c33d6c5a74e5f23ca6f4de.tar.gz |
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
Diffstat (limited to 'app/controllers')
82 files changed, 224 insertions, 0 deletions
diff --git a/app/controllers/abuse_reports_controller.rb b/app/controllers/abuse_reports_controller.rb index ed13ead63f9..51547ed7eaf 100644 --- a/app/controllers/abuse_reports_controller.rb +++ b/app/controllers/abuse_reports_controller.rb @@ -30,6 +30,7 @@ class AbuseReportsController < ApplicationController )) end + # rubocop: disable CodeReuse/ActiveRecord def set_user @user = User.find_by(id: params[:user_id]) @@ -39,4 +40,5 @@ class AbuseReportsController < ApplicationController redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked." end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/abuse_reports_controller.rb b/app/controllers/admin/abuse_reports_controller.rb index dc9a6df5f75..68a49f0749f 100644 --- a/app/controllers/admin/abuse_reports_controller.rb +++ b/app/controllers/admin/abuse_reports_controller.rb @@ -1,8 +1,10 @@ class Admin::AbuseReportsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @abuse_reports = AbuseReport.order(id: :desc).page(params[:page]) @abuse_reports.includes(:reporter, :user) end + # rubocop: enable CodeReuse/ActiveRecord def destroy abuse_report = AbuseReport.find(params[:id]) diff --git a/app/controllers/admin/applications_controller.rb b/app/controllers/admin/applications_controller.rb index 5be23c76a95..daa21d1be93 100644 --- a/app/controllers/admin/applications_controller.rb +++ b/app/controllers/admin/applications_controller.rb @@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController before_action :set_application, only: [:show, :edit, :update, :destroy] before_action :load_scopes, only: [:new, :create, :edit, :update] + # rubocop: disable CodeReuse/ActiveRecord def index @applications = Doorkeeper::Application.where("owner_id IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord def show end @@ -45,9 +47,11 @@ class Admin::ApplicationsController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def set_application @application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord # Only allow a trusted parameter "white list" through. def application_params diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb index a9109a1d4d0..b2fbbfc3e64 100644 --- a/app/controllers/admin/broadcast_messages_controller.rb +++ b/app/controllers/admin/broadcast_messages_controller.rb @@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController before_action :finder, only: [:edit, :update, :destroy] + # rubocop: disable CodeReuse/ActiveRecord def index @broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page]) @broadcast_message = BroadcastMessage.new end + # rubocop: enable CodeReuse/ActiveRecord def edit end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 737942f3eb2..5dc3e6c2990 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -4,10 +4,12 @@ class Admin::DashboardController < Admin::ApplicationController COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest, Note, Snippet, Key, Milestone].freeze + # rubocop: disable CodeReuse/ActiveRecord def index @counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS) @projects = Project.order_id_desc.without_deleted.with_route.limit(10) @users = User.order_id_desc.limit(10) @groups = Group.order_id_desc.with_route.limit(10) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index d7a5b745d3f..2a47f01c6ad 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -10,6 +10,7 @@ class Admin::GroupsController < Admin::ApplicationController @groups = @groups.page(params[:page]) end + # rubocop: disable CodeReuse/ActiveRecord def show @group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id]) @members = present_members( @@ -18,6 +19,7 @@ class Admin::GroupsController < Admin::ApplicationController AccessRequestsFinder.new(@group).execute(current_user)) @projects = @group.projects.with_statistics.page(params[:projects_page]) end + # rubocop: enable CodeReuse/ActiveRecord def new @group = Group.new diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index ceb45865804..57ad7389a23 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -44,9 +44,11 @@ class Admin::IdentitiesController < Admin::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def identity @identity ||= user.identities.find(params[:id]) diff --git a/app/controllers/admin/impersonation_tokens_controller.rb b/app/controllers/admin/impersonation_tokens_controller.rb index a7b562b1d8e..9ebba88ef16 100644 --- a/app/controllers/admin/impersonation_tokens_controller.rb +++ b/app/controllers/admin/impersonation_tokens_controller.rb @@ -30,9 +30,11 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def finder(options = {}) PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options)) @@ -42,6 +44,7 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: []) end + # rubocop: disable CodeReuse/ActiveRecord def set_index_vars @scopes = Gitlab::Auth.available_scopes(current_user) @@ -49,4 +52,5 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController @inactive_impersonation_tokens = finder(state: 'inactive').execute @active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/jobs_controller.rb b/app/controllers/admin/jobs_controller.rb index e355d5fdea7..788693c62c4 100644 --- a/app/controllers/admin/jobs_controller.rb +++ b/app/controllers/admin/jobs_controller.rb @@ -1,4 +1,5 @@ class Admin::JobsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_builds = Ci::Build @@ -16,6 +17,7 @@ class Admin::JobsController < Admin::ApplicationController end @builds = @builds.page(params[:page]).per(30) end + # rubocop: enable CodeReuse/ActiveRecord def cancel_all Ci::Build.running_or_pending.each(&:cancel) diff --git a/app/controllers/admin/keys_controller.rb b/app/controllers/admin/keys_controller.rb index 0b76193a90e..0400a3b2f3b 100644 --- a/app/controllers/admin/keys_controller.rb +++ b/app/controllers/admin/keys_controller.rb @@ -24,9 +24,11 @@ class Admin::KeysController < Admin::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:user_id]) end + # rubocop: enable CodeReuse/ActiveRecord def key_params params.require(:user_id, :id) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 3afe66c3566..5cb08c9787b 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -19,6 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def show if @group @group_members = present_members( @@ -30,7 +31,9 @@ class Admin::ProjectsController < Admin::ApplicationController @requesters = present_members( AccessRequestsFinder.new(@project).execute(current_user)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def transfer namespace = Namespace.find_by(id: params[:new_namespace_id]) ::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace) @@ -38,6 +41,7 @@ class Admin::ProjectsController < Admin::ApplicationController @project.reload redirect_to admin_project_path(@project) end + # rubocop: enable CodeReuse/ActiveRecord def repository_check RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id) diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index 6c76c55a9d4..090149fc1e2 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -1,6 +1,7 @@ class Admin::RunnersController < Admin::ApplicationController before_action :runner, except: :index + # rubocop: disable CodeReuse/ActiveRecord def index sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc } @runners = Ci::Runner.order(sort) @@ -8,6 +9,7 @@ class Admin::RunnersController < Admin::ApplicationController @runners = @runners.page(params[:page]).per(30) @active_runners_cnt = Ci::Runner.online.count end + # rubocop: enable CodeReuse/ActiveRecord def show assign_builds_and_projects @@ -57,6 +59,7 @@ class Admin::RunnersController < Admin::ApplicationController params.require(:runner).permit(Ci::Runner::FORM_EDITABLE) end + # rubocop: disable CodeReuse/ActiveRecord def assign_builds_and_projects @builds = runner.builds.order('id DESC').first(30) @projects = @@ -69,4 +72,5 @@ class Admin::RunnersController < Admin::ApplicationController @projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any? @projects = @projects.page(params[:page]).per(30) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/admin/services_controller.rb b/app/controllers/admin/services_controller.rb index 91a36af34f3..c455930c044 100644 --- a/app/controllers/admin/services_controller.rb +++ b/app/controllers/admin/services_controller.rb @@ -30,16 +30,20 @@ class Admin::ServicesController < Admin::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def services_templates Service.available_services_names.map do |service_name| service_template = "#{service_name}_service".camelize.constantize service_template.where(template: true).first_or_create end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def service @service ||= Service.where(id: params[:id], template: true).first end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430') diff --git a/app/controllers/admin/spam_logs_controller.rb b/app/controllers/admin/spam_logs_controller.rb index d52d67a67a5..8df35d25303 100644 --- a/app/controllers/admin/spam_logs_controller.rb +++ b/app/controllers/admin/spam_logs_controller.rb @@ -1,7 +1,9 @@ class Admin::SpamLogsController < Admin::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @spam_logs = SpamLog.order(id: :desc).page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def destroy spam_log = SpamLog.find(params[:id]) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index a51a8c3ed4a..85bdc85c55b 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -174,9 +174,11 @@ class Admin::UsersController < Admin::ApplicationController user == current_user end + # rubocop: disable CodeReuse/ActiveRecord def user @user ||= User.find_by!(username: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def redirect_back_or_admin_user(options = {}) redirect_back_or_default(default: default_route, options: options) diff --git a/app/controllers/boards/issues_controller.rb b/app/controllers/boards/issues_controller.rb index 7dd19f87ef5..071906f1e91 100644 --- a/app/controllers/boards/issues_controller.rb +++ b/app/controllers/boards/issues_controller.rb @@ -11,6 +11,7 @@ module Boards before_action :authorize_update_issue, only: [:update] skip_before_action :authenticate_user!, only: [:index] + # rubocop: disable CodeReuse/ActiveRecord def index list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params) issues = list_service.execute @@ -25,6 +26,7 @@ module Boards render_issues(issues, list_service.metadata) end + # rubocop: enable CodeReuse/ActiveRecord def create service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params) diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index dfa1da7872c..961f121548b 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -88,6 +88,7 @@ module AuthenticatesWithTwoFactor # Setup in preparation of communication with a U2F (universal 2nd factor) device # Actual communication is performed using a Javascript API + # rubocop: disable CodeReuse/ActiveRecord def setup_u2f_authentication(user) key_handles = user.u2f_registrations.pluck(:key_handle) u2f = U2F::U2F.new(u2f_app_id) @@ -99,4 +100,5 @@ module AuthenticatesWithTwoFactor sign_requests: sign_requests }) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index b26a76d2b62..709c8aaf337 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -99,6 +99,7 @@ module CreatesCommit end # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def merge_request_exists? strong_memoize(:merge_request) do MergeRequestsFinder.new(current_user, project_id: @project.id) @@ -110,6 +111,7 @@ module CreatesCommit target_branch: @start_branch) end end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables def different_project? diff --git a/app/controllers/concerns/enforces_two_factor_authentication.rb b/app/controllers/concerns/enforces_two_factor_authentication.rb index 997af4ab9e9..69e5cbed343 100644 --- a/app/controllers/concerns/enforces_two_factor_authentication.rb +++ b/app/controllers/concerns/enforces_two_factor_authentication.rb @@ -24,6 +24,7 @@ module EnforcesTwoFactorAuthentication current_user.try(:require_two_factor_authentication_from_group?) end + # rubocop: disable CodeReuse/ActiveRecord def two_factor_authentication_reason(global: -> {}, group: -> {}) if two_factor_authentication_required? if Gitlab::CurrentSettings.require_two_factor_authentication? @@ -34,6 +35,7 @@ module EnforcesTwoFactorAuthentication end end end + # rubocop: enable CodeReuse/ActiveRecord def two_factor_grace_period periods = [Gitlab::CurrentSettings.two_factor_grace_period] diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb index 6ec6897e707..c363cad0ffa 100644 --- a/app/controllers/concerns/group_tree.rb +++ b/app/controllers/concerns/group_tree.rb @@ -1,5 +1,6 @@ module GroupTree # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def render_group_tree(groups) groups = groups.sort_by_attribute(@sort = params[:sort]) @@ -23,7 +24,9 @@ module GroupTree end # rubocop:enable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def filtered_groups_with_ancestors(groups) filtered_groups = groups.search(params[:filter]).page(params[:page]) @@ -40,4 +43,5 @@ module GroupTree filtered_groups end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/issuable_actions.rb b/app/controllers/concerns/issuable_actions.rb index 7b6e5bcb5f1..e723107bd7f 100644 --- a/app/controllers/concerns/issuable_actions.rb +++ b/app/controllers/concerns/issuable_actions.rb @@ -89,6 +89,7 @@ module IssuableActions render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" } end + # rubocop: disable CodeReuse/ActiveRecord def discussions notes = issuable.discussion_notes .inc_relations_for_view @@ -103,6 +104,7 @@ module IssuableActions render json: discussion_serializer.represent(discussions, context: self) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index a2c96f5d635..d29154d5c60 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -48,9 +48,11 @@ module IssuableCollections false end + # rubocop: disable CodeReuse/ActiveRecord def issuables_collection finder.execute.preload(preload_for_collection) end + # rubocop: enable CodeReuse/ActiveRecord def redirect_out_of_range(total_pages) return false if total_pages.nil? || total_pages.zero? @@ -81,6 +83,7 @@ module IssuableCollections end # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def filter_params set_sort_order_from_cookie set_default_state @@ -101,6 +104,7 @@ module IssuableCollections @filter_params.permit(finder_type.valid_params) end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables def set_default_state diff --git a/app/controllers/concerns/issues_calendar.rb b/app/controllers/concerns/issues_calendar.rb index 671a204621d..76e1d1ff4e8 100644 --- a/app/controllers/concerns/issues_calendar.rb +++ b/app/controllers/concerns/issues_calendar.rb @@ -2,6 +2,7 @@ module IssuesCalendar extend ActiveSupport::Concern # rubocop:disable Gitlab/ModuleWithInstanceVariables + # rubocop: disable CodeReuse/ActiveRecord def render_issues_calendar(issuables) @issues = issuables .non_archived @@ -20,5 +21,6 @@ module IssuesCalendar end end end + # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables end diff --git a/app/controllers/concerns/members_presentation.rb b/app/controllers/concerns/members_presentation.rb index 215e0bdf3cb..e146e7574aa 100644 --- a/app/controllers/concerns/members_presentation.rb +++ b/app/controllers/concerns/members_presentation.rb @@ -10,10 +10,12 @@ module MembersPresentation ).fabricate! end + # rubocop: disable CodeReuse/ActiveRecord def preload_associations(members) ActiveRecord::Associations::Preloader.new.preload(members, :user) ActiveRecord::Associations::Preloader.new.preload(members, :source) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status) ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 409e6d4c4d2..94a352c0bcc 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -57,6 +57,7 @@ module MembershipActions redirect_to members_page_url end + # rubocop: disable CodeReuse/ActiveRecord def leave member = membershipable.members_and_requesters.find_by!(user_id: current_user.id) Members::DestroyService.new(current_user).execute(member) @@ -77,6 +78,7 @@ module MembershipActions format.json { render json: { notice: notice } } end end + # rubocop: enable CodeReuse/ActiveRecord def resend_invite member = membershipable.members.find(params[:id]) diff --git a/app/controllers/concerns/renders_member_access.rb b/app/controllers/concerns/renders_member_access.rb index d640378c24d..c5b77dacb26 100644 --- a/app/controllers/concerns/renders_member_access.rb +++ b/app/controllers/concerns/renders_member_access.rb @@ -13,6 +13,7 @@ module RendersMemberAccess private + # rubocop: disable CodeReuse/ActiveRecord def preload_max_member_access_for_collection(klass, collection) return if !current_user || collection.blank? @@ -20,4 +21,5 @@ module RendersMemberAccess current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index cf04023080a..c5f23e33424 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -20,9 +20,11 @@ module RendersNotes project.team.max_member_access_for_user_ids(user_ids) end + # rubocop: disable CodeReuse/ActiveRecord def preload_noteable_for_regular_notes(notes) ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) end + # rubocop: enable CodeReuse/ActiveRecord def preload_first_time_contribution_for_authors(noteable, notes) return unless noteable.is_a?(Issuable) && noteable.first_contribution? @@ -30,7 +32,9 @@ module RendersNotes notes.each {|n| n.specialize_for_first_contribution!(noteable)} end + # rubocop: disable CodeReuse/ActiveRecord def preload_author_status(notes) ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status }) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index bb8c245a5b7..56772df21d7 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -89,6 +89,7 @@ module UploadsActions end end + # rubocop: disable CodeReuse/ActiveRecord def build_uploader_from_upload return unless uploader = build_uploader @@ -96,6 +97,7 @@ module UploadsActions upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths) upload&.build_uploader end + # rubocop: enable CodeReuse/ActiveRecord def build_uploader_from_params return unless uploader = build_uploader diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb index ccfcbbdc776..e8f796f17ca 100644 --- a/app/controllers/dashboard/projects_controller.rb +++ b/app/controllers/dashboard/projects_controller.rb @@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def starred @projects = load_projects(params.merge(starred: true)) .includes(:forked_from_project, :tags) @@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController @sort = params[:sort] end + # rubocop: disable CodeReuse/ActiveRecord def load_projects(finder_params) projects = ProjectsFinder .new(params: finder_params, current_user: current_user) @@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController prepare_projects_for_rendering(projects) end + # rubocop: enable CodeReuse/ActiveRecord def load_events projects = load_projects(params.merge(non_public: true)) diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index bd7111e28bc..231a23427f7 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id) end + # rubocop: disable CodeReuse/ActiveRecord def redirect_out_of_range(todos) total_pages = if todo_params.except(:sort, :page).empty? @@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController out_of_range end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index c7273606a85..03a2ee07fea 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def starred @projects = load_projects.reorder('star_count DESC') @@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def load_projects projects = ProjectsFinder.new(current_user: current_user, params: params) .execute @@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController prepare_projects_for_rendering(projects) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1f48c3417d0..8b46eedae79 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -97,6 +97,7 @@ class GroupsController < Groups::ApplicationController redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion." end + # rubocop: disable CodeReuse/ActiveRecord def transfer parent_group = Group.find_by(id: params[:new_parent_group_id]) service = ::Groups::TransferService.new(@group, current_user) @@ -109,9 +110,11 @@ class GroupsController < Groups::ApplicationController render :edit end end + # rubocop: enable CodeReuse/ActiveRecord protected + # rubocop: disable CodeReuse/ActiveRecord def authorize_create_group! allowed = if params[:parent_id].present? parent = Group.find_by(id: params[:parent_id]) @@ -122,6 +125,7 @@ class GroupsController < Groups::ApplicationController render_404 unless allowed end + # rubocop: enable CodeReuse/ActiveRecord def determine_layout if [:new, :create].include?(action_name.to_sym) @@ -156,6 +160,7 @@ class GroupsController < Groups::ApplicationController ] end + # rubocop: disable CodeReuse/ActiveRecord def load_events params[:sort] ||= 'latest_activity_desc' @@ -175,6 +180,7 @@ class GroupsController < Groups::ApplicationController .new(current_user) .execute(@events, atom_request: request.format.atom?) end + # rubocop: enable CodeReuse/ActiveRecord def user_actions if current_user diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 5766c6924cd..14b8c6e4137 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -1,16 +1,20 @@ class Import::BaseController < ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def find_already_added_projects(import_type) current_user.created_projects.where(import_type: import_type).includes(:import_state) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find_jobs(import_type) current_user.created_projects .includes(:import_state) .where(import_type: import_type) .to_json(only: [:id], methods: [:import_status]) end + # rubocop: enable CodeReuse/ActiveRecord def find_or_create_namespace(names, owner) names = params[:target_namespace].presence || names diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index fa31933e778..f885e04b198 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController redirect_to status_import_bitbucket_url end + # rubocop: disable CodeReuse/ActiveRecord def status bitbucket_client = Bitbucket::Client.new(credentials) repos = bitbucket_client.repos @@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController @repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('bitbucket') diff --git a/app/controllers/import/bitbucket_server_controller.rb b/app/controllers/import/bitbucket_server_controller.rb index 798daeca6c9..fdd1078cdf7 100644 --- a/app/controllers/import/bitbucket_server_controller.rb +++ b/app/controllers/import/bitbucket_server_controller.rb @@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController redirect_to status_import_bitbucket_server_path end + # rubocop: disable CodeReuse/ActiveRecord def status repos = bitbucket_client.repos @@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController clear_session_data redirect_to new_import_bitbucket_server_path end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('bitbucket_server') diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb index 2d665e05ac3..df96d181153 100644 --- a/app/controllers/import/fogbugz_controller.rb +++ b/app/controllers/import/fogbugz_controller.rb @@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController redirect_to status_import_fogbugz_path end + # rubocop: disable CodeReuse/ActiveRecord def status unless client.valid? return redirect_to new_import_fogbugz_path @@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('fogbugz') diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index c9870332c0f..f8b43b4fde5 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -22,6 +22,7 @@ class Import::GithubController < Import::BaseController redirect_to status_import_url end + # rubocop: disable CodeReuse/ActiveRecord def status @repos = client.repos @already_added_projects = find_already_added_projects(provider) @@ -29,6 +30,7 @@ class Import::GithubController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.full_name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs(provider) @@ -104,9 +106,11 @@ class Import::GithubController < Import::BaseController :github end + # rubocop: disable CodeReuse/ActiveRecord def logged_in_with_provider? current_user.identities.exists?(provider: provider) end + # rubocop: enable CodeReuse/ActiveRecord def provider_auth if session[access_token_key].blank? diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb index 53f70446d95..bdc402b0a77 100644 --- a/app/controllers/import/gitlab_controller.rb +++ b/app/controllers/import/gitlab_controller.rb @@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController redirect_to status_import_gitlab_url end + # rubocop: disable CodeReuse/ActiveRecord def status @repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS) @@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController @repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('gitlab') diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb index 3bce27e810a..e9387d0ad14 100644 --- a/app/controllers/import/google_code_controller.rb +++ b/app/controllers/import/google_code_controller.rb @@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController redirect_to status_import_google_code_path end + # rubocop: disable CodeReuse/ActiveRecord def status unless client.valid? return redirect_to new_import_google_code_path @@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController @repos.reject! { |repo| already_added_projects_names.include? repo.name } end + # rubocop: enable CodeReuse/ActiveRecord def jobs render json: find_jobs('google_code') diff --git a/app/controllers/import/manifest_controller.rb b/app/controllers/import/manifest_controller.rb index e5a719fa0df..4ed9dca2475 100644 --- a/app/controllers/import/manifest_controller.rb +++ b/app/controllers/import/manifest_controller.rb @@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController def new end + # rubocop: disable CodeReuse/ActiveRecord def status @already_added_projects = find_already_added_projects already_added_import_urls = @already_added_projects.pluck(:import_url) @@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController already_added_import_urls.include?(repository[:url]) end end + # rubocop: enable CodeReuse/ActiveRecord def upload group = Group.find(params[:group_id]) @@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController end end + # rubocop: disable CodeReuse/ActiveRecord def group @group ||= Group.find_by(id: session[:manifest_import_group_id]) end + # rubocop: enable CodeReuse/ActiveRecord def repositories @repositories ||= session[:manifest_import_repositories] @@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController find_already_added_projects.to_json(only: [:id], methods: [:import_status]) end + # rubocop: disable CodeReuse/ActiveRecord def find_already_added_projects group.all_projects .where(import_type: 'manifest') .where(creator_id: current_user) .includes(:import_state) end + # rubocop: enable CodeReuse/ActiveRecord def verify_import_enabled render_404 unless manifest_import_enabled? diff --git a/app/controllers/instance_statistics/conversational_development_index_controller.rb b/app/controllers/instance_statistics/conversational_development_index_controller.rb index d6d2191849f..306c16d559c 100644 --- a/app/controllers/instance_statistics/conversational_development_index_controller.rb +++ b/app/controllers/instance_statistics/conversational_development_index_controller.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def index @metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 331583c49e6..a1bcf206b65 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -5,6 +5,7 @@ class PasswordsController < Devise::PasswordsController before_action :check_password_authentication_available, only: [:create] before_action :throttle_reset, only: [:create] + # rubocop: disable CodeReuse/ActiveRecord def edit super reset_password_token = Devise.token_generator.digest( @@ -24,6 +25,7 @@ class PasswordsController < Devise::PasswordsController end end end + # rubocop: enable CodeReuse/ActiveRecord def update super do |resource| diff --git a/app/controllers/profiles/accounts_controller.rb b/app/controllers/profiles/accounts_controller.rb index 7d1aa8d1ce0..fd9cb9fca3e 100644 --- a/app/controllers/profiles/accounts_controller.rb +++ b/app/controllers/profiles/accounts_controller.rb @@ -5,6 +5,7 @@ class Profiles::AccountsController < Profiles::ApplicationController @user = current_user end + # rubocop: disable CodeReuse/ActiveRecord def unlink provider = params[:provider] identity = current_user.identities.find_by(provider: provider) @@ -19,4 +20,5 @@ class Profiles::AccountsController < Profiles::ApplicationController redirect_to profile_account_path end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/profiles/notifications_controller.rb b/app/controllers/profiles/notifications_controller.rb index 8a38ba65d4c..00bd2040b9a 100644 --- a/app/controllers/profiles/notifications_controller.rb +++ b/app/controllers/profiles/notifications_controller.rb @@ -1,10 +1,12 @@ class Profiles::NotificationsController < Profiles::ApplicationController + # rubocop: disable CodeReuse/ActiveRecord def show @user = current_user @group_notifications = current_user.notification_settings.for_groups.order(:id) @project_notifications = current_user.notification_settings.for_projects.order(:id) @global_notification_setting = current_user.global_notification_setting end + # rubocop: enable CodeReuse/ActiveRecord def update result = Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute diff --git a/app/controllers/profiles/personal_access_tokens_controller.rb b/app/controllers/profiles/personal_access_tokens_controller.rb index 346eab4ba19..b357741e3fb 100644 --- a/app/controllers/profiles/personal_access_tokens_controller.rb +++ b/app/controllers/profiles/personal_access_tokens_controller.rb @@ -38,6 +38,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController params.require(:personal_access_token).permit(:name, :expires_at, scopes: []) end + # rubocop: disable CodeReuse/ActiveRecord def set_index_vars @scopes = Gitlab::Auth.available_scopes(current_user) @@ -46,4 +47,5 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController @new_personal_access_token = PersonalAccessToken.redis_getdel(current_user.id) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 5671663f81e..94e6efca487 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -44,11 +44,13 @@ class ProfilesController < Profiles::ApplicationController redirect_to profile_personal_access_tokens_path end + # rubocop: disable CodeReuse/ActiveRecord def audit_log @events = AuditEvent.where(entity_type: "User", entity_id: current_user.id) .order("created_at DESC") .page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def update_username result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index 6484a713f8e..3e8ffa485dd 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -82,16 +82,20 @@ class Projects::ArtifactsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def build_from_id project.builds.find_by(id: params[:job_id]) if params[:job_id] end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def build_from_ref return unless @ref_name builds = project.latest_successful_builds_for(@ref_name) builds.find_by(name: params[:job]) end + # rubocop: enable CodeReuse/ActiveRecord def artifacts_file @artifacts_file ||= build.artifacts_file diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 56dafa31332..bfe4e7f934f 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -177,6 +177,7 @@ class Projects::BlobController < Projects::ApplicationController render_404 end + # rubocop: disable CodeReuse/ActiveRecord def after_edit_path 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 @@ -186,6 +187,7 @@ class Projects::BlobController < Projects::ApplicationController project_blob_path(@project, File.join(@branch_name, @path)) end end + # rubocop: enable CodeReuse/ActiveRecord def editor_variables @branch_name = params[:branch_name] diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index d1dc9fe9600..d14795e787b 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -48,6 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController @branches = @repository.recent_branches end + # rubocop: disable CodeReuse/ActiveRecord def create branch_name = sanitize(strip_tags(params[:branch_name])) branch_name = Addressable::URI.unescape(branch_name) @@ -88,6 +89,7 @@ class Projects::BranchesController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def destroy @branch_name = Addressable::URI.unescape(params[:id]) diff --git a/app/controllers/projects/build_artifacts_controller.rb b/app/controllers/projects/build_artifacts_controller.rb index b45e5d7ff43..9e99a84fac7 100644 --- a/app/controllers/projects/build_artifacts_controller.rb +++ b/app/controllers/projects/build_artifacts_controller.rb @@ -42,14 +42,18 @@ class Projects::BuildArtifactsController < Projects::ApplicationController @job ||= job_from_id || job_from_ref end + # rubocop: disable CodeReuse/ActiveRecord def job_from_id project.builds.find_by(id: params[:build_id]) if params[:build_id] end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def job_from_ref return unless @ref_name jobs = project.latest_successful_builds_for(@ref_name) jobs.find_by(name: params[:job]) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/projects/clusters/applications_controller.rb index a5c82caa897..8c9df51981a 100644 --- a/app/controllers/projects/clusters/applications_controller.rb +++ b/app/controllers/projects/clusters/applications_controller.rb @@ -4,6 +4,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll before_action :authorize_read_cluster! before_action :authorize_create_cluster!, only: [:create] + # rubocop: disable CodeReuse/ActiveRecord def create application = @application_class.find_or_initialize_by(cluster: @cluster) @@ -23,6 +24,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll rescue StandardError head :bad_request end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 53637780a07..81f375875b2 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -38,6 +38,7 @@ class Projects::CommitController < Projects::ApplicationController render_diff_for_path(@commit.diffs(diff_options)) end + # rubocop: disable CodeReuse/ActiveRecord def pipelines @pipelines = @commit.pipelines.order(id: :desc) @pipelines = @pipelines.where(ref: params[:ref]) if params[:ref] @@ -58,6 +59,7 @@ class Projects::CommitController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def merge_requests @merge_requests = @commit.merge_requests.map do |mr| @@ -144,6 +146,7 @@ class Projects::CommitController < Projects::ApplicationController @environment = EnvironmentsFinder.new(@project, current_user, commit: @commit).execute.last end + # rubocop: disable CodeReuse/ActiveRecord def define_note_vars @noteable = @commit @note = @project.build_commit_note(commit) @@ -176,6 +179,7 @@ class Projects::CommitController < Projects::ApplicationController @notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes) @notes = prepare_notes_for_rendering(@notes, @commit) end + # rubocop: enable CodeReuse/ActiveRecord def assign_change_commit_vars @start_branch = params[:start_branch] diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 5546bef850b..cd9c9aa30f1 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -15,6 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController redirect_to project_commits_path(@project, @project.default_branch) end + # rubocop: disable CodeReuse/ActiveRecord def show @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) @@ -32,6 +33,7 @@ class Projects::CommitsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def signatures respond_to do |format| diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index a1e12821caf..cca77903250 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -96,8 +96,10 @@ class Projects::CompareController < Projects::ApplicationController @diff_notes_disabled = compare.present? end + # rubocop: disable CodeReuse/ActiveRecord def merge_request @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) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/deploy_keys_controller.rb b/app/controllers/projects/deploy_keys_controller.rb index 28fea322334..2555139cd2c 100644 --- a/app/controllers/projects/deploy_keys_controller.rb +++ b/app/controllers/projects/deploy_keys_controller.rb @@ -52,6 +52,7 @@ class Projects::DeployKeysController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def disable deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id]) return render_404 unless deploy_key_project @@ -63,6 +64,7 @@ class Projects::DeployKeysController < Projects::ApplicationController format.json { head :ok } end end + # rubocop: enable CodeReuse/ActiveRecord protected diff --git a/app/controllers/projects/deployments_controller.rb b/app/controllers/projects/deployments_controller.rb index b68cdc39cb8..5a2da7274d1 100644 --- a/app/controllers/projects/deployments_controller.rb +++ b/app/controllers/projects/deployments_controller.rb @@ -2,6 +2,7 @@ class Projects::DeploymentsController < Projects::ApplicationController before_action :authorize_read_environment! before_action :authorize_read_deployment! + # rubocop: disable CodeReuse/ActiveRecord def index deployments = environment.deployments.reorder(created_at: :desc) deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time @@ -9,6 +10,7 @@ class Projects::DeploymentsController < Projects::ApplicationController render json: { deployments: DeploymentSerializer.new(project: project) .represent_concise(deployments) } end + # rubocop: enable CodeReuse/ActiveRecord def metrics return render_404 unless deployment.has_metrics? @@ -41,9 +43,11 @@ class Projects::DeploymentsController < Projects::ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def deployment @deployment ||= environment.deployments.find_by(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def environment @environment ||= project.environments.find(params[:environment_id]) diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb index 78b9d53a780..efdddb24290 100644 --- a/app/controllers/projects/discussions_controller.rb +++ b/app/controllers/projects/discussions_controller.rb @@ -50,9 +50,11 @@ class Projects::DiscussionsController < Projects::ApplicationController } end + # rubocop: disable CodeReuse/ActiveRecord def merge_request @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id]) end + # rubocop: enable CodeReuse/ActiveRecord def discussion @discussion ||= @merge_request.find_discussion(params[:id]) || render_404 diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 68353e6a210..be22950286e 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -31,6 +31,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def folder folder_environments = project.environments.where(environment_type: params[:id]) @environments = folder_environments.with_state(params[:scope] || :available) @@ -51,10 +52,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def show @deployments = environment.deployments.order(id: :desc).page(params[:page]) end + # rubocop: enable CodeReuse/ActiveRecord def new @environment = project.environments.new diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb index f43bba18d81..b709edc8f10 100644 --- a/app/controllers/projects/forks_controller.rb +++ b/app/controllers/projects/forks_controller.rb @@ -7,6 +7,7 @@ class Projects::ForksController < Projects::ApplicationController before_action :authorize_download_code! before_action :authenticate_user!, only: [:new, :create] + # rubocop: disable CodeReuse/ActiveRecord def index base_query = project.forks.includes(:creator) @@ -27,12 +28,14 @@ class Projects::ForksController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def new @namespaces = current_user.manageable_namespaces @namespaces.delete(@project.namespace) end + # rubocop: disable CodeReuse/ActiveRecord def create namespace = Namespace.find(params[:namespace_key]) @@ -55,6 +58,7 @@ class Projects::ForksController < Projects::ApplicationController render :error end end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335') diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index c3ac8e107fb..632e498e4ba 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -161,6 +161,7 @@ class Projects::IssuesController < Projects::ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def issue return @issue if defined?(@issue) @@ -172,6 +173,7 @@ class Projects::IssuesController < Projects::ApplicationController @issue end + # rubocop: enable CodeReuse/ActiveRecord alias_method :subscribable_resource, :issue alias_method :issuable, :issue alias_method :awardable, :issue diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index e69faae754a..62b74e84c2c 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController layout 'project' + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_builds = project.builds.relevant @@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController ]) @builds = @builds.page(params[:page]).per(30).without_count end + # rubocop: enable CodeReuse/ActiveRecord def cancel_all return access_denied! unless can?(current_user, :update_build, project) @@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController redirect_to project_jobs_path(project) end + # rubocop: disable CodeReuse/ActiveRecord def show @pipeline = @build.pipeline @builds = @pipeline.builds @@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController end end end + # rubocop: enable CodeReuse/ActiveRecord def trace build.trace.read do |stream| diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index 8a2bce6e7b5..18dbd65637c 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def set_priorities Label.transaction do available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id) @@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController format.json { render json: { message: 'success' } } end end + # rubocop: enable CodeReuse/ActiveRecord def promote promote_service = Labels::PromoteService.new(@project, @current_user) diff --git a/app/controllers/projects/lfs_api_controller.rb b/app/controllers/projects/lfs_api_controller.rb index a01351ba292..6d6f88c1075 100644 --- a/app/controllers/projects/lfs_api_controller.rb +++ b/app/controllers/projects/lfs_api_controller.rb @@ -41,11 +41,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController params[:operation] == 'upload' end + # rubocop: disable CodeReuse/ActiveRecord def existing_oids @existing_oids ||= begin project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid) end end + # rubocop: enable CodeReuse/ActiveRecord def download_objects! objects.each do |object| diff --git a/app/controllers/projects/lfs_storage_controller.rb b/app/controllers/projects/lfs_storage_controller.rb index dd7e673ec75..930d9a05c50 100644 --- a/app/controllers/projects/lfs_storage_controller.rb +++ b/app/controllers/projects/lfs_storage_controller.rb @@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController params[:size].to_i end + # rubocop: disable CodeReuse/ActiveRecord def store_file!(oid, size) object = LfsObject.find_by(oid: oid, size: size) unless object&.file&.exists? @@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController link_to_project!(object) end + # rubocop: enable CodeReuse/ActiveRecord def create_file!(oid, size) uploaded_file = UploadedFile.from_params( @@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController LfsObject.create!(oid: oid, size: size, file: uploaded_file) end + # rubocop: disable CodeReuse/ActiveRecord def link_to_project!(object) if object && !object.projects.exists?(storage_project.id) object.lfs_objects_projects.create!(project: storage_project) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/merge_requests/application_controller.rb b/app/controllers/projects/merge_requests/application_controller.rb index fead81dd472..aa2008722ec 100644 --- a/app/controllers/projects/merge_requests/application_controller.rb +++ b/app/controllers/projects/merge_requests/application_controller.rb @@ -5,9 +5,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont private + # rubocop: disable CodeReuse/ActiveRecord def merge_request @issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def merge_request_params params.require(:merge_request).permit(merge_request_params_attributes) diff --git a/app/controllers/projects/merge_requests/creations_controller.rb b/app/controllers/projects/merge_requests/creations_controller.rb index 03d0290ac1d..2ccb3896857 100644 --- a/app/controllers/projects/merge_requests/creations_controller.rb +++ b/app/controllers/projects/merge_requests/creations_controller.rb @@ -109,6 +109,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap set_pipeline_variables end + # rubocop: disable CodeReuse/ActiveRecord def selected_target_project if @project.id.to_s == params[:target_project_id] || !@project.forked? @project @@ -119,6 +120,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap @project.forked_from_project end end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384') diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 34de554212f..666e65b6c5e 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @diffs = @compare.diffs(diff_options) end + # rubocop: disable CodeReuse/ActiveRecord def commit return nil unless commit_id = params[:commit_id].presence return nil unless @merge_request.all_commits.exists?(sha: commit_id) @commit ||= @project.commit(commit_id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def find_merge_request_diff_compare @merge_request_diff = if diff_id = params[:diff_id].presence @@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @merge_request_diff end end + # rubocop: enable CodeReuse/ActiveRecord def additional_attributes { diff --git a/app/controllers/projects/milestones_controller.rb b/app/controllers/projects/milestones_controller.rb index b9b3dcd5a85..e2c05171cd6 100644 --- a/app/controllers/projects/milestones_controller.rb +++ b/app/controllers/projects/milestones_controller.rb @@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def milestone @milestone ||= @project.milestones.find_by!(iid: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord def authorize_admin_milestone! return render_404 unless can?(current_user, :admin_milestone, @project) diff --git a/app/controllers/projects/pages_controller.rb b/app/controllers/projects/pages_controller.rb index ff49911d892..e1eba4f8327 100644 --- a/app/controllers/projects/pages_controller.rb +++ b/app/controllers/projects/pages_controller.rb @@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController before_action :authorize_read_pages!, only: [:show] before_action :authorize_update_pages!, except: [:show] + # rubocop: disable CodeReuse/ActiveRecord def show @domains = @project.pages_domains.order(:domain) end + # rubocop: enable CodeReuse/ActiveRecord def destroy project.remove_pages diff --git a/app/controllers/projects/pages_domains_controller.rb b/app/controllers/projects/pages_domains_controller.rb index 4856be61e88..c29b3c953a6 100644 --- a/app/controllers/projects/pages_domains_controller.rb +++ b/app/controllers/projects/pages_domains_controller.rb @@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController params.require(:pages_domain).permit(:key, :certificate) end + # rubocop: disable CodeReuse/ActiveRecord def domain @domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb index aeda7b3edf5..d8adeffd0b2 100644 --- a/app/controllers/projects/pipeline_schedules_controller.rb +++ b/app/controllers/projects/pipeline_schedules_controller.rb @@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play] before_action :authorize_admin_pipeline_schedule!, only: [:destroy] + # rubocop: disable CodeReuse/ActiveRecord def index @scope = params[:scope] @all_schedules = PipelineSchedulesFinder.new(@project).execute @schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope]) .includes(:last_pipeline) end + # rubocop: enable CodeReuse/ActiveRecord def new @schedule = project.pipeline_schedules.new diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index b5db646bf57..2cc721dfeec 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -159,6 +159,7 @@ class Projects::PipelinesController < Projects::ApplicationController params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value]) end + # rubocop: disable CodeReuse/ActiveRecord def pipeline @pipeline ||= project .pipelines @@ -166,6 +167,7 @@ class Projects::PipelinesController < Projects::ApplicationController .find_by!(id: params[:id]) .present(current_user: current_user) end + # rubocop: enable CodeReuse/ActiveRecord def whitelist_query_limiting # Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343 diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index cfa5e72af64..08d5e377941 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController # Authorize before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access] + # rubocop: disable CodeReuse/ActiveRecord def index @sort = params[:sort].presence || sort_value_name @group_links = @project.project_group_links @@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController @requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user)) @project_member = @project.project_members.new end + # rubocop: enable CodeReuse/ActiveRecord def import @projects = current_user.authorized_projects.order_id_desc diff --git a/app/controllers/projects/releases_controller.rb b/app/controllers/projects/releases_controller.rb index 19e09b3af6f..caf400ecd92 100644 --- a/app/controllers/projects/releases_controller.rb +++ b/app/controllers/projects/releases_controller.rb @@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController @tag ||= @repository.find_tag(params[:tag_id]) end + # rubocop: disable CodeReuse/ActiveRecord def release @release ||= @project.releases.find_or_initialize_by(tag: @tag.name) end + # rubocop: enable CodeReuse/ActiveRecord def release_params params.require(:release).permit(:description) diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index 4697af4f26a..ccd481b4dbd 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -31,6 +31,7 @@ module Projects render 'show' end + # rubocop: disable CodeReuse/ActiveRecord def define_protected_refs @protected_branches = @project.protected_branches.order(:name).page(params[:page]) @protected_tags = @project.protected_tags.order(:name).page(params[:page]) @@ -42,6 +43,7 @@ module Projects load_gon_index end + # rubocop: enable CodeReuse/ActiveRecord def remote_mirror @remote_mirror = project.remote_mirrors.first_or_initialize diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index 7f2c3ca38ad..74bba97987f 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController before_action :authorize_push_code!, only: [:new, :create] before_action :authorize_admin_project!, only: [:destroy] + # rubocop: disable CodeReuse/ActiveRecord def index params[:sort] = params[:sort].presence || sort_value_recently_updated @@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController format.atom { render layout: 'xml.atom' } end end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def show @tag = @repository.find_tag(params[:id]) @@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController @release = @project.releases.find_or_initialize_by(tag: @tag.name) @commit = @repository.commit(@tag.dereferenced_target) end + # rubocop: enable CodeReuse/ActiveRecord def create result = Tags::CreateService.new(@project, current_user) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 98076791ab9..e2f9d501c4b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -25,12 +25,14 @@ class ProjectsController < Projects::ApplicationController redirect_to(current_user ? root_path : explore_root_path) end + # rubocop: disable CodeReuse/ActiveRecord def new namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id] return access_denied! if namespace && !can?(current_user, :create_projects, namespace) @project = Project.new(namespace_id: namespace&.id) end + # rubocop: enable CodeReuse/ActiveRecord def edit @badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id)) @@ -75,6 +77,7 @@ class ProjectsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def transfer return access_denied! unless can?(current_user, :change_namespace, @project) @@ -85,6 +88,7 @@ class ProjectsController < Projects::ApplicationController flash[:alert] = @project.errors[:new_namespace].first end end + # rubocop: enable CodeReuse/ActiveRecord def remove_fork return access_denied! unless can?(current_user, :remove_fork_project, @project) @@ -231,6 +235,7 @@ class ProjectsController < Projects::ApplicationController } end + # rubocop: disable CodeReuse/ActiveRecord def refs find_refs = params['find'] @@ -265,6 +270,7 @@ class ProjectsController < Projects::ApplicationController render json: options.to_json end + # rubocop: enable CodeReuse/ActiveRecord # Render project landing depending of which features are available # So if page is not availble in the list it renders the next page @@ -303,6 +309,7 @@ class ProjectsController < Projects::ApplicationController end end + # rubocop: disable CodeReuse/ActiveRecord def load_events projects = Project.where(id: @project.id) @@ -312,6 +319,7 @@ class ProjectsController < Projects::ApplicationController Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?) end + # rubocop: enable CodeReuse/ActiveRecord def project_params params.require(:project) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 983f888b8ec..a928758f325 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -31,6 +31,7 @@ class SearchController < ApplicationController check_single_commit_result end + # rubocop: disable CodeReuse/ActiveRecord def autocomplete term = params[:term] @@ -43,6 +44,7 @@ class SearchController < ApplicationController render json: search_autocomplete_opts(term).to_json end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ab8e2e35b98..9f2e66dea90 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -107,6 +107,7 @@ class SessionsController < Devise::SessionsController # Handle an "initial setup" state, where there's only one user, it's an admin, # and they require a password change. + # rubocop: disable CodeReuse/ActiveRecord def check_initial_setup return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one @@ -121,6 +122,7 @@ class SessionsController < Devise::SessionsController redirect_to edit_user_password_path(reset_password_token: @token), notice: "Please create a password for your new account." end + # rubocop: enable CodeReuse/ActiveRecord def user_params params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response) diff --git a/app/controllers/snippets/notes_controller.rb b/app/controllers/snippets/notes_controller.rb index 217da89a1fd..e992afc0026 100644 --- a/app/controllers/snippets/notes_controller.rb +++ b/app/controllers/snippets/notes_controller.rb @@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController nil end + # rubocop: disable CodeReuse/ActiveRecord def snippet PersonalSnippet.find_by(id: params[:snippet_id]) end + # rubocop: enable CodeReuse/ActiveRecord alias_method :noteable, :snippet def note_params diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index dcf18c1f751..19d865900e9 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -24,6 +24,7 @@ class SnippetsController < ApplicationController layout 'snippets' respond_to :html + # rubocop: disable CodeReuse/ActiveRecord def index if params[:username].present? @user = User.find_by(username: params[:username]) @@ -38,6 +39,7 @@ class SnippetsController < ApplicationController redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path) end end + # rubocop: enable CodeReuse/ActiveRecord def new @snippet = PersonalSnippet.new @@ -94,9 +96,11 @@ class SnippetsController < ApplicationController protected + # rubocop: disable CodeReuse/ActiveRecord def snippet @snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id]) end + # rubocop: enable CodeReuse/ActiveRecord alias_method :awardable, :snippet alias_method :spammable, :snippet diff --git a/app/controllers/user_callouts_controller.rb b/app/controllers/user_callouts_controller.rb index 18cde4a7b1a..b8d2deba93b 100644 --- a/app/controllers/user_callouts_controller.rb +++ b/app/controllers/user_callouts_controller.rb @@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController private + # rubocop: disable CodeReuse/ActiveRecord def ensure_callout current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name]) end + # rubocop: enable CodeReuse/ActiveRecord def feature_name params.require(:feature_name) |