chore: rename dossier_resolution => dossier_correction

This commit is contained in:
Colin Darie 2023-04-03 17:05:54 +02:00
parent b14a70abf7
commit 5ab44fc7a9
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
13 changed files with 64 additions and 64 deletions

View file

@ -1,13 +1,13 @@
module DossierResolvableConcern
module DossierCorrectableConcern
extend ActiveSupport::Concern
included do
has_many :resolutions, class_name: 'DossierResolution', dependent: :destroy
has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy
def flag_as_pending_correction!(commentaire)
return unless may_flag_as_pending_correction?
resolutions.create(commentaire:)
corrections.create(commentaire:)
return if en_construction?
@ -15,16 +15,16 @@ module DossierResolvableConcern
end
def may_flag_as_pending_correction?
return false if resolutions.pending.exists?
return false if corrections.pending.exists?
en_construction? || may_repasser_en_construction?
end
def pending_resolution?
def pending_correction?
# We don't want to show any alert if user is not allowed to modify the dossier
return false unless en_construction?
resolutions.pending.exists?
corrections.pending.exists?
end
end
end

View file

@ -47,13 +47,13 @@
# user_id :integer
#
class Dossier < ApplicationRecord
include DossierCloneConcern
include DossierCorrectableConcern
include DossierFilteringConcern
include DossierPrefillableConcern
include DossierRebaseConcern
include DossierResolvableConcern
include DossierSearchableConcern
include DossierSectionsConcern
include DossierCloneConcern
enum state: {
brouillon: 'brouillon',

View file

@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: dossier_resolutions
# Table name: dossier_corrections
#
# id :bigint not null, primary key
# resolved_at :datetime
@ -9,7 +9,7 @@
# commentaire_id :bigint
# dossier_id :bigint not null
#
class DossierResolution < ApplicationRecord
class DossierCorrection < ApplicationRecord
belongs_to :dossier
belongs_to :commentaire

View file

@ -184,7 +184,7 @@ class ProcedurePresentation < ApplicationRecord
dossiers.filter_by_datetimes(column, dates)
elsif field['column'] == "state" && values.include?("pending_correction")
dossiers.joins(:resolutions).where(resolutions: DossierResolution.pending)
dossiers.joins(:corrections).where(corrections: DossierCorrection.pending)
else
dossiers.where("dossiers.#{column} IN (?)", values)
end

View file

@ -1,9 +1,9 @@
class DossierProjectionService
class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :batch_operation_id, :resolutions, :columns) do
class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :batch_operation_id, :corrections, :columns) do
def pending_correction?
return false if resolutions.blank?
return false if corrections.blank?
resolutions.any? { _1[:resolved_at].nil? }
corrections.any? { _1[:resolved_at].nil? }
end
end
end
@ -29,8 +29,8 @@ class DossierProjectionService
batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' }
hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' }
hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' }
dossier_resolutions = { TABLE => 'dossier_resolutions', COLUMN => 'resolved_at' }
([state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field, dossier_resolutions] + fields) # the view needs state and archived dossier attributes
dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' }
([state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, batch_operation_field, dossier_corrections] + fields) # the view needs state and archived dossier attributes
.each { |f| f[:id_value_h] = {} }
.group_by { |f| f[TABLE] } # one query per table
.each do |table, fields|
@ -83,13 +83,13 @@ class DossierProjectionService
.where(id: dossiers_ids)
.pluck('dossiers.id, groupe_instructeurs.label')
.to_h
when 'dossier_resolutions'
when 'dossier_corrections'
columns = fields.map { _1[COLUMN].to_sym }
id_value_h = DossierResolution.where(dossier_id: dossiers_ids)
id_value_h = DossierCorrection.where(dossier_id: dossiers_ids)
.pluck(:dossier_id, *columns)
.group_by(&:first) # group resolutions by dossier_id
.transform_values do |values| # build each resolution has an hash column => value
.group_by(&:first) # group corrections by dossier_id
.transform_values do |values| # build each correction has an hash column => value
values.map { Hash[columns.zip(_1[1..-1])] }
end
@ -130,7 +130,7 @@ class DossierProjectionService
hidden_by_user_at_field[:id_value_h][dossier_id],
hidden_by_administration_at_field[:id_value_h][dossier_id],
batch_operation_field[:id_value_h][dossier_id],
dossier_resolutions[:id_value_h][dossier_id],
dossier_corrections[:id_value_h][dossier_id],
fields.map { |f| f[:id_value_h][dossier_id] }
)
end

View file

@ -5,7 +5,7 @@
= "Dossier nº #{dossier.id}"
= status_badge(dossier.state, 'super')
= pending_correction_badge(:for_instructeur) if dossier.pending_resolution?
= pending_correction_badge(:for_instructeur) if dossier.pending_correction?
= link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link"
= procedure_badge(dossier.procedure)

View file

@ -3,7 +3,7 @@
%h1
= dossier.procedure.libelle
= status_badge(dossier.state, 'super')
= pending_correction_badge(:for_user) if dossier.pending_resolution?
= pending_correction_badge(:for_user) if dossier.pending_correction?
%h2
= t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id)
- if dossier.depose_at.present?