Skip to content

Commit

Permalink
chore: rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
yhru committed Dec 11, 2024
1 parent 5229f10 commit 2f90a5a
Show file tree
Hide file tree
Showing 43 changed files with 71 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GroupeInstructeursController < AdministrateurController
before_action :ensure_not_super_admin!, only: [:add_instructeur]

ITEMS_PER_PAGE = 25
CSV_MAX_SIZE = 1.megabytes
CSV_MAX_SIZE = 1.megabyte
CSV_ACCEPTED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/administrateurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def filter_procedures(filter)
procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present?
procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.present?
procedures_result = procedures_result.where(template: true) if filter.template?
procedures_result = procedures_result.where('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present?
procedures_result = procedures_result.where(published_at: filter.from_publication_date..) if filter.from_publication_date.present?
procedures_result = procedures_result.where(service: service) if filter.service_siret.present?
procedures_result = procedures_result.where(service: services) if services
procedures_result = procedures_result.where(for_individual: filter.for_individual) if filter.for_individual.present?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/administrateurs/types_de_champ_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def move_and_morph
@created = champ_component_from(@coordinate)
@morphed = @coordinate.siblings
if from > to # case of moved up, update components from target (> plus one) to origin
@morphed = @morphed.where("position > ?", to).where("position <= ?", from)
@morphed = @morphed.where("position > ?", to).where(position: ..from)
else # case of moved down, update components from origin up to target (< minus one)
@morphed = @morphed.where("position >= ?", from).where("position < ?", to)
@morphed = @morphed.where(position: from..).where(position: ...to)
end

@morphed = @morphed.map { |c| champ_component_from(c) }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manager/procedures_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Manager
class ProceduresController < Manager::ApplicationController
CSV_MAX_SIZE = 1.megabytes
CSV_MAX_SIZE = 1.megabyte
CSV_ACCEPTED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel"
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/demarche_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil,
dossiers = dossiers.where(revision: find_revision(revision))
else
if !min_revision.nil?
dossiers = dossiers.joins(:revision).where('procedure_revisions.created_at >= ?', find_revision(min_revision).created_at)
dossiers = dossiers.joins(:revision).where(procedure_revisions: { created_at: find_revision(min_revision).created_at.. })
end

if !max_revision.nil?
dossiers = dossiers.joins(:revision).where('procedure_revisions.created_at <= ?', find_revision(max_revision).created_at)
dossiers = dossiers.joins(:revision).where(procedure_revisions: { created_at: ..find_revision(max_revision).created_at })
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/groupe_instructeur_with_dossiers_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil,
dossiers = dossiers.where(revision: find_revision(revision))
else
if !min_revision.nil?
dossiers = dossiers.joins(:revision).where('procedure_revisions.created_at >= ?', find_revision(min_revision).created_at)
dossiers = dossiers.joins(:revision).where(procedure_revisions: { created_at: find_revision(min_revision).created_at.. })
end

if !max_revision.nil?
dossiers = dossiers.joins(:revision).where('procedure_revisions.created_at <= ?', find_revision(max_revision).created_at)
dossiers = dossiers.joins(:revision).where(procedure_revisions: { created_at: ..find_revision(max_revision).created_at })
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/cron/auto_archive_procedure_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def perform(*args)
def procedures_to_close
Procedure
.publiees
.where("auto_archive_on <= ?", Time.zone.today)
.where(auto_archive_on: ..Time.zone.today)
end
end
2 changes: 1 addition & 1 deletion app/models/administrateur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def merge(old_admin)
i.administrateurs.delete(old_admin)
end

old_admin.api_tokens.where('version >= ?', 3).find_each do |token|
old_admin.api_tokens.where(version: 3..).find_each do |token|
self.api_tokens << token
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Archive < ApplicationRecord
)
}

enum time_span_type: {
enum :time_span_type, {
everything: 'everything',
monthly: 'monthly'
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/attestation_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AttestationTemplate < ApplicationRecord
validates :json_body, tags: true, if: -> { procedure.present? && version == 2 }
validates :footer, length: { maximum: 190 }

FILE_MAX_SIZE = 1.megabytes
FILE_MAX_SIZE = 1.megabyte
validates :logo, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: FILE_MAX_SIZE }
validates :signature, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: FILE_MAX_SIZE }

Expand Down
6 changes: 3 additions & 3 deletions app/models/batch_operation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class BatchOperation < ApplicationRecord
enum operation: {
enum :operation, {
accepter: 'accepter',
refuser: 'refuser',
classer_sans_suite: 'classer_sans_suite',
Expand Down Expand Up @@ -30,12 +30,12 @@ class BatchOperation < ApplicationRecord

scope :stale, lambda {
where.not(finished_at: nil)
.where('updated_at < ?', (Time.zone.now - RETENTION_DURATION))
.where(updated_at: ...(Time.zone.now - RETENTION_DURATION))
}

scope :stuck, lambda {
where(finished_at: nil)
.where('updated_at < ?', (Time.zone.now - MAX_DUREE_GENERATION))
.where(updated_at: ...(Time.zone.now - MAX_DUREE_GENERATION))
}

def dossiers_safe_scope(dossier_ids = self.dossier_ids)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/domain_migratable_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DomainMigratableConcern
extend ActiveSupport::Concern

included do
enum preferred_domain: { demarches_gouv_fr: 0, demarches_simplifiees_fr: 1 }, _prefix: true
enum :preferred_domain, { demarches_gouv_fr: 0, demarches_simplifiees_fr: 1 }, prefix: true

validates :preferred_domain, inclusion: { in: User.preferred_domains.keys, allow_nil: true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module TransientModelsWithPurgeableJobConcern
included do
include AASM

enum job_status: {
enum :job_status, {
pending: 'pending',
generated: 'generated',
failed: 'failed'
Expand All @@ -32,12 +32,12 @@ module TransientModelsWithPurgeableJobConcern

scope :stale, lambda { |duration|
where(job_status: [job_statuses.fetch(:generated), job_statuses.fetch(:failed)])
.where('updated_at < ?', (Time.zone.now - duration))
.where(updated_at: ...(Time.zone.now - duration))
}

scope :stuck, lambda { |duration|
where(job_status: [job_statuses.fetch(:pending)])
.where('updated_at < ?', (Time.zone.now - duration))
.where(updated_at: ...(Time.zone.now - duration))
}

def available?
Expand Down
6 changes: 3 additions & 3 deletions app/models/deleted_dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class DeletedDossier < ApplicationRecord
belongs_to :groupe_instructeur, inverse_of: :deleted_dossiers, optional: true

scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) }
scope :deleted_since, -> (since) { where(deleted_dossiers: { deleted_at: since.. }) }
scope :state_termine, -> { where(state: [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)]) }

enum reason: {
enum :reason, {
user_request: 'user_request',
manager_request: 'manager_request',
user_removed: 'user_removed',
Expand All @@ -16,7 +16,7 @@ class DeletedDossier < ApplicationRecord
user_expired: 'user_expired'
}

enum state: {
enum :state, {
en_construction: 'en_construction',
en_instruction: 'en_instruction',
accepte: 'accepte',
Expand Down
10 changes: 5 additions & 5 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Dossier < ApplicationRecord
include DossierStateConcern
include DossierChampsConcern

enum state: {
enum :state, {
brouillon: 'brouillon',
en_construction: 'en_construction',
en_instruction: 'en_instruction',
Expand Down Expand Up @@ -237,8 +237,8 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
scope :for_groupe_instructeur, -> (groupe_instructeurs) { where(groupe_instructeur: groupe_instructeurs) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order, id: order) }
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, id: order) }
scope :updated_since, -> (since) { where('dossiers.updated_at >= ?', since) }
scope :created_since, -> (since) { where('dossiers.depose_at >= ?', since) }
scope :updated_since, -> (since) { where(dossiers: { updated_at: since.. }) }
scope :created_since, -> (since) { where(dossiers: { depose_at: since.. }) }
scope :hidden_by_user_since, -> (since) { where('dossiers.hidden_by_user_at IS NOT NULL AND dossiers.hidden_by_user_at >= ?', since) }
scope :hidden_by_administration_since, -> (since) { where('dossiers.hidden_by_administration_at IS NOT NULL AND dossiers.hidden_by_administration_at >= ?', since) }
scope :hidden_since, -> (since) { hidden_by_user_since(since).or(hidden_by_administration_since(since)) }
Expand Down Expand Up @@ -370,8 +370,8 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
scope :without_termine_expiration_notice_sent, -> { where(termine_close_to_expiration_notice_sent_at: nil) }

scope :deleted_by_user_expired, -> { where('dossiers.hidden_by_user_at < ?', 1.week.ago) }
scope :deleted_by_administration_expired, -> { where('dossiers.hidden_by_administration_at < ?', 1.week.ago) }
scope :deleted_by_user_expired, -> { where(dossiers: { hidden_by_user_at: ...1.week.ago }) }
scope :deleted_by_administration_expired, -> { where(dossiers: { hidden_by_administration_at: ...1.week.ago }) }
scope :en_brouillon_expired_to_delete, -> { state_brouillon.deleted_by_user_expired }
scope :en_construction_expired_to_delete, -> { state_en_construction.deleted_by_user_expired }
scope :termine_expired_to_delete, -> { state_termine.deleted_by_user_expired.deleted_by_administration_expired }
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DossierAssignment < ApplicationRecord
belongs_to :groupe_instructeur, optional: true, inverse_of: :assignments
belongs_to :previous_groupe_instructeur, class_name: 'GroupeInstructeur', optional: true, inverse_of: :previous_assignments

enum mode: {
enum :mode, {
auto: 'auto',
manual: 'manual',
tech: 'tech'
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier_batch_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DossierBatchOperation < ApplicationRecord
belongs_to :batch_operation
has_many :groupe_instructeurs, through: :dossier

enum state: {
enum :state, {
pending: 'pending',
success: 'success',
error: 'error'
Expand Down
4 changes: 2 additions & 2 deletions app/models/dossier_correction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class DossierCorrection < ApplicationRecord

scope :pending, -> { where(resolved_at: nil) }

enum reason: {
enum :reason, {
incorrect: 'incorrect',
incomplete: 'incomplete',
outdated: 'outdated'
}, _prefix: :dossier
}, prefix: :dossier

def resolved?
resolved_at.present?
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier_operation_log.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DossierOperationLog < ApplicationRecord
enum operation: {
enum :operation, {
changer_groupe_instructeur: 'changer_groupe_instructeur',
passer_en_instruction: 'passer_en_instruction',
repasser_en_construction: 'repasser_en_construction',
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DossierTransfer < ApplicationRecord
before_validation -> { sanitize_email(:email) }

scope :pending, -> { where('created_at > ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :stale, -> { where('created_at < ?', (Time.zone.now - EXPIRATION_LIMIT)) }
scope :stale, -> { where(created_at: ...(Time.zone.now - EXPIRATION_LIMIT)) }
scope :with_dossiers, -> { joins(:dossiers).merge(Dossier.visible_by_user) }
scope :for_email, -> (email) { includes(dossiers: :user).with_dossiers.where(email: email) }

Expand Down
4 changes: 2 additions & 2 deletions app/models/dossiers_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def filter_procedures(dossiers)
dossiers_result = dossiers_result.where(state: state) if state.present? && state != Dossier::A_CORRIGER
dossiers_result = dossiers_result.with_pending_corrections if state.present? && state == Dossier::A_CORRIGER
dossiers_result = exclude_accuse_lecture(dossiers_result) if state.present? && Dossier::TERMINE.include?(state)
dossiers_result = dossiers_result.where('dossiers.created_at >= ?', from_created_at_date) if from_created_at_date.present?
dossiers_result = dossiers_result.where('dossiers.depose_at >= ?', from_depose_at_date) if from_depose_at_date.present?
dossiers_result = dossiers_result.where(dossiers: { created_at: from_created_at_date.. }) if from_created_at_date.present?
dossiers_result = dossiers_result.where(dossiers: { depose_at: from_depose_at_date.. }) if from_depose_at_date.present?
dossiers_result
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/email_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class EmailEvent < ApplicationRecord
RETENTION_DURATION = 1.month

enum status: {
enum :status, {
pending: 'pending',
dispatched: 'dispatched',
dispatch_error: 'dispatch_error'
Expand All @@ -11,7 +11,7 @@ class EmailEvent < ApplicationRecord
scope :dolist_smtp, -> { where(method: 'dolist_smtp') } # legacy method: removable after 2023-06
scope :dolist_api, -> { where(method: 'dolist_api') }
scope :sendinblue, -> { where(method: 'sendinblue') }
scope :outdated, -> { where("created_at < ?", RETENTION_DURATION.ago) }
scope :outdated, -> { where(created_at: ...RETENTION_DURATION.ago) }

class << self
def create_from_message!(message, status:)
Expand Down
4 changes: 2 additions & 2 deletions app/models/etablissement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Etablissement < ApplicationRecord
validates :siret, presence: true
validates :dossier_id, uniqueness: { allow_nil: true }

enum entreprise_etat_administratif: {
enum :entreprise_etat_administratif, {
actif: "actif",
fermé: "fermé"
}, _prefix: true
}, prefix: true

after_commit -> { dossier&.index_search_terms_later }

Expand Down
8 changes: 4 additions & 4 deletions app/models/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ class Export < ApplicationRecord
MAX_DUREE_CONSERVATION_EXPORT = 32.hours
MAX_DUREE_GENERATION = 16.hours

enum format: {
enum :format, {
csv: 'csv',
ods: 'ods',
xlsx: 'xlsx',
zip: 'zip',
json: 'json'
}, _prefix: true
}, prefix: true

enum time_span_type: {
enum :time_span_type, {
everything: 'everything',
monthly: 'monthly'
}

enum statut: {
enum :statut, {
'a-suivre': 'a-suivre',
suivis: 'suivis',
traites: 'traites',
Expand Down
2 changes: 1 addition & 1 deletion app/models/geo_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def filename
properties['filename']
end

enum source: {
enum :source, {
cadastre: 'cadastre',
selection_utilisateur: 'selection_utilisateur'
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/groupe_instructeur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GroupeInstructeur < ApplicationRecord

has_one_attached :signature

SIGNATURE_MAX_SIZE = 1.megabytes
SIGNATURE_MAX_SIZE = 1.megabyte
validates :signature, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: SIGNATURE_MAX_SIZE }

validates :label, presence: true, allow_nil: false
Expand Down
2 changes: 1 addition & 1 deletion app/models/individual.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Individual < ApplicationRecord
include SanitizeConcern

enum notification_method: {
enum :notification_method, {
email: 'email',
no_notification: 'no_notification'
}
Expand Down
10 changes: 5 additions & 5 deletions app/models/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def revisions_with_pending_dossiers
scope :publiques, -> do
publiees_ou_closes
.opendata
.where('estimated_dossiers_count >= ?', 4)
.where(estimated_dossiers_count: 4..)
.where.not('lien_site_web LIKE ?', '%mail%')
.where.not('lien_site_web LIKE ?', '%intra%')
end
Expand All @@ -204,7 +204,7 @@ def revisions_with_pending_dossiers
scope :discarded_expired, -> do
with_discarded
.discarded
.where('hidden_at < ?', 1.month.ago)
.where(hidden_at: ...1.month.ago)
end

scope :for_api, -> {
Expand All @@ -222,15 +222,15 @@ def revisions_with_pending_dossiers
)
}

enum declarative_with_state: {
enum :declarative_with_state, {
en_instruction: 'en_instruction',
accepte: 'accepte'
}

enum closing_reason: {
enum :closing_reason, {
internal_procedure: 'internal_procedure',
other: 'other'
}, _prefix: true
}, prefix: true

scope :for_api_v2, -> {
includes(:draft_revision, :published_revision, administrateurs: :user)
Expand Down
Loading

0 comments on commit 2f90a5a

Please sign in to comment.