Merge pull request #6002 from betagouv/remove-useless-code-avis-table
Nettoyage du code de migration des Experts (#6002)
This commit is contained in:
commit
07aa588edf
11 changed files with 19 additions and 43 deletions
|
@ -113,11 +113,12 @@ type Association {
|
|||
|
||||
type Avis {
|
||||
attachment: File
|
||||
claimant: Profile
|
||||
dateQuestion: ISO8601DateTime!
|
||||
dateReponse: ISO8601DateTime
|
||||
expert: Profile
|
||||
id: ID!
|
||||
instructeur: Profile!
|
||||
instructeur: Profile! @deprecated(reason: "Utilisez le champ claimant à la place.")
|
||||
question: String!
|
||||
reponse: String
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ module Types
|
|||
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
|
||||
]
|
||||
|
||||
field :instructeur, Types::ProfileType, null: false, method: :claimant
|
||||
field :instructeur, Types::ProfileType, null: false, method: :claimant, deprecation_reason: "Utilisez le champ claimant à la place."
|
||||
field :claimant, Types::ProfileType, null: true
|
||||
field :expert, Types::ProfileType, null: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -90,10 +90,10 @@ module Types
|
|||
def avis(id: nil)
|
||||
if id.present?
|
||||
Loaders::Record
|
||||
.for(Avis, where: { dossier: object }, includes: [:instructeur, :claimant], array: true)
|
||||
.for(Avis, where: { dossier: object }, includes: [:expert, :claimant], array: true)
|
||||
.load(ApplicationRecord.id_from_typed_id(id))
|
||||
else
|
||||
Loaders::Association.for(object.class, avis: [:instructeur, :claimant]).load(object)
|
||||
Loaders::Association.for(object.class, avis: [:expert, :claimant]).load(object)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@ class Avis < ApplicationRecord
|
|||
include EmailSanitizableConcern
|
||||
|
||||
belongs_to :dossier, inverse_of: :avis, touch: true, optional: false
|
||||
belongs_to :instructeur, optional: true
|
||||
belongs_to :experts_procedure, optional: false
|
||||
belongs_to :claimant, class_name: 'Instructeur', optional: false
|
||||
belongs_to :claimant, polymorphic: true, optional: false
|
||||
|
||||
has_one_attached :piece_justificative_file
|
||||
has_one_attached :introduction_file
|
||||
|
@ -57,26 +56,7 @@ class Avis < ApplicationRecord
|
|||
attr_accessor :emails
|
||||
attr_accessor :invite_linked_dossiers
|
||||
|
||||
def claimant
|
||||
claimant_id = read_attribute(:claimant_id)
|
||||
claimant_type = read_attribute(:claimant_type)
|
||||
if claimant_type == 'Instructeur' || !tmp_expert_migrated
|
||||
Instructeur.find(claimant_id)
|
||||
else
|
||||
Expert.find(claimant_id)
|
||||
end
|
||||
end
|
||||
|
||||
def claimant=(claimant)
|
||||
self.claimant_id = claimant.id
|
||||
|
||||
if claimant.is_a? Instructeur
|
||||
self.claimant_type = 'Instructeur'
|
||||
else
|
||||
self.claimant_type = 'Expert'
|
||||
self.tmp_expert_migrated = true
|
||||
end
|
||||
end
|
||||
self.ignored_columns = [:instructeur_id, :tmp_expert_migrated]
|
||||
|
||||
def email_to_display
|
||||
expert&.email
|
||||
|
|
|
@ -23,8 +23,6 @@ class Instructeur < ApplicationRecord
|
|||
has_many :previous_follows, -> { inactive }, class_name: 'Follow', inverse_of: :instructeur
|
||||
has_many :followed_dossiers, through: :follows, source: :dossier
|
||||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :avis
|
||||
has_many :dossiers_from_avis, through: :avis, source: :dossier
|
||||
has_many :trusted_device_tokens, dependent: :destroy
|
||||
|
||||
has_one :user, dependent: :nullify
|
||||
|
|
|
@ -21,7 +21,7 @@ class DossierSearchService
|
|||
end
|
||||
|
||||
def self.dossiers_by_id(id, instructeur)
|
||||
(instructeur.dossiers.where(id: id) + instructeur.dossiers_from_avis.where(id: id)).uniq
|
||||
instructeur.dossiers.where(id: id).uniq
|
||||
end
|
||||
|
||||
def self.id_compatible?(number)
|
||||
|
|
|
@ -109,7 +109,7 @@ class SerializerService
|
|||
reponse
|
||||
dateQuestion
|
||||
dateReponse
|
||||
instructeur {
|
||||
claimant {
|
||||
email
|
||||
}
|
||||
expert {
|
||||
|
|
|
@ -32,11 +32,13 @@
|
|||
- if current_instructeur.procedures.count > 0
|
||||
%li
|
||||
= active_link_to "Démarches", instructeur_procedures_path, active: ['dossiers','procedures'].include?(controller_name), class: 'tab-link'
|
||||
- if current_instructeur.avis.count > 0
|
||||
- if nav_bar_profile == :expert && expert_signed_in?
|
||||
- if current_expert.avis.count > 0
|
||||
%ul.header-tabs
|
||||
%li
|
||||
= active_link_to instructeur_all_avis_path, active: controller_name == 'avis', class: 'tab-link' do
|
||||
= active_link_to expert_all_avis_path, active: controller_name == 'avis', class: 'tab-link' do
|
||||
Avis
|
||||
- avis_counter = current_instructeur.avis.without_answer.count
|
||||
- avis_counter = current_expert.avis.without_answer.count
|
||||
- if avis_counter > 0
|
||||
%span.badge.warning= avis_counter
|
||||
|
||||
|
|
|
@ -320,8 +320,6 @@ Rails.application.routes.draw do
|
|||
#
|
||||
|
||||
scope module: 'instructeurs', as: 'instructeur' do
|
||||
get 'avis', to: 'avis#index', as: 'all_avis'
|
||||
|
||||
# this redirections are ephemeral, to ensure that emails sent to experts before are still valid
|
||||
# TODO : they will be removed in September, 2020
|
||||
get 'avis/:id', to: redirect('/procedures/old/avis/%{id}')
|
||||
|
@ -339,12 +337,8 @@ Rails.application.routes.draw do
|
|||
resources :avis, only: [:show, :update] do
|
||||
get '', action: 'procedure', on: :collection, as: :procedure
|
||||
member do
|
||||
get 'messagerie'
|
||||
post 'commentaire' => 'avis#create_commentaire'
|
||||
post 'avis' => 'avis#create_avis'
|
||||
patch 'revoquer'
|
||||
get 'revive'
|
||||
get 'bilans_bdf'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ ActiveRecord::Schema.define(version: 2021_03_11_141956) do
|
|||
t.datetime "revoked_at"
|
||||
t.bigint "experts_procedure_id"
|
||||
t.string "claimant_type"
|
||||
t.boolean "tmp_expert_migrated", default: false
|
||||
t.boolean "tmp_expert_migrated"
|
||||
t.index ["claimant_id"], name: "index_avis_on_claimant_id"
|
||||
t.index ["dossier_id"], name: "index_avis_on_dossier_id"
|
||||
t.index ["experts_procedure_id"], name: "index_avis_on_experts_procedure_id"
|
||||
|
|
|
@ -345,9 +345,9 @@ describe Dossier do
|
|||
end
|
||||
|
||||
context 'when they are a lot of advice' do
|
||||
let!(:avis_1) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010'), tmp_expert_migrated: true) }
|
||||
let!(:avis_2) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010'), tmp_expert_migrated: true) }
|
||||
let!(:avis_3) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010'), tmp_expert_migrated: true) }
|
||||
let!(:avis_1) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010')) }
|
||||
let!(:avis_2) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010')) }
|
||||
let!(:avis_3) { create(:avis, dossier: dossier, claimant: expert_1, experts_procedure: experts_procedure_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010')) }
|
||||
|
||||
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis_2, avis_1, avis_3]) }
|
||||
it { expect(dossier.avis_for_expert(expert_1)).to match([avis_2, avis_1, avis_3]) }
|
||||
|
|
Loading…
Reference in a new issue