Commit cd7b816e authored by Yorick Peterse's avatar Yorick Peterse

Allow EE offenses for the CodeReuse cops

This whitelists various EE specific offenses of the various CodeReuse
cops.
parent e652e2a7
......@@ -43,6 +43,7 @@ module KerberosSpnegoHelper
headers['Www-Authenticate'] = spnego_challenge if spnego_response_token
end
# rubocop: disable CodeReuse/ActiveRecord
def find_kerberos_user
krb_principal = spnego_credentials!(spnego_token)
return unless krb_principal
......@@ -50,6 +51,7 @@ module KerberosSpnegoHelper
identity = ::Identity.with_extern_uid(:kerberos, krb_principal).take
identity&.user
end
# rubocop: enable CodeReuse/ActiveRecord
# The Kerberos backend will translate spnego_token into a Kerberos
# principal and/or provide a value for @spnego_response_token.
......
......@@ -23,6 +23,7 @@ module Search
@projects ||= ProjectsFinder.new(current_user: current_user).execute
end
# rubocop: disable CodeReuse/ActiveRecord
def elastic_projects
@elastic_projects ||=
if current_user&.full_private_access?
......@@ -33,6 +34,7 @@ module Search
[]
end
end
# rubocop: enable CodeReuse/ActiveRecord
def elastic_global
true
......
......@@ -4,6 +4,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
helper EE::GeoHelper
# rubocop: disable CodeReuse/ActiveRecord
def index
@nodes = GeoNode.all.order(:id)
@node = GeoNode.new
......@@ -12,6 +13,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
flash_now(:alert, 'You need a different license to enable Geo replication')
end
end
# rubocop: enable CodeReuse/ActiveRecord
def create
@node = Geo::NodeCreateService.new(geo_node_params).execute
......
......@@ -39,7 +39,9 @@ class Admin::PushRulesController < Admin::ApplicationController
params.require(:push_rule).permit(allowed_fields)
end
# rubocop: disable CodeReuse/ActiveRecord
def push_rule
@push_rule ||= PushRule.find_or_initialize_by(is_sample: true)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -4,6 +4,7 @@ module Boards
# If board parent is a project it only enumerates project members
# If board parent is a group it enumerates all members of current group,
# ancestors, and descendants
# rubocop: disable CodeReuse/ActiveRecord
def index
user_ids = user_finder.execute.select(:user_id)
......@@ -11,6 +12,7 @@ module Boards
render json: UserSerializer.new.represent(users)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -22,6 +22,7 @@ module EE
)
end
# rubocop: disable CodeReuse/ActiveRecord
def objects_exceed_repo_limit?
return false unless project.size_limit_enabled?
......@@ -33,5 +34,6 @@ module EE
@exceeded_limit > 0 # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -17,6 +17,7 @@ module EE
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def override
member = @group.members.find_by!(id: params[:id])
updated_member = ::Members::UpdateService.new(current_user, override_params)
......@@ -28,6 +29,7 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
protected
......
......@@ -6,6 +6,7 @@ module EE
private
# rubocop: disable CodeReuse/ActiveRecord
def set_suggested_approvers
if merge_request.requires_approve?
@suggested_approvers = ::Gitlab::AuthorityAnalyzer.new( # rubocop:disable Gitlab/ModuleWithInstanceVariables
......@@ -14,6 +15,7 @@ module EE
).calculate(merge_request.approvals_required)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def merge_request_params
clamp_approvals_before_merge(super)
......
......@@ -37,6 +37,7 @@ module EE
# Assigning both @merge_request and @issuable like in
# `Projects::MergeRequests::ApplicationController`, and calling super if
# we don't need the extra includes requires us to disable this cop.
# rubocop: disable CodeReuse/ActiveRecord
def merge_request
return super unless APPROVAL_RENDERING_ACTIONS.include?(action_name.to_sym)
......@@ -48,6 +49,7 @@ module EE
.find_by!(iid: params[:id])
super
end
# rubocop: enable CodeReuse/ActiveRecord
def define_edit_vars
super
......
......@@ -20,6 +20,7 @@ module EE
@metric = project.prometheus_metrics.new # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
# rubocop: disable CodeReuse/ActiveRecord
def index
respond_to do |format|
format.json do
......@@ -34,6 +35,7 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def create
@metric = project.prometheus_metrics.create(metrics_params) # rubocop:disable Gitlab/ModuleWithInstanceVariables
......
......@@ -24,10 +24,12 @@ module EE
private
# rubocop: disable CodeReuse/ActiveRecord
def define_protected_env_variables
@protected_environments = @project.protected_environments.order(:name)
@protected_environment = @project.protected_environments.new
end
# rubocop: enable CodeReuse/ActiveRecord
def assign_variables_to_gon
gon.push(current_project_id: project.id)
......
......@@ -28,16 +28,20 @@ class Groups::AnalyticsController < Groups::ApplicationController
users.map { |user| data.fetch(user.id, 0) }
end
# rubocop: disable CodeReuse/ActiveRecord
def users
@users ||= @group.users.select(:id, :name, :username).reorder(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def load_events
@start_date = params[:start_date] || Date.today - 1.week
@events = Event.contributions
.where("created_at > ?", @start_date)
.where(project_id: @group.projects)
end
# rubocop: enable CodeReuse/ActiveRecord
def event_totals
@event_totals ||= {
......
......@@ -19,10 +19,12 @@ class Groups::AutocompleteSourcesController < Groups::ApplicationController
@autocomplete_service = ::Groups::AutocompleteService.new(@group, current_user)
end
# rubocop: disable CodeReuse/ActiveRecord
def target
case params[:type]&.downcase
when 'epic'
EpicsFinder.new(current_user, group_id: @group.id).find_by(iid: params[:type_id])
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -17,6 +17,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController
end
alias_method :awardable, :note
# rubocop: disable CodeReuse/ActiveRecord
def epic
@epic ||= @group.epics.find_by(iid: params[:epic_id])
......@@ -24,6 +25,7 @@ class Groups::Epics::NotesController < Groups::ApplicationController
@epic
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :epic
def finder_params
......
......@@ -44,6 +44,7 @@ class Groups::EpicsController < Groups::ApplicationController
request.format.json?
end
# rubocop: disable CodeReuse/ActiveRecord
def epic
@issuable = @epic ||= @group.epics.find_by(iid: params[:epic_id] || params[:id])
......@@ -51,6 +52,7 @@ class Groups::EpicsController < Groups::ApplicationController
@noteable = @epic
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :issuable, :epic
alias_method :awardable, :epic
alias_method :subscribable_resource, :epic
......
......@@ -25,10 +25,12 @@ class Groups::LdapGroupLinksController < Groups::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def destroy
@group.ldap_group_links.where(id: params[:id]).destroy_all # rubocop: disable DestroyAll
redirect_back_or_default(default: { action: 'index' }, options: { notice: 'LDAP link removed' })
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -6,6 +6,7 @@ class Groups::TodosController < Groups::ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def issuable
strong_memoize(:epic) do
next if params[:issuable_type] != 'epic'
......@@ -13,4 +14,5 @@ class Groups::TodosController < Groups::ApplicationController
@group.epics.find_by(id: params[:issuable_id])
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -12,6 +12,7 @@ class Oauth::GeoAuthController < ActionController::Base
redirect_to oauth.authorize_url(redirect_uri: oauth_geo_callback_url, state: params[:state])
end
# rubocop: disable CodeReuse/ActiveRecord
def callback
oauth = Gitlab::Geo::OauthSession.new(state: params[:state])
unless oauth.oauth_state_valid?
......@@ -30,6 +31,7 @@ class Oauth::GeoAuthController < ActionController::Base
invalid_credentials
end
end
# rubocop: enable CodeReuse/ActiveRecord
def logout
logout = Oauth2::LogoutTokenValidationService.new(current_user, params)
......
......@@ -13,6 +13,7 @@ class Projects::ApproverGroupsController < Projects::ApplicationController
access_denied! unless can?(current_user, :update_approvers, subject)
end
# rubocop: disable CodeReuse/ActiveRecord
def subject
@subject ||=
if params[:merge_request_id]
......@@ -21,4 +22,5 @@ class Projects::ApproverGroupsController < Projects::ApplicationController
project
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -13,6 +13,7 @@ class Projects::ApproversController < Projects::ApplicationController
access_denied! unless can?(current_user, :update_approvers, subject)
end
# rubocop: disable CodeReuse/ActiveRecord
def subject
@subject ||=
if params[:merge_request_id]
......@@ -21,4 +22,5 @@ class Projects::ApproversController < Projects::ApplicationController
project
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -19,11 +19,13 @@ module Projects
render_404 if link.target != issue && link.source != issue
end
# rubocop: disable CodeReuse/ActiveRecord
def issue
@issue ||=
IssuesFinder.new(current_user, project_id: @project.id)
.find_by!(iid: params[:issue_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def create_service
IssueLinks::CreateService.new(issue, current_user, create_params)
......
......@@ -14,6 +14,7 @@ class Projects::PathLocksController < Projects::ApplicationController
@path_locks = @project.path_locks.page(params[:page])
end
# rubocop: disable CodeReuse/ActiveRecord
def toggle
path_lock = @project.path_locks.find_by(path: params[:path])
......@@ -27,6 +28,7 @@ class Projects::PathLocksController < Projects::ApplicationController
rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied
access_denied!
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
path_lock = @project.path_locks.find(params[:id])
......
......@@ -9,11 +9,13 @@ module Projects
before_action :authorize_admin_project!, except: [:notify]
before_action :alert, only: [:update, :show, :destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index
alerts = project.prometheus_alerts.reorder(id: :asc)
render json: serialize_as_json(alerts)
end
# rubocop: enable CodeReuse/ActiveRecord
def show
render json: serialize_as_json(alert)
......@@ -81,9 +83,11 @@ module Projects
PrometheusAlertSerializer.new(project: project, current_user: current_user)
end
# rubocop: disable CodeReuse/ActiveRecord
def alert
@alert ||= project.prometheus_alerts.find_by(prometheus_metric_id: params[:id]) || render_404
end
# rubocop: enable CodeReuse/ActiveRecord
def application
@application ||= alert.environment.cluster_prometheus_adapter
......
......@@ -6,6 +6,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
respond_to :json
# rubocop: disable CodeReuse/ActiveRecord
def index
# TODO: Move to finder or list service
@vulnerability_feedback = @project.vulnerability_feedback.with_associations
......@@ -21,6 +22,7 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
render json: serializer.represent(@vulnerability_feedback)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
service = VulnerabilityFeedbackModule::CreateService.new(project, current_user, vulnerability_feedback_params)
......
......@@ -17,8 +17,10 @@ class UnsubscribesController < ApplicationController
protected
# rubocop: disable CodeReuse/ActiveRecord
def get_user
@email = Base64.urlsafe_decode64(params[:email])
User.where(email: @email).first
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -16,6 +16,8 @@ module Autocomplete
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/Finder
def execute
project = ::Autocomplete::ProjectFinder
.new(current_user, params)
......@@ -23,5 +25,7 @@ module Autocomplete
project ? project.invited_groups : Group.none
end
# rubocop: enable CodeReuse/Finder
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -11,6 +11,7 @@ module Boards
private
# rubocop: disable CodeReuse/Finder
def finder_service
parent = @board.parent
......@@ -28,5 +29,6 @@ module Boards
::MilestonesFinder.new(finder_params)
end
# rubocop: enable CodeReuse/Finder
end
end
......@@ -11,6 +11,7 @@ module Boards
private
# rubocop: disable CodeReuse/Finder
def finder_service
@finder_service ||=
if @board.parent.is_a?(Group)
......@@ -19,5 +20,6 @@ module Boards
MembersFinder.new(@board.parent, @current_user)
end
end
# rubocop: enable CodeReuse/Finder
end
end
......@@ -20,6 +20,7 @@ module EE
private
# rubocop: disable CodeReuse/ActiveRecord
def by_weight(items)
return items unless weights?
......@@ -31,6 +32,7 @@ module EE
items.where(weight: params[:weight])
end
end
# rubocop: enable CodeReuse/ActiveRecord
def weights?
params[:weight].present? && params[:weight] != ::Issue::WEIGHT_ALL
......@@ -57,6 +59,7 @@ module EE
super
end
# rubocop: disable CodeReuse/ActiveRecord
def assignees
strong_memoize(:assignees) do
if params[:assignee_ids]
......@@ -68,5 +71,6 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -13,6 +13,7 @@ module Epics
@epic_id = epic_id
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
strong_memoize(:execute) do
Milestone.joins(issues: :epic_issue).where(epic_issues: { epic_id: epic_id }).joins(
......@@ -28,6 +29,7 @@ module Epics
).pluck(*FIELDS)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def start_date
start_date_sourcing_milestone&.slice(START_DATE_INDEX)
......
......@@ -43,14 +43,17 @@ class EpicsFinder < IssuableFinder
@group = group
end
# rubocop: disable CodeReuse/ActiveRecord
def init_collection
groups = groups_user_can_read_epics(group.self_and_descendants)
Epic.where(group: groups)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def groups_user_can_read_epics(groups)
groups = Gitlab::GroupPlansPreloader.new.preload(groups)
......@@ -58,7 +61,9 @@ class EpicsFinder < IssuableFinder
groups.select { |g| Ability.allowed?(current_user, :read_epic, g) }
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_timeframe(items)
return items unless params[:start_date] && params[:end_date]
......@@ -72,4 +77,5 @@ class EpicsFinder < IssuableFinder
rescue ArgumentError
items
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -46,6 +46,7 @@ module Geo
#
# @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: [])
relation =
if use_legacy_queries?
......@@ -56,7 +57,9 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: [])
relation =
if use_legacy_queries?
......@@ -67,23 +70,29 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_file_ids: [])
find_failed_registries
.retry_due
.where.not(file_id: except_file_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: [])
find_synced_missing_on_primary_registries
.retry_due
.where.not(file_id: except_file_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def all
if selective_sync?
Upload.where(group_uploads.or(project_uploads).or(other_uploads))
......@@ -91,7 +100,9 @@ module Geo
Upload.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def group_uploads
namespace_ids =
if current_node.selective_sync_by_namespaces?
......@@ -110,6 +121,7 @@ module Geo
upload_table[:model_type].eq('Namespace').and(namespace_ids_in_sql)
end
# rubocop: enable CodeReuse/ActiveRecord
def project_uploads
project_ids = current_node.projects.select(:id)
......@@ -170,12 +182,15 @@ module Geo
fdw_find_syncable.merge(Geo::FileRegistry.failed)
end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_syncable
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.geo_syncable
.merge(Geo::FileRegistry.attachments)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_file_ids:)
upload_types = Geo::FileService::DEFAULT_OBJECT_TYPES.map { |val| "'#{val}'" }.join(',')
......@@ -186,11 +201,13 @@ module Geo
.where(file_registry: { id: nil })
.where.not(id: except_file_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_find_synced_missing_on_primary
fdw_find_synced.merge(Geo::FileRegistry.missing_on_primary)
end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all
if selective_sync?
Geo::Fdw::Upload.where(group_uploads.or(project_uploads).or(other_uploads))
......@@ -198,22 +215,26 @@ module Geo
Geo::Fdw::Upload.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table
Geo::Fdw::Upload.table_name
end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_file_ids:)
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.with_files_stored_remotely
.merge(Geo::FileRegistry.attachments)
.where.not(id: except_file_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
#
# Legacy accessors (non FDW)
#
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced
legacy_inner_join_registry_ids(
syncable,
......@@ -221,7 +242,9 @@ module Geo
Upload
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed
legacy_inner_join_registry_ids(
syncable,
......@@ -229,7 +252,9 @@ module Geo
Upload
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_file_ids:)
registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) | except_file_ids
......@@ -239,7 +264,9 @@ module Geo
Upload
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_file_ids:)
registry_file_ids = Geo::FileRegistry.attachments.pluck(:file_id) - except_file_ids
......@@ -249,7 +276,9 @@ module Geo
Upload
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids(
syncable,
......@@ -257,5 +286,6 @@ module Geo
Upload
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -21,6 +21,7 @@ module Geo
#
# @return [ActiveRecord::Relation<Geo::Fdw::Upload>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_project_uploads(project)
fdw_table = Geo::Fdw::Upload.table_name
upload_type = 'file'
......@@ -31,8 +32,10 @@ module Geo
AND #{fdw_table}.model_type='#{project.class.name}'
AND file_registry.file_type='#{upload_type}'")
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::FileRegistry>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_file_registries_uploads(project)
fdw_table = Geo::Fdw::Upload.table_name
upload_type = 'file'
......@@ -43,12 +46,14 @@ module Geo
AND #{fdw_table}.model_type='#{project.class.name}'
AND file_registry.file_type='#{upload_type}'")
end
# rubocop: enable CodeReuse/ActiveRecord
#
# Legacy accessors (non FDW)
#
# @return [ActiveRecord::Relation<Geo::FileRegistry>] list of file registry items
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_file_registries_uploads(project)
upload_ids = Upload.where(model_type: project.class.name, model_id: project.id).pluck(:id)
......@@ -64,8 +69,10 @@ module Geo
AND file_registry.file_type='#{upload_type}'
SQL
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Upload>] list of upload files
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_project_uploads(project)
file_registry_ids = legacy_find_file_registries_uploads(project).pluck(:file_id)
......@@ -79,5 +86,6 @@ module Geo
ON (file_registry.file_id = uploads.id)
SQL
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -42,6 +42,7 @@ module Geo
#
# @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_artifact_ids: [])
relation =
if use_legacy_queries?
......@@ -52,7 +53,9 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_artifact_ids: [])
relation =
if use_legacy_queries?
......@@ -63,27 +66,33 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
def syncable
all.geo_syncable
end
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_artifact_ids: [])
find_failed_registries
.retry_due
.where.not(artifact_id: except_artifact_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_artifact_ids: [])
find_synced_missing_on_primary_registries
.retry_due
.where.not(artifact_id: except_artifact_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def all
if selective_sync?
Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects })
......@@ -91,6 +100,7 @@ module Geo
Ci::JobArtifact.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def find_synced
if use_legacy_queries?
......@@ -132,11 +142,14 @@ module Geo
# FDW accessors
#
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find
fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id")
.geo_syncable
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_artifact_ids:)
fdw_all.joins("LEFT OUTER JOIN job_artifact_registry
ON job_artifact_registry.artifact_id = #{fdw_table}.id")
......@@ -144,14 +157,18 @@ module Geo
.where(job_artifact_registry: { artifact_id: nil })
.where.not(id: except_artifact_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_artifact_ids:)
fdw_all.joins("INNER JOIN job_artifact_registry ON job_artifact_registry.artifact_id = #{fdw_table}.id")
.with_files_stored_remotely
.where.not(id: except_artifact_ids)
.merge(Geo::JobArtifactRegistry.all)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all
if selective_sync?
Geo::Fdw::Ci::JobArtifact.joins(:project).where(projects: { id: current_node.projects })
......@@ -159,6 +176,7 @@ module Geo
Geo::Fdw::Ci::JobArtifact.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table
Geo::Fdw::Ci::JobArtifact.table_name
......@@ -168,6 +186,7 @@ module Geo
# Legacy accessors (non FDW)
#
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced
legacy_inner_join_registry_ids(
syncable,
......@@ -175,7 +194,9 @@ module Geo
Ci::JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed
legacy_inner_join_registry_ids(
syncable,
......@@ -183,7 +204,9 @@ module Geo
Ci::JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_artifact_ids:)
registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) | except_artifact_ids
......@@ -193,7 +216,9 @@ module Geo
Ci::JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_artifact_ids:)
registry_artifact_ids = Geo::JobArtifactRegistry.pluck(:artifact_id) - except_artifact_ids
......@@ -203,7 +228,9 @@ module Geo
Ci::JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids(
syncable,
......@@ -211,5 +238,6 @@ module Geo
Ci::JobArtifact
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -42,6 +42,7 @@ module Geo
#
# @param [Integer] batch_size used to limit the results returned
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: [])
relation =
if use_legacy_queries?
......@@ -52,7 +53,9 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_file_ids: [])
relation =
if use_legacy_queries?
......@@ -63,27 +66,33 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
def syncable
all.geo_syncable
end
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_file_ids: [])
find_failed_registries
.retry_due
.where.not(file_id: except_file_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_file_ids: [])
find_synced_missing_on_primary_registries
.retry_due
.where.not(file_id: except_file_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def all
if selective_sync?
LfsObject.joins(:projects).where(projects: { id: current_node.projects })
......@@ -91,6 +100,7 @@ module Geo
LfsObject.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def find_synced
if use_legacy_queries?
......@@ -124,12 +134,15 @@ module Geo
# FDW accessors
#
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.geo_syncable
.merge(Geo::FileRegistry.lfs_objects)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced(except_file_ids:)
fdw_all.joins("LEFT OUTER JOIN file_registry
ON file_registry.file_id = #{fdw_table}.id
......@@ -138,13 +151,16 @@ module Geo
.where(file_registry: { id: nil })
.where.not(id: except_file_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_migrated_local(except_file_ids:)
fdw_all.joins("INNER JOIN file_registry ON file_registry.file_id = #{fdw_table}.id")
.with_files_stored_remotely
.where.not(id: except_file_ids)
.merge(Geo::FileRegistry.lfs_objects)
end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_find_synced
fdw_find.merge(Geo::FileRegistry.synced)
......@@ -158,6 +174,7 @@ module Geo
fdw_find.merge(Geo::FileRegistry.failed)
end
# rubocop: disable CodeReuse/ActiveRecord
def fdw_all
if selective_sync?
Geo::Fdw::LfsObject.joins(:project).where(projects: { id: current_node.projects })
......@@ -165,6 +182,7 @@ module Geo
Geo::Fdw::LfsObject.all
end
end
# rubocop: enable CodeReuse/ActiveRecord
def fdw_table
Geo::Fdw::LfsObject.table_name
......@@ -174,6 +192,7 @@ module Geo
# Legacy accessors (non FDW)
#
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced
legacy_inner_join_registry_ids(
syncable,
......@@ -181,7 +200,9 @@ module Geo
LfsObject
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_failed
legacy_inner_join_registry_ids(
syncable,
......@@ -189,7 +210,9 @@ module Geo
LfsObject
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced(except_file_ids:)
registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) | except_file_ids
......@@ -199,7 +222,9 @@ module Geo
LfsObject
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_migrated_local(except_file_ids:)
registry_file_ids = Geo::FileRegistry.lfs_objects.pluck(:file_id) - except_file_ids
......@@ -209,7 +234,9 @@ module Geo
LfsObject
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_missing_on_primary
legacy_inner_join_registry_ids(
syncable,
......@@ -217,5 +244,6 @@ module Geo
LfsObject
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -113,6 +113,7 @@ module Geo
end
end
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced_projects(batch_size:)
relation =
if use_legacy_queries?
......@@ -123,7 +124,9 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_projects_updated_recently(batch_size:)
relation =
if use_legacy_queries?
......@@ -134,6 +137,7 @@ module Geo
relation.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
protected
......@@ -183,10 +187,12 @@ module Geo
#
# @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_unsynced_projects
Geo::Fdw::Project.joins("LEFT OUTER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id")
.where(project_registry: { project_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_synced_wikis
......@@ -194,14 +200,17 @@ module Geo
end
# @return [ActiveRecord::Relation<Geo::Fdw::Project>]
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_projects_updated_recently
Geo::Fdw::Project.joins("INNER JOIN project_registry ON project_registry.project_id = #{fdw_project_table}.id")
.merge(Geo::ProjectRegistry.dirty)
.merge(Geo::ProjectRegistry.retry_due)
end
# rubocop: enable CodeReuse/ActiveRecord
# Find all registries that repository or wiki need verification
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
# rubocop: disable CodeReuse/ActiveRecord
def fdw_find_registries_to_verify(batch_size:)
repo_condition =
local_repo_condition
......@@ -215,6 +224,7 @@ module Geo
.where(repo_condition.or(wiki_condition))
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_verified_wikis
......@@ -233,6 +243,7 @@ module Geo
#
# @return [ActiveRecord::Relation<Project>] list of unsynced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_unsynced_projects
legacy_left_outer_join_registry_ids(
current_node.projects,
......@@ -240,8 +251,10 @@ module Geo
Project
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Project>] list of projects updated recently
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_projects_updated_recently
registries = Geo::ProjectRegistry.dirty.retry_due.pluck(:project_id, :last_repository_synced_at)
return Project.none if registries.empty?
......@@ -259,6 +272,7 @@ module Geo
joined_relation
end
# rubocop: enable CodeReuse/ActiveRecord
def quote_value(value)
::Gitlab::SQL::Glob.q(value)
......@@ -270,6 +284,7 @@ module Geo
end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of synced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_synced_wikis
legacy_inner_join_registry_ids(
current_node.projects,
......@@ -277,6 +292,7 @@ module Geo
Project
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified projects
def legacy_find_verified_repositories
......@@ -284,6 +300,7 @@ module Geo
end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified wikis
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_verified_wikis
legacy_inner_join_registry_ids(
current_node.projects,
......@@ -291,8 +308,10 @@ module Geo
Project
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Project>] list of synced projects
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_project_registries(project_registries)
legacy_inner_join_registry_ids(
current_node.projects,
......@@ -300,8 +319,10 @@ module Geo
Project
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that sync has failed
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_failed_projects(type = nil)
legacy_inner_join_registry_ids(
find_filtered_failed_project_registries(type),
......@@ -310,8 +331,10 @@ module Geo
foreign_key: :project_id
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects that verification has failed
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_verification_failed_projects(type = nil)
legacy_inner_join_registry_ids(
find_filtered_verification_failed_project_registries(type),
......@@ -320,8 +343,10 @@ module Geo
foreign_key: :project_id
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of projects where there is a checksum_mismatch
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_filtered_checksum_mismatch_projects(type = nil)
legacy_inner_join_registry_ids(
find_filtered_checksum_mismatch_project_registries(type),
......@@ -330,8 +355,10 @@ module Geo
foreign_key: :project_id
)
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
# rubocop: disable CodeReuse/ActiveRecord
def legacy_find_registries_to_verify(batch_size:)
registries = Geo::ProjectRegistry
.where(local_repo_condition.or(local_wiki_condition))
......@@ -364,6 +391,7 @@ module Geo
Geo::ProjectRegistry.where(project_id: project_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
def legacy_repository_state_table
::ProjectRepositoryState.arel_table
......
......@@ -11,6 +11,7 @@ module Geo
#
# We consider fully synced any project without pending actions
# or failures
# rubocop: disable CodeReuse/ActiveRecord
def synced_projects
no_repository_resync = project_registry[:resync_repository].eq(false)
no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil)
......@@ -22,11 +23,13 @@ module Geo
.and(repository_verified)
).includes(project: :route).includes(project: { namespace: :route })
end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry which project is pending to update
#
# We include here only projects that have successfully synced before.
# We exclude projects that have tried to re-sync or re-check already and had failures
# rubocop: disable CodeReuse/ActiveRecord
def pending_projects
no_repository_sync_failure = project_registry[:repository_retry_count].eq(nil)
repository_successfully_synced_before = project_registry[:last_repository_successful_sync_at].not_eq(nil)
......@@ -42,10 +45,12 @@ module Geo
.and(repository_without_verification_failure_before)))
).includes(project: :route).includes(project: { namespace: :route })
end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry which project has a failure
#
# Both types of failures are included: Synchronization and Verification
# rubocop: disable CodeReuse/ActiveRecord
def failed_projects
repository_sync_failed = project_registry[:repository_retry_count].gt(0)
repository_verification_failed = project_registry[:last_repository_verification_failure].not_eq(nil)
......@@ -57,16 +62,19 @@ module Geo
.or(repository_checksum_mismatch)
).includes(project: :route).includes(project: { namespace: :route })
end
# rubocop: enable CodeReuse/ActiveRecord
# Return any project registry that has never been fully synced
#
# We don't include projects without a corresponding ProjectRegistry
# for performance reasons.
# rubocop: disable CodeReuse/ActiveRecord
def never_synced_projects
Geo::ProjectRegistry.where(last_repository_successful_sync_at: nil)
.includes(project: :route)
.includes(project: { namespace: :route })
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -24,6 +24,7 @@ module Geo
!Gitlab::Geo::Fdw.enabled? || selective_sync?
end
# rubocop: disable CodeReuse/ActiveRecord
def legacy_inner_join_registry_ids(objects, registry_ids, klass, foreign_key: :id)
return klass.none if registry_ids.empty?
......@@ -36,7 +37,9 @@ module Geo
joined_relation
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def legacy_left_outer_join_registry_ids(objects, registry_ids, klass)
return objects if registry_ids.empty?
......@@ -49,5 +52,6 @@ module Geo
joined_relation.where(registry: { registry_present: [nil, false] })
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -4,6 +4,7 @@ module Geo
@shard_name = shard_name
end
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_repositories(batch_size:)
query = build_query_to_find_failed_projects(type: :repository, batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:failed_repositories, query)
......@@ -12,7 +13,9 @@ module Geo
.from(cte.alias_to(projects_table))
.order("projects.repository_retry_at ASC")
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_wikis(batch_size:)
query = build_query_to_find_failed_projects(type: :wiki, batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:failed_wikis, query)
......@@ -21,7 +24,9 @@ module Geo
.from(cte.alias_to(projects_table))
.order("projects.wiki_retry_at ASC")
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_outdated_projects(batch_size:)
query = build_query_to_find_outdated_projects(batch_size: batch_size)
cte = Gitlab::SQL::CTE.new(:outdated_projects, query)
......@@ -30,7 +35,9 @@ module Geo
.from(cte.alias_to(projects_table))
.order(last_repository_updated_at_asc)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_unverified_projects(batch_size:)
relation =
Project.select(:id)
......@@ -42,6 +49,7 @@ module Geo
relation = apply_shard_restriction(relation) if shard_name.present?
relation
end
# rubocop: enable CodeReuse/ActiveRecord
def count_verified_repositories
Project.verified_repos.count
......@@ -63,6 +71,7 @@ module Geo
attr_reader :shard_name
# rubocop: disable CodeReuse/ActiveRecord
def build_query_to_find_failed_projects(type:, batch_size:)
query =
projects_table
......@@ -74,7 +83,9 @@ module Geo
query = apply_shard_restriction(query) if shard_name.present?
query
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def build_query_to_find_outdated_projects(batch_size:)
query =
projects_table
......@@ -86,6 +97,7 @@ module Geo
query = apply_shard_restriction(query) if shard_name.present?
query
end
# rubocop: enable CodeReuse/ActiveRecord
def projects_table
Project.arel_table
......@@ -124,8 +136,10 @@ module Geo
Gitlab::Database.nulls_last_order('projects.last_repository_updated_at', 'ASC')
end
# rubocop: disable CodeReuse/ActiveRecord
def apply_shard_restriction(relation)
relation.where(projects_table[:repository_storage].eq(shard_name))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -10,9 +10,11 @@ class LogFinder
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
AuditEvent.order(id: :desc).where(conditions).page(@params[:page]).per(PER_PAGE)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -17,8 +17,10 @@ class Packages::MavenPackageFinder
private
# rubocop: disable CodeReuse/ActiveRecord
def packages
project.packages.joins(:maven_metadatum)
.where(packages_maven_metadata: { path: path })
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -17,7 +17,9 @@ class Packages::PackageFileFinder
private
# rubocop: disable CodeReuse/ActiveRecord
def package_files
package.package_files.where(file_name: file_name)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -11,6 +11,7 @@ class SoftwareLicensePoliciesFinder
@project = project
end
# rubocop: disable CodeReuse/ActiveRecord
def find_by_name_or_id(id)
return nil unless can?(current_user, :read_software_license_policy, project)
......@@ -20,4 +21,5 @@ class SoftwareLicensePoliciesFinder
software_licenses[:name].eq(id).or(software_license_policies[:id].eq(id))
).take
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -15,6 +15,7 @@ module EE
end
# Tries to find a matching partial first, if there is none, we try to find a matching view
# rubocop: disable CodeReuse/ActiveRecord
def find_ce_template(name)
prefixes = [] # So don't create extra [] garbage
......@@ -24,6 +25,7 @@ module EE
ce_lookup_context.find(name, prefixes, false)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def ce_lookup_context
@ce_lookup_context ||= begin
......
......@@ -44,6 +44,7 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def namespaces_options_with_developer_maintainer_access(options = {})
selected = options.delete(:selected) || :current_user
options[:groups] = current_user.manageable_groups(include_groups_with_developer_maintainer_access: true)
......@@ -52,5 +53,6 @@ module EE
namespaces_options(selected, options)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -10,9 +10,11 @@ module EE
end
override :find_project_for_result_blob
# rubocop: disable CodeReuse/ActiveRecord
def find_project_for_result_blob(result)
super || ::Project.find_by(id: result['_parent'])
end
# rubocop: enable CodeReuse/ActiveRecord
override :parse_search_result
def parse_search_result(result)
......
......@@ -18,6 +18,7 @@ module Emails
subject: subject('Mirror user changed'))
end
# rubocop: disable CodeReuse/ActiveRecord
def prometheus_alert_fired_email(project_id, user_id, alert_params)
alert_metric_id = alert_params["labels"]["gitlab_alert_id"]
......@@ -36,6 +37,7 @@ module Emails
mail(to: user.notification_email, subject: subject(subject_text))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -3,10 +3,12 @@ class ClearNamespaceSharedRunnersMinutesService < BaseService
@namespace = namespace
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
NamespaceStatistics.where(namespace: @namespace).update_all(
shared_runners_seconds: 0,
shared_runners_seconds_last_reset: Time.now
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -6,6 +6,7 @@ module CleanupApprovers
private
# rubocop: disable CodeReuse/ActiveRecord
def cleanup_approvers(target, reload: false)
target.approvers.where.not(user_id: params[:approver_ids]).destroy_all # rubocop: disable DestroyAll
target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all # rubocop: disable DestroyAll
......@@ -19,4 +20,5 @@ module CleanupApprovers
target
end
# rubocop: enable CodeReuse/ActiveRecord
end
module EE
module Boards
module BaseService
# rubocop: disable CodeReuse/ActiveRecord
def set_assignee
assignee = ::User.find_by(id: params.delete(:assignee_id))
params.merge!(assignee: assignee)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def set_milestone
milestone_id = params[:milestone_id]
......@@ -27,6 +30,7 @@ module EE
params[:milestone_id] = milestone&.id
end
# rubocop: enable CodeReuse/ActiveRecord
def set_labels
labels = params.delete(:labels)
......
......@@ -22,6 +22,7 @@ module EE
end
override :issues_label_links
# rubocop: disable CodeReuse/ActiveRecord
def issues_label_links
if has_valid_milestone?
super.where("issues.milestone_id = ?", board.milestone_id)
......@@ -29,9 +30,11 @@ module EE
super
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def all_assignee_lists
if parent.feature_available?(:board_assignee_lists)
board.lists.assignee.where.not(user_id: nil)
......@@ -39,7 +42,9 @@ module EE
::List.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def all_milestone_lists
if parent.feature_available?(:board_milestone_lists)
board.lists.milestone.where.not(milestone_id: nil)
......@@ -47,33 +52,40 @@ module EE
::List.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def without_assignees_from_lists(issues)
return issues if all_assignee_lists.empty?
issues
.where.not(id: issues.joins(:assignees).where(users: { id: all_assignee_lists.select(:user_id) }))
end
# rubocop: enable CodeReuse/ActiveRecord
override :metadata_fields
def metadata_fields
super.merge(total_weight: 'COALESCE(SUM(weight), 0)')
end
# rubocop: disable CodeReuse/ActiveRecord
def without_milestones_from_lists(issues)
return issues if all_milestone_lists.empty?
issues.where("milestone_id NOT IN (?) OR milestone_id IS NULL",
all_milestone_lists.select(:milestone_id))
end
# rubocop: enable CodeReuse/ActiveRecord
def with_assignee(issues)
issues.assigned_to(list.user)
end
# rubocop: disable CodeReuse/ActiveRecord
def with_milestone(issues)
issues.where(milestone_id: list.milestone_id)
end
# rubocop: enable CodeReuse/ActiveRecord
# Prevent filtering by milestone stubs
# like Milestone::Upcoming, Milestone::Started etc
......
......@@ -4,6 +4,7 @@ module EE
extend ::Gitlab::Utils::Override
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute
if parent.multiple_issue_boards_available?
super
......@@ -15,13 +16,16 @@ module EE
boards.where(id: super.first).reorder(nil)
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
override :boards
# rubocop: disable CodeReuse/ActiveRecord
def boards
super.order('LOWER(name) ASC')
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -36,10 +36,12 @@ module EE
milestones.find(params['milestone_id'])
end
# rubocop: disable CodeReuse/ActiveRecord
def find_user(board)
user_ids = user_finder(board).execute.select(:user_id)
::User.where(id: user_ids).find(params['assignee_id'])
end
# rubocop: enable CodeReuse/ActiveRecord
def milestone_finder(board)
@milestone_finder ||= ::Boards::MilestonesFinder.new(board, current_user)
......
......@@ -9,6 +9,7 @@ module EE
extend ::Gitlab::Utils::Override
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(board)
not_available_lists =
list_type_features_availability(board).select { |_, available| !available }
......@@ -19,6 +20,7 @@ module EE
super
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -23,6 +23,7 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def builds_for_shared_runner
return super unless shared_runner_build_limits_feature_enabled?
......@@ -31,7 +32,9 @@ module EE
.where("projects.visibility_level=? OR (#{builds_check_limit.to_sql})=1", # rubocop:disable GitlabSecurity/SqlInjection
::Gitlab::VisibilityLevel::PUBLIC)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def builds_check_limit
all_namespaces
.joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id')
......@@ -40,7 +43,9 @@ module EE
application_shared_runners_minutes, application_shared_runners_minutes)
.select('1')
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def all_namespaces
namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id')
......@@ -50,6 +55,7 @@ module EE
namespaces
end
# rubocop: enable CodeReuse/ActiveRecord
def application_shared_runners_minutes
::Gitlab::CurrentSettings.shared_runners_minutes
......
......@@ -27,7 +27,7 @@ module EE
if epic_param
EpicIssues::CreateService.new(epic_param, current_user, { target_issue: issue }).execute
else
link = EpicIssue.find_by(issue_id: issue.id)
link = EpicIssue.find_by(issue_id: issue.id) # rubocop: disable CodeReuse/ActiveRecord
return unless link
......
module EE
module Lfs
module UnlockFileService
# rubocop: disable CodeReuse/ActiveRecord
def execute
result = super
......@@ -12,6 +13,7 @@ module EE
result
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
module EE
module Milestones
module PromoteService
# rubocop: disable CodeReuse/ActiveRecord
def update_children(group_milestone, milestone_ids)
boards = ::Board.where(project_id: group_project_ids, milestone_id: milestone_ids)
......@@ -8,6 +9,7 @@ module EE
super
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -6,6 +6,7 @@ module EE
extend ::Gitlab::Utils::Override
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(milestone)
super
......@@ -17,6 +18,7 @@ module EE
milestone
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -50,6 +50,7 @@ module EE
project.group&.refresh_members_authorized_projects
end
# rubocop: disable CodeReuse/ActiveRecord
def create_predefined_push_rule
return unless project.feature_available?(:push_rules)
......@@ -60,6 +61,7 @@ module EE
project.push_rule = push_rule
end
end
# rubocop: enable CodeReuse/ActiveRecord
def setup_ci_cd_project
return unless ::License.feature_available?(:ci_cd_projects)
......
......@@ -25,19 +25,23 @@ module EE
raise UsersNotAccessibleError.new unless users_accessible?
end
# rubocop: disable CodeReuse/ActiveRecord
def groups_accessible?
group_ids = @merge_params.group_ids + @push_params.group_ids + @unprotect_params.group_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables
allowed_groups = @project.invited_groups.where(id: group_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables
group_ids.count == allowed_groups.count
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def users_accessible?
user_ids = @merge_params.user_ids + @push_params.user_ids + @unprotect_params.user_ids # rubocop:disable Gitlab/ModuleWithInstanceVariables
allowed_users = @project.team.users.where(id: user_ids) # rubocop:disable Gitlab/ModuleWithInstanceVariables
user_ids.count == allowed_users.count
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -10,6 +10,7 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def mirror_cleanup(user)
user_mirrors = ::Project.where(mirror_user: user)
......@@ -20,6 +21,7 @@ module EE
::NotificationService.new.project_mirror_user_changed(new_mirror_user, user.name, mirror)
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -9,10 +9,12 @@ module EE
super
end
# rubocop: disable CodeReuse/ActiveRecord
def migrate_epics
user.epics.update_all(author_id: ghost_user.id)
::Epic.where(last_edited_by_id: user.id).update_all(last_edited_by_id: ghost_user.id)
end
# rubocop: enable CodeReuse/ActiveRecord
def migrate_vulnerability_feedback
user.vulnerability_feedback.update_all(author_id: ghost_user.id)
......
......@@ -8,6 +8,7 @@ module EpicIssues
private
# rubocop: disable CodeReuse/ActiveRecord
def relate_issues(referenced_issue)
link = EpicIssue.find_or_initialize_by(issue: referenced_issue)
......@@ -23,6 +24,7 @@ module EpicIssues
yield params
end
# rubocop: enable CodeReuse/ActiveRecord
def create_notes(referenced_issue, params)
if params[:issue_moved]
......
......@@ -17,9 +17,11 @@ module Geo
private
# rubocop: disable CodeReuse/ActiveRecord
def private_token
# TODO: should we ask admin user to be defined as part of configuration?
@private_token ||= User.find_by(admin: true).authentication_token
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -122,9 +122,11 @@ module Geo
false
end
# rubocop: disable CodeReuse/ActiveRecord
def registry
@registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id)
end
# rubocop: enable CodeReuse/ActiveRecord
def mark_sync_as_successful(missing_on_primary: false)
log_info("Marking #{type} sync as successful")
......@@ -189,6 +191,7 @@ module Geo
@temp_repo ||= ::Repository.new(repository.full_path, repository.project, disk_path: disk_path_temp, is_wiki: repository.is_wiki)
end
# rubocop: disable CodeReuse/ActiveRecord
def clean_up_temporary_repository
exists = gitlab_shell.exists?(project.repository_storage, disk_path_temp + '.git')
......@@ -196,6 +199,7 @@ module Geo
raise Gitlab::Shell::Error, "Temporary #{type} can not be removed"
end
end
# rubocop: enable CodeReuse/ActiveRecord
def set_temp_repository_as_main
log_info(
......
......@@ -47,6 +47,7 @@ module Geo
log_info("File download", metadata)
end
# rubocop: disable CodeReuse/ActiveRecord
def update_registry(bytes_downloaded, mark_as_synced:, missing_on_primary: false)
registry =
if object_type.to_sym == :job_artifact
......@@ -75,6 +76,7 @@ module Geo
registry.save
end
# rubocop: enable CodeReuse/ActiveRecord
def lease_key
"file_download_service:#{object_type}:#{object_db_id}"
......
......@@ -32,6 +32,7 @@ module Geo
private
# rubocop: disable CodeReuse/ActiveRecord
def file_registry
strong_memoize(:file_registry) do
if object_type.to_sym == :job_artifact
......@@ -41,6 +42,7 @@ module Geo
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def file_path
strong_memoize(:file_path) do
......@@ -57,6 +59,7 @@ module Geo
end
end
# rubocop: disable CodeReuse/ActiveRecord
def file_uploader
strong_memoize(:file_uploader) do
case object_type.to_s
......@@ -74,6 +77,7 @@ module Geo
log_error('Could not build uploader', err.message)
raise
end
# rubocop: enable CodeReuse/ActiveRecord
def upload?
Geo::FileService::DEFAULT_OBJECT_TYPES.include?(object_type.to_s)
......
......@@ -39,6 +39,7 @@ module Geo
private
# rubocop: disable CodeReuse/ActiveRecord
def schedule_file_removal(uploads)
paths_to_remove = uploads.find_each(batch_size: BATCH_SIZE).each_with_object([]) do |upload, to_remove|
file_path = File.join(base_dir, upload.path)
......@@ -52,6 +53,7 @@ module Geo
Geo::FileRemovalWorker.bulk_perform_async(paths_to_remove)
end
# rubocop: enable CodeReuse/ActiveRecord
def mark_for_resync!
finder.find_file_registries_uploads(project).delete_all
......
......@@ -23,9 +23,11 @@ module Geo
syncs_since_gc > 0 && period_match? && housekeeping_enabled?
end
# rubocop: disable CodeReuse/ActiveRecord
def registry
@registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id)
end
# rubocop: enable CodeReuse/ActiveRecord
def increment!
Gitlab::Metrics.measure(:geo_increment_syncs_since_gc) do
......
......@@ -6,6 +6,7 @@ module Geo
@type = type
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
return unless Gitlab::Geo.geo_database_configured?
return unless Gitlab::Geo.secondary?
......@@ -21,6 +22,7 @@ module Geo
num_updated
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -19,10 +19,12 @@ module Issues
Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now
end
# rubocop: disable CodeReuse/ActiveRecord
def csv_builder
@csv_builder ||=
CsvBuilder.new(@issues.preload(:author, :assignees, :timelogs), header_to_value_hash)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
module MergeRequests
class RemoveApprovalService < MergeRequests::BaseService
# rubocop: disable CodeReuse/ActiveRecord
def execute(merge_request)
# paranoid protection against running wrong deletes
return unless merge_request.id && current_user.id
......@@ -19,6 +20,7 @@ module MergeRequests
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -28,7 +28,7 @@ module Projects
def alert
strong_memoize(:alert) do
metric.prometheus_alerts.find_by(project: project)
metric.prometheus_alerts.find_by(project: project) # rubocop: disable CodeReuse/ActiveRecord
end
end
......
......@@ -34,6 +34,7 @@ module Projects
private
# rubocop: disable CodeReuse/ActiveRecord
def make_sure_chat_name_created(slack_data)
service = project.gitlab_slack_application_service
......@@ -54,6 +55,7 @@ module Projects
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def exchange_slack_token
Gitlab::HTTP.get(SLACK_EXCHANGE_TOKEN_URL, query: {
......
......@@ -3,6 +3,7 @@ module ProtectedEnvironments
class SearchService < BaseService
# Returns unprotected environments filtered by name
# Limited to 20 per performance reasons
# rubocop: disable CodeReuse/ActiveRecord
def execute(name)
project
.environments
......@@ -12,5 +13,6 @@ module ProtectedEnvironments
.limit(20)
.pluck(:name)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -46,9 +46,11 @@ module SlashCommands
params[:original_command] == 'help'
end
# rubocop: disable CodeReuse/ActiveRecord
def find_integration
SlackIntegration.find_by(team_id: params[:team_id], alias: project_alias)
end
# rubocop: enable CodeReuse/ActiveRecord
# Splits the command
# '/gitlab help' => [nil, 'help']
......
......@@ -8,6 +8,7 @@ module SoftwareLicensePolicies
end
# Returns the created managed license.
# rubocop: disable CodeReuse/ActiveRecord
def execute
return error("", 403) unless can?(@current_user, :admin_software_license_policy, @project)
......@@ -39,5 +40,6 @@ module SoftwareLicensePolicies
success(software_license_policy: software_license_policy)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
-# rubocop: disable CodeReuse/ActiveRecord
- return unless Gitlab::CurrentSettings.should_check_namespace_plan?
.form-group.row
......
......@@ -22,8 +22,8 @@
%h3 Push
- code_push_count = @events.code_push.count
- commits_count = @events.code_push.map(&:commits_count).sum
- person_count = @events.code_push.pluck(:author_id).uniq.count
- commits_count = @events.code_push.map(&:commits_count).sum # rubocop: disable CodeReuse/ActiveRecord
- person_count = @events.code_push.pluck(:author_id).uniq.count # rubocop: disable CodeReuse/ActiveRecord
- person_count_string = pluralize person_count, 'person'
- pushes_string = _('<strong>%{pushes}</strong> pushes, more than <strong>%{commits}</strong> commits by <strong>%{people}</strong> contributors.').html_safe % { pushes: code_push_count, commits: commits_count , people: person_count_string }
- if code_push_count > 0 || commits_count > 0 || person_count > 0
......@@ -49,7 +49,7 @@
%h3 Issues
- issues_created_count = @events.issues.created.count
- issues_closed_count = @events.issues.closed.pluck(:target_id).uniq.count
- issues_closed_count = @events.issues.closed.pluck(:target_id).uniq.count # rubocop: disable CodeReuse/ActiveRecord
- if issues_created_count > 0 && issues_closed_count > 0
= _('<strong>%{created_count}</strong> created, <strong>%{closed_count}</strong> closed.').html_safe % { created_count: issues_created_count, closed_count: issues_closed_count }
- else
......
......@@ -26,7 +26,7 @@
This merge request must be approved by these users.
You can override the project settings by setting your own list of approvers.
- skip_groups = issuable.overall_approver_groups.pluck(:group_id)
- skip_groups = issuable.overall_approver_groups.pluck(:group_id) # rubocop: disable CodeReuse/ActiveRecord
= groups_select_tag('merge_request[approver_group_ids]', multiple: true, data: { skip_groups: skip_groups, all_available: true, project: issuable.target_project }, class: 'input-large')
.form-text.text-muted
This merge request must be approved by members of these groups.
......
......@@ -2,7 +2,7 @@
- return unless milestone.supports_weight?
- total_weight = milestone.issues_visible_to_user(current_user).sum(:weight)
- total_weight = milestone.issues_visible_to_user(current_user).sum(:weight) # rubocop: disable CodeReuse/ActiveRecord
.block.weight
.sidebar-collapsed-icon.has-tooltip{ title: milestone_weight_tooltip_text(total_weight), data: { container: 'body', placement: 'left' } }
= icon('balance-scale')
......
class AdminEmailsWorker
include ApplicationWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(recipient_id, subject, body)
recipient_list(recipient_id).pluck(:id).uniq.each do |user_id|
Notify.send_admin_notification(user_id, subject, body).deliver_later
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -5,6 +5,7 @@ class ChatNotificationWorker
RESCHEDULE_INTERVAL = 2.seconds
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
send_response(build)
......@@ -16,6 +17,7 @@ class ChatNotificationWorker
# the job instead of producing an error.
self.class.perform_in(RESCHEDULE_INTERVAL, build_id)
end
# rubocop: enable CodeReuse/ActiveRecord
def send_response(build)
Gitlab::Chat::Responder.responder_for(build).try do |responder|
......
......@@ -4,6 +4,7 @@ class ClearSharedRunnersMinutesWorker
include ApplicationWorker
include CronjobQueue
# rubocop: disable CodeReuse/ActiveRecord
def perform
return unless try_obtain_lease
......@@ -17,6 +18,7 @@ class ClearSharedRunnersMinutesWorker
shared_runners_seconds: 0,
shared_runners_seconds_last_reset: Time.now)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -7,6 +7,7 @@ class ClusterUpdateAppWorker
sidekiq_options retry: 3, dead: false
# rubocop: disable CodeReuse/ActiveRecord
def perform(app_name, app_id, project_id, scheduled_time)
project = Project.find_by(id: project_id)
return unless project
......@@ -18,4 +19,5 @@ class ClusterUpdateAppWorker
Clusters::Applications::PrometheusUpdateService.new(app, project).execute
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
module EE
module BuildFinishedWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
super
......@@ -7,5 +8,6 @@ module EE
ChatNotificationWorker.perform_async(build_id) if build.pipeline.chat?
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -7,6 +7,7 @@ module EE
private
override :never_checked_project_ids
# rubocop: disable CodeReuse/ActiveRecord
def never_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary?
......@@ -16,8 +17,10 @@ module EE
.where('last_wiki_synced_at < ?', 24.hours.ago)
.limit(batch_size).pluck(:project_id)
end
# rubocop: enable CodeReuse/ActiveRecord
override :old_checked_project_ids
# rubocop: disable CodeReuse/ActiveRecord
def old_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary?
......@@ -26,6 +29,7 @@ module EE
.reorder(last_repository_check_at: :asc)
.limit(batch_size).pluck(:project_id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -7,6 +7,7 @@ module EE
private
override :update_repository_check_status
# rubocop: disable CodeReuse/ActiveRecord
def update_repository_check_status(project, healthy)
return super unless ::Gitlab::Geo.secondary?
......@@ -18,6 +19,7 @@ module EE
)
project_registry.save!
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -27,6 +27,7 @@ class ElasticBatchProjectIndexerWorker
logger.warn("#{err.message} indexing #{project.full_name} (ID=#{project.id}), trace - #{err.backtrace}")
end
# rubocop: disable CodeReuse/ActiveRecord
def build_relation(start, finish, update_index)
relation = Project.includes(:index_status)
......@@ -40,4 +41,5 @@ class ElasticBatchProjectIndexerWorker
relation
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -10,14 +10,18 @@ module Geo
private
# Why do we need a different `file_type` for each Uploader? Why not just use 'upload'?
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation)
relation.pluck(:id, :uploader)
.map { |id, uploader| [uploader.sub(/Uploader\z/, '').underscore, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def convert_registry_relation_to_job_args(relation)
relation.pluck(:file_type, :file_id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -46,13 +46,17 @@ module Geo
}
end
# rubocop: disable CodeReuse/ActiveRecord
def convert_resource_relation_to_job_args(relation)
relation.pluck(:id).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def convert_registry_relation_to_job_args(relation)
relation.pluck(self.class::RESOURCE_ID_KEY).map { |id| [self.class::FILE_SERVICE_OBJECT_TYPE.to_s, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -42,6 +42,7 @@ module Geo
take_batch(lfs_object_ids, attachment_ids, job_artifact_ids)
end
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_lfs_objects_ids(batch_size:)
return [] unless lfs_objects_object_store_enabled?
......@@ -49,7 +50,9 @@ module Geo
.pluck(:id)
.map { |id| ['lfs', id] }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_attachments_ids(batch_size:)
return [] unless attachments_object_store_enabled?
......@@ -57,7 +60,9 @@ module Geo
.pluck(:uploader, :id)
.map { |uploader, id| [uploader.sub(/Uploader\z/, '').underscore, id] }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local_job_artifacts_ids(batch_size:)
return [] unless job_artifacts_object_store_enabled?
......@@ -65,6 +70,7 @@ module Geo
.pluck(:id)
.map { |id| ['job_artifact', id] }
end
# rubocop: enable CodeReuse/ActiveRecord
def scheduled_file_ids(file_types)
file_types = Array(file_types)
......
......@@ -12,6 +12,7 @@ module Geo
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
end
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, scheduled_time)
registry = Geo::ProjectRegistry.find_or_initialize_by(project_id: project_id)
project = registry.project
......@@ -30,5 +31,6 @@ module Geo
Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time)
Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -8,6 +8,7 @@ module Geo
LEASE_TIMEOUT = 60.minutes
TRUNCATE_DELAY = 10.minutes
# rubocop: disable CodeReuse/ActiveRecord
def perform
return if Gitlab::Database.read_only?
......@@ -34,6 +35,7 @@ module Geo
.each_batch { |batch| batch.delete_all }
end
end
# rubocop: enable CodeReuse/ActiveRecord
def lease_timeout
LEASE_TIMEOUT
......
......@@ -8,6 +8,7 @@ module Geo
BATCH_SIZE = 250
LEASE_TIMEOUT = 60.minutes
# rubocop: disable CodeReuse/ActiveRecord
def perform(geo_node_id)
# Prevent multiple Sidekiq workers from performing repositories clean up
try_obtain_lease do
......@@ -23,9 +24,11 @@ module Geo
rescue ActiveRecord::RecordNotFound => e
log_error('Could not find Geo node, skipping repositories clean up', geo_node_id: geo_node_id, error: e)
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def clean_up_repositories(project)
# There is a possibility project does not have repository or wiki
return true unless gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git")
......@@ -38,6 +41,7 @@ module Geo
log_error('Could not clean up repository', project_id: project.id, shard: project.repository.storage, disk_path: project.disk_path)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def lease_timeout
LEASE_TIMEOUT
......
......@@ -61,22 +61,28 @@ module Geo
end
end
# rubocop: disable CodeReuse/ActiveRecord
def find_project_ids_not_synced(batch_size:)
shard_restriction(finder.find_unsynced_projects(batch_size: batch_size))
.where.not(id: scheduled_project_ids)
.reorder(last_repository_updated_at: :desc)
.pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_project_ids_updated_recently(batch_size:)
shard_restriction(finder.find_projects_updated_recently(batch_size: batch_size))
.where.not(id: scheduled_project_ids)
.order('project_registry.last_repository_synced_at ASC NULLS FIRST, projects.last_repository_updated_at ASC')
.pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def shard_restriction(relation)
relation.where(repository_storage: shard_name)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -51,13 +51,17 @@ module Geo
resources + find_failed_project_ids(batch_size: remaining_capacity)
end
# rubocop: disable CodeReuse/ActiveRecord
def find_unverified_project_ids(batch_size:)
finder.find_unverified_projects(batch_size: batch_size).pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_outdated_project_ids(batch_size:)
finder.find_outdated_projects(batch_size: batch_size).pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
def find_failed_project_ids(batch_size:)
repositories_ids = find_failed_repositories_ids(batch_size: batch_size)
......@@ -66,13 +70,17 @@ module Geo
take_batch(repositories_ids, wiki_ids, batch_size: batch_size)
end
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_repositories_ids(batch_size:)
finder.find_failed_repositories(batch_size: batch_size).pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_failed_wiki_ids(batch_size:)
finder.find_failed_wikis(batch_size: batch_size).pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -10,6 +10,7 @@ module Geo
attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id)
return unless Gitlab::Geo.primary?
......@@ -20,6 +21,7 @@ module Geo
Geo::RepositoryVerificationPrimaryService.new(project).execute
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -24,10 +24,12 @@ module Geo
current_node.verification_max_capacity
end
# rubocop: disable CodeReuse/ActiveRecord
def load_pending_resources
finder.find_registries_to_verify(batch_size: db_retrieve_batch_size)
.pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
def schedule_job(registry_id)
job_id = Geo::RepositoryVerification::Secondary::SingleWorker.perform_async(registry_id)
......
......@@ -14,6 +14,7 @@ module Geo
delegate :project, to: :registry
# rubocop: disable CodeReuse/ActiveRecord
def perform(registry_id)
return unless Gitlab::Geo.secondary?
......@@ -25,6 +26,7 @@ module Geo
verify_checksum(:wiki)
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -107,9 +107,11 @@ module Geo
(Time.now.utc - start_time) >= run_time
end
# rubocop: disable CodeReuse/ActiveRecord
def take_batch(*arrays, batch_size: db_retrieve_batch_size)
interleave(*arrays).uniq.compact.take(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
# Combines the elements of multiple, arbitrary-length arrays into a single array.
#
......
class LdapGroupSyncWorker
include ApplicationWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(group_ids, provider = nil)
return unless Gitlab::Auth::LDAP::Config.group_sync_enabled?
......@@ -14,6 +15,7 @@ class LdapGroupSyncWorker
sync_groups(groups)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def sync_groups(groups, proxy: nil)
groups.each { |group| sync_group(group, proxy: proxy) }
......
......@@ -2,6 +2,7 @@ class LdapSyncWorker
include ApplicationWorker
include CronjobQueue
# rubocop: disable CodeReuse/ActiveRecord
def perform
return unless Gitlab::Auth::LDAP::Config.group_sync_enabled?
......@@ -13,4 +14,5 @@ class LdapSyncWorker
Gitlab::Auth::LDAP::Access.allowed?(ldap_user, update_ldap_group_links_synchronously: true)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -2,8 +2,10 @@ class ProjectImportScheduleWorker
include ApplicationWorker
prepend WaitableWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id)
project = Project.find_by(id: project_id)
project&.import_schedule
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -15,6 +15,7 @@ class UpdateAllMirrorsWorker
cancel_lease(lease_uuid)
end
# rubocop: disable CodeReuse/ActiveRecord
def schedule_mirrors!
capacity = Gitlab::Mirror.available_capacity
......@@ -42,6 +43,7 @@ class UpdateAllMirrorsWorker
ProjectImportScheduleWorker.bulk_perform_and_wait(all_project_ids.map { |id| [id] }, timeout: SCHEDULE_WAIT_TIMEOUT.to_i)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......@@ -53,6 +55,7 @@ class UpdateAllMirrorsWorker
::Gitlab::ExclusiveLease.cancel(LEASE_KEY, uuid)
end
# rubocop: disable CodeReuse/ActiveRecord
def pull_mirrors_batch(freeze_at:, batch_size:, offset_at: nil)
relation = Project
.mirrors_to_sync(freeze_at)
......@@ -64,4 +67,5 @@ class UpdateAllMirrorsWorker
relation
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -18,9 +18,11 @@ module API
authorize!(:admin_epic, epic)
end
# rubocop: disable CodeReuse/ActiveRecord
def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end
# rubocop: enable CodeReuse/ActiveRecord
def link
@link ||= epic.epic_issues.find(params[:epic_issue_id])
......@@ -81,6 +83,7 @@ module API
params do
requires :epic_iid, type: Integer, desc: 'The iid of the epic'
end
# rubocop: disable CodeReuse/ActiveRecord
post ':id/(-/)epics/:epic_iid/issues/:issue_id' do
authorize_can_admin!
......@@ -98,6 +101,7 @@ module API
render_api_error!(result[:message], result[:http_status])
end
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove an issue from the epic' do
success EE::API::Entities::EpicIssueLink
......
......@@ -26,10 +26,13 @@ module API
authorize!(:destroy_epic, epic)
end
# rubocop: disable CodeReuse/ActiveRecord
def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_epics(args = {})
args = declared_params.merge(args)
args[:label_name] = args.delete(:labels)
......@@ -38,6 +41,7 @@ module API
epics.reorder(args[:order_by] => args[:sort])
end
# rubocop: enable CodeReuse/ActiveRecord
end
params do
......
......@@ -29,6 +29,7 @@ module API
requires :target_project_id, type: String, desc: 'The ID of the target project'
requires :target_issue_iid, type: Integer, desc: 'The IID of the target issue'
end
# rubocop: disable CodeReuse/ActiveRecord
post ':id/issues/:issue_iid/links' do
source_issue = find_project_issue(params[:issue_iid])
target_issue = find_project_issue(declared_params[:target_issue_iid],
......@@ -48,6 +49,7 @@ module API
render_api_error!(result[:message], result[:http_status])
end
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove issues relation' do
success EE::API::Entities::IssueLink
......
......@@ -31,6 +31,7 @@ module API
params do
requires 'cn', type: String, desc: 'The CN of a LDAP group'
end
# rubocop: disable CodeReuse/ActiveRecord
delete ":id/ldap_group_links/:cn" do
group = find_group(params[:id])
authorize! :admin_group, group
......@@ -43,12 +44,14 @@ module API
render_api_error!('Linked LDAP group not found', 404)
end
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Remove a linked LDAP group from group'
params do
requires 'cn', type: String, desc: 'The CN of a LDAP group'
requires 'provider', type: String, desc: 'The LDAP provider for this LDAP group'
end
# rubocop: disable CodeReuse/ActiveRecord
delete ":id/ldap_group_links/:provider/:cn" do
group = find_group(params[:id])
authorize! :admin_group, group
......@@ -61,6 +64,7 @@ module API
render_api_error!('Linked LDAP group not found', 404)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -87,6 +87,7 @@ module API
values: %w(approved blacklisted),
desc: 'The approval status of the license. "blacklisted" or "approved".'
end
# rubocop: disable CodeReuse/ActiveRecord
patch ':id/managed_licenses/:managed_license_id', requirements: { managed_license_id: /.*/ } do
authorize_can_admin!
break not_found!('SoftwareLicensePolicy') unless software_license_policy
......@@ -103,6 +104,7 @@ module API
render_api_error!(result[:message], result[:http_status])
end
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing software license policy from a project' do
success Entities::ManagedLicense
......
......@@ -36,28 +36,34 @@ module API
project
end
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_requests
merge_requests = authorized_merge_requests.reorder(updated_at: :desc).preload(:target_project)
merge_requests = paginate(merge_requests)
merge_requests.select { |mr| licensed_project?(mr.target_project) }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_with_access(id, access_level = :read_merge_request)
merge_request = authorized_merge_requests.find_by(id: id)
not_found! unless can?(current_user, access_level, merge_request)
merge_request
end
# rubocop: enable CodeReuse/ActiveRecord
def authorized_merge_requests
MergeRequestsFinder.new(current_user, authorized_only: true).execute
end
# rubocop: disable CodeReuse/ActiveRecord
def find_notes(noteable)
# They're not presented on Jira Dev Panel ATM. A comments count with a
# redirect link is presented.
notes = paginate(noteable.notes.user.reorder(nil))
notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
end
# rubocop: enable CodeReuse/ActiveRecord
def licensed_project?(project)
project.feature_available?(JIRA_DEV_PANEL_FEATURE)
......@@ -80,6 +86,7 @@ module API
params do
use :pagination
end
# rubocop: disable CodeReuse/ActiveRecord
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
namespace = Namespace.find_by_full_path(params[:namespace])
not_found!('Namespace') unless namespace
......@@ -89,6 +96,7 @@ module API
projects = ::Kaminari.paginate_array(projects)
present paginate(projects), with: ::API::Github::Entities::Repository
end
# rubocop: enable CodeReuse/ActiveRecord
end
# Jira dev panel integration weirdly requests for "/-/jira/pulls" instead
......
......@@ -39,6 +39,7 @@ module EE
end
# Overrides API::BoardsResponses authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
def authorize_list_type_resource!
if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id])
render_api_error!({ error: 'Label not found!' }, 400)
......@@ -60,6 +61,7 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Overrides API::BoardsResponses list_creation_params
params :list_creation_params do
......
......@@ -5,9 +5,11 @@ module EE
prepended do
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def epic
@epic ||= user_group.epics.find_by(iid: params[:epic_iid])
end
# rubocop: enable CodeReuse/ActiveRecord
def authorize_can_read!
authorize!(:read_epic, epic)
......
......@@ -36,9 +36,11 @@ module EE
)
end
# rubocop: disable CodeReuse/ActiveRecord
def parent_records(parent, ids)
parent.epics.where(iid: ids.to_a)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -2,6 +2,7 @@ module EE
module Banzai
module ReferenceParser
module EpicParser
# rubocop: disable CodeReuse/ActiveRecord
def records_for_nodes(nodes)
@epics_for_nodes ||= grouped_objects_for_nodes(
nodes,
......@@ -12,6 +13,7 @@ module EE
self.class.data_attribute
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -36,6 +36,7 @@ module EE
end
# Add ssh keys that are in LDAP but not in GitLab
# rubocop: disable CodeReuse/ActiveRecord
def add_new_ssh_keys
keys = ldap_user.ssh_keys - user.keys.ldap.pluck(:key)
......@@ -50,8 +51,10 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Remove ssh keys that do not exist in LDAP any more
# rubocop: disable CodeReuse/ActiveRecord
def remove_old_ssh_keys
keys = user.keys.ldap.where.not(key: ldap_user.ssh_keys)
......@@ -63,8 +66,10 @@ module EE
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Update user Kerberos identity with Kerberos principal name from Active Directory
# rubocop: disable CodeReuse/ActiveRecord
def update_kerberos_identity
# there can be only one Kerberos identity in GitLab; if the user has a Kerberos identity in AD,
# replace any existing Kerberos identity for the user
......@@ -80,6 +85,7 @@ module EE
"error messages: #{kerberos_identity.errors.messages}"
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Update user email if it changed in LDAP
def update_email
......@@ -110,6 +116,7 @@ module EE
ldap_config.active_directory && (::Gitlab.config.kerberos.enabled || ::AuthHelper.kerberos_enabled? )
end
# rubocop: disable CodeReuse/ActiveRecord
def update_memberships
return if ldap_user.nil? || ldap_user.group_cns.empty?
......@@ -119,6 +126,7 @@ module EE
::LdapGroupSyncWorker.perform_async(group_ids, provider) if group_ids.any?
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -6,10 +6,12 @@ module EE
attr_accessor :adapter
attr_reader :entry
# rubocop: disable CodeReuse/ActiveRecord
def self.find_by_cn(cn, adapter)
cn = Net::LDAP::Filter.escape(cn)
adapter.group(cn)
end
# rubocop: enable CodeReuse/ActiveRecord
def initialize(entry, adapter = nil)
Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
......
......@@ -229,10 +229,12 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def select_and_preload_group_members(group)
group.members.select(:id, :access_level, :user_id, :ldap, :override)
.with_identity_provider(provider).preload(:user)
end
# rubocop: enable CodeReuse/ActiveRecord
def logger
Rails.logger
......
......@@ -76,12 +76,14 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def groups_where_group_links_with_provider_ordered
::Group.where_group_links_with_provider(provider)
.preload(:ldap_group_links)
.reorder('ldap_sync_last_successful_update_at ASC, namespaces.id ASC')
.distinct
end
# rubocop: enable CodeReuse/ActiveRecord
def config
proxy.adapter.config
......
......@@ -108,6 +108,7 @@ module EE
dn
end
# rubocop: disable CodeReuse/ActiveRecord
def member_uid_to_dn(uid)
identity = ::Identity.with_secondary_extern_uid(provider, uid).take
......@@ -126,7 +127,9 @@ module EE
ldap_user.dn
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def update_identity(dn, uid)
identity = ::Identity.with_extern_uid(provider, dn).take
......@@ -136,6 +139,7 @@ module EE
identity.secondary_extern_uid = uid
identity.save
end
# rubocop: enable CodeReuse/ActiveRecord
def logger
Rails.logger
......
......@@ -15,6 +15,7 @@ module EE
@proxy = proxy
end
# rubocop: disable CodeReuse/ActiveRecord
def update_permissions
dns = member_dns
return true if dns.empty?
......@@ -40,6 +41,7 @@ module EE
false
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -7,6 +7,7 @@ module EE
JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN".freeze
JOB_TOKEN_PARAM = :job_token
# rubocop: disable CodeReuse/ActiveRecord
def find_user_from_job_token
return unless route_authentication_setting[:job_token_allowed]
......@@ -20,6 +21,7 @@ module EE
job.user
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -41,9 +41,11 @@ module EE
::Project.update(export_into_project_id, params)
end
# rubocop: disable CodeReuse/ActiveRecord
def export_into_project_exists?
::Project.exists?(export_into_project_id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -44,6 +44,7 @@ module EE
usage_data
end
# rubocop: disable CodeReuse/ActiveRecord
def projects_mirrored_with_pipelines_enabled
count(::Project.joins(:project_feature).where(
mirror: true,
......@@ -53,7 +54,9 @@ module EE
}
))
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service_desk_counts
return {} unless ::License.feature_available?(:service_desk)
......@@ -68,7 +71,9 @@ module EE
))
}
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def security_products_usage
types = {
container_scanning: :container_scanning_jobs,
......@@ -81,6 +86,7 @@ module EE
results = count(::Ci::Build.where(name: types.keys).group(:name))
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value }
end
# rubocop: enable CodeReuse/ActiveRecord
override :system_usage_data
def system_usage_data
......
......@@ -17,6 +17,7 @@ module EE
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
# rubocop: disable CodeReuse/ActiveRecord
def perform_geo_secondary(project_id, refresh = [])
project = ::Project.find_by(id: project_id)
......@@ -24,6 +25,7 @@ module EE
project.repository.refresh_method_caches(refresh.map(&:to_sym))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -18,12 +18,14 @@ module Gitlab
protected
# rubocop: disable CodeReuse/ActiveRecord
def identity
@identity ||= current_user.identities.where(provider: :group_saml,
saml_provider: saml_provider,
extern_uid: uid.to_s)
.first_or_initialize
end
# rubocop: enable CodeReuse/ActiveRecord
def update_group_membership
MembershipUpdater.new(current_user, saml_provider).execute
......
......@@ -8,12 +8,14 @@ module Gitlab
@users = Hash.new(0)
end
# rubocop: disable CodeReuse/ActiveRecord
def calculate(number_of_approvers)
involved_users
# Picks most active users from hash like: {user1: 2, user2: 6}
@users.sort_by { |user, count| -count }.map(&:first).take(number_of_approvers)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -9,7 +9,7 @@ module Gitlab
if blob.project.feature_available?(:code_owners)
Loader.new(blob.project, blob.commit_id, blob.path).users
else
User.none
User.none # rubocop: disable CodeReuse/ActiveRecord
end
end
end
......
......@@ -8,7 +8,7 @@ module Gitlab
end
def users
return User.none if code_owners_file.empty?
return User.none if code_owners_file.empty? # rubocop: disable CodeReuse/ActiveRecord
owners = code_owners_file.owners_for_path(@path)
extracted_users = Gitlab::UserExtractor.new(owners).users
......
module Gitlab
module Elastic
class Helper
# rubocop: disable CodeReuse/ActiveRecord
def self.create_empty_index
index_name = Project.index_name
settings = {}
......@@ -32,6 +33,7 @@ module Gitlab
mappings: mappings.to_hash
}
end
# rubocop: enable CodeReuse/ActiveRecord
def self.delete_index
Project.__elasticsearch__.delete_index!
......
......@@ -66,6 +66,7 @@ module Gitlab
raise Error, output unless status&.zero?
end
# rubocop: disable CodeReuse/ActiveRecord
def update_index_status(to_sha)
head_commit = repository.try(:commit)
......@@ -88,6 +89,7 @@ module Gitlab
index_status.update(last_commit: sha, indexed_at: Time.now)
project.index_status(true)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -248,6 +248,7 @@ module Gitlab
}
end
# rubocop: disable CodeReuse/ActiveRecord
def guest_project_ids
if current_user
current_user.authorized_projects
......@@ -257,6 +258,7 @@ module Gitlab
[]
end
end
# rubocop: enable CodeReuse/ActiveRecord
def non_guest_project_ids
if limit_project_ids == :any
......
......@@ -30,6 +30,7 @@ module Gitlab
mail_key
end
# rubocop: disable CodeReuse/ActiveRecord
def project
return @project if instance_variable_defined?(:@project)
......@@ -39,6 +40,7 @@ module Gitlab
@project = found_project&.service_desk_enabled? ? found_project : nil
end
# rubocop: enable CodeReuse/ActiveRecord
def create_issue!
# NB: the support bot is specifically forbidden
......
......@@ -18,13 +18,17 @@ module Gitlab
self.cache_value(:geo_node_current) { GeoNode.current_node }
end
# rubocop: disable CodeReuse/ActiveRecord
def self.primary_node
self.cache_value(:geo_primary_node) { GeoNode.find_by(primary: true) }
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def self.secondary_nodes
self.cache_value(:geo_secondary_nodes) { GeoNode.where(primary: false) }
end
# rubocop: enable CodeReuse/ActiveRecord
def self.connected?
Gitlab::Database.postgresql? && GeoNode.connected? && GeoNode.table_exists?
......
......@@ -46,6 +46,7 @@ module Gitlab
end
# accepts a block that should return whether the event was handled
# rubocop: disable CodeReuse/ActiveRecord
def fill_gaps
with_redis do |redis|
redis.zremrangebyscore(GEO_EVENT_LOG_GAPS, '-inf', outdated_timestamp)
......@@ -59,6 +60,7 @@ module Gitlab
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -19,6 +19,7 @@ module Gitlab
#
# Subclasses should return the number of bytes downloaded,
# or nil or -1 if a failure occurred.
# rubocop: disable CodeReuse/ActiveRecord
def execute
upload = Upload.find_by(id: object_db_id)
return fail_before_transfer unless upload.present?
......@@ -26,6 +27,7 @@ module Gitlab
transfer = ::Gitlab::Geo::FileTransfer.new(object_type.to_sym, upload)
Result.from_transfer_result(transfer.download_from_primary)
end
# rubocop: enable CodeReuse/ActiveRecord
class Result
attr_reader :success, :bytes_downloaded, :primary_missing_file, :failed_before_transfer
......
......@@ -18,6 +18,7 @@ module Gitlab
@message = message
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
recorded_file = Upload.find_by(id: object_db_id)
......@@ -27,6 +28,7 @@ module Gitlab
success(CarrierWave::SanitizedFile.new(recorded_file.absolute_path))
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -7,6 +7,7 @@ module Gitlab
#
# TODO: Rearrange things so this class does not inherit FileDownloader
class JobArtifactDownloader < FileDownloader
# rubocop: disable CodeReuse/ActiveRecord
def execute
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
return fail_before_transfer unless job_artifact.present?
......@@ -14,6 +15,7 @@ module Gitlab
transfer = ::Gitlab::Geo::JobArtifactTransfer.new(job_artifact)
Result.from_transfer_result(transfer.download_from_primary)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -6,6 +6,7 @@ module Gitlab
#
# TODO: Rearrange things so this class does not inherit from FileUploader
class JobArtifactUploader < ::Gitlab::Geo::FileUploader
# rubocop: disable CodeReuse/ActiveRecord
def execute
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
......@@ -21,6 +22,7 @@ module Gitlab
success(job_artifact.file)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -63,12 +63,14 @@ module Gitlab
end
end
# rubocop: disable CodeReuse/ActiveRecord
def hmac_secret(access_key)
@hmac_secret ||= begin
geo_node = GeoNode.find_by(access_key: access_key, enabled: true)
geo_node&.secret_access_key
end
end
# rubocop: enable CodeReuse/ActiveRecord
def decode_auth_header
return unless auth_header.present?
......
......@@ -7,6 +7,7 @@ module Gitlab
#
# TODO: Rearrange things so this class does not inherit FileDownloader
class LfsDownloader < FileDownloader
# rubocop: disable CodeReuse/ActiveRecord
def execute
lfs_object = LfsObject.find_by(id: object_db_id)
return fail_before_transfer unless lfs_object.present?
......@@ -14,6 +15,7 @@ module Gitlab
transfer = ::Gitlab::Geo::LfsTransfer.new(lfs_object)
Result.from_transfer_result(transfer.download_from_primary)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -6,6 +6,7 @@ module Gitlab
#
# TODO: Rearrange things so this class does not inherit from FileUploader
class LfsUploader < FileUploader
# rubocop: disable CodeReuse/ActiveRecord
def execute
lfs_object = LfsObject.find_by(id: object_db_id)
......@@ -20,6 +21,7 @@ module Gitlab
success(lfs_object.file)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -104,6 +104,7 @@ module Gitlab
@exit
end
# rubocop: disable CodeReuse/ActiveRecord
def can_replay?(event_log)
return true if event_log.project_id.nil?
......@@ -112,6 +113,7 @@ module Gitlab
Gitlab::Geo.current_node&.projects_include?(event_log.project_id)
end
# rubocop: enable CodeReuse/ActiveRecord
# Sleeps for the expired TTL that remains on the lease plus some random seconds.
#
......
......@@ -6,6 +6,7 @@ module Gitlab
BATCH_SIZE = 50
# fetches up to BATCH_SIZE next events and keep track of batches
# rubocop: disable CodeReuse/ActiveRecord
def fetch_in_batches(batch_size: BATCH_SIZE)
last_id = last_processed_id
......@@ -18,6 +19,7 @@ module Gitlab
break unless Lease.renew!
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -15,9 +15,11 @@ module Gitlab
attr_reader :event, :created_at, :logger
# rubocop: disable CodeReuse/ActiveRecord
def registry
@registry ||= ::Geo::ProjectRegistry.find_or_initialize_by(project_id: event.project_id)
end
# rubocop: enable CodeReuse/ActiveRecord
def skippable?
registry.new_record?
......
......@@ -19,9 +19,11 @@ module Gitlab
private
# rubocop: disable CodeReuse/ActiveRecord
def file_registry_job_artifacts
@file_registry_job_artifacts ||= ::Geo::JobArtifactRegistry.where(artifact_id: event.job_artifact_id)
end
# rubocop: enable CodeReuse/ActiveRecord
def file_path
@file_path ||= File.join(::JobArtifactUploader.root, event.file_path)
......
......@@ -5,12 +5,14 @@ module Gitlab
class LfsObjectDeletedEvent
include BaseEvent
# rubocop: disable CodeReuse/ActiveRecord
def process
# Must always schedule, regardless of shard health
job_id = ::Geo::FileRemovalWorker.perform_async(file_path)
log_event(job_id)
::Geo::FileRegistry.lfs_objects.where(file_id: event.lfs_object_id).delete_all
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -28,9 +28,11 @@ module Gitlab
).async_execute
end
# rubocop: disable CodeReuse/ActiveRecord
def delete_project_registry_entries
::Geo::ProjectRegistry.where(project_id: event.project_id).delete_all
end
# rubocop: enable CodeReuse/ActiveRecord
def log_event(job_id)
logger.event_info(
......
......@@ -5,10 +5,12 @@ module Gitlab
class UploadDeletedEvent
include BaseEvent
# rubocop: disable CodeReuse/ActiveRecord
def process
log_event
::Geo::FileRegistry.where(file_id: event.upload_id, file_type: event.upload_type).delete_all
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -13,6 +13,7 @@ module Gitlab
#
# Returns an Array containing all the Groups, including their preloaded
# plans.
# rubocop: disable CodeReuse/ActiveRecord
def preload(groups)
groups_and_ancestors = groups_and_ancestors_for(groups)
......@@ -52,6 +53,7 @@ module Gitlab
group.memoized_plans = plans_map[group.id].map { |id| plans[id] }
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Returns an ActiveRecord::Relation that includes the given groups, and all
# their (recursive) ancestors.
......
......@@ -43,10 +43,12 @@ module Gitlab
private
# rubocop: disable CodeReuse/ActiveRecord
def find_by_login(login)
identity = ::Identity.with_extern_uid(:kerberos, login).take
identity && identity.user
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......@@ -49,6 +49,7 @@ class Gitlab::PathLocksFinder
tokens
end
# rubocop: disable CodeReuse/ActiveRecord
def find_by_token(token)
if @non_locked_paths.include?(token)
return false
......@@ -62,8 +63,11 @@ class Gitlab::PathLocksFinder
lock
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_downstream(path)
@project.path_locks.find_by("path LIKE ?", "#{sanitize_sql_like(path)}%")
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -4,6 +4,7 @@ module Gitlab
module SlashCommands
module Presenters
class Run < Presenters::Base
# rubocop: disable CodeReuse/ActiveRecord
def present(pipeline)
build = pipeline.builds.take
......@@ -13,6 +14,7 @@ module Gitlab
unsupported_chat_service
end
end
# rubocop: enable CodeReuse/ActiveRecord
def unsupported_chat_service
ephemeral_response(text: 'Sorry, this chat service is currently not supported by GitLab ChatOps.')
......
......@@ -171,6 +171,7 @@ module API
optional(*optional_attributes)
at_least_one_of(*optional_attributes)
end
# rubocop: disable CodeReuse/ActiveRecord
put "application/settings" do
attrs = declared_params(include_missing: false)
......@@ -216,5 +217,6 @@ module API
render_validation_error!(current_settings)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
......@@ -266,6 +266,7 @@ module Gitlab
check_change_access!
end
# rubocop: disable CodeReuse/ActiveRecord
def check_change_access!
# If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also
......@@ -291,6 +292,7 @@ module Gitlab
raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
# rubocop: enable CodeReuse/ActiveRecord
def check_single_change_access(change, skip_lfs_integrity_check: false)
Checks::ChangeAccess.new(
......
......@@ -37,9 +37,11 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of groups
# and all their ancestors (recursively).
......
......@@ -314,13 +314,16 @@ if $0 == __FILE__
end
describe '.run_git_command' do
# rubocop: disable CodeReuse/ActiveRecord
it 'returns the single output when there is a single command' do
output = run_git_command('status')
expect(output).to be_kind_of(String)
expect(self).to have_received(:warn).with(/git status/)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
it 'returns an array of output for more commands' do
output = run_git_command('status', 'help')
......@@ -328,6 +331,7 @@ if $0 == __FILE__
expect(self).to have_received(:warn).with(/git status/)
expect(self).to have_received(:warn).with(/git help/)
end
# rubocop: enable CodeReuse/ActiveRecord
end
describe '.matching_ce_refs' do
......
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