From a171ebb77289b4ffa0b28b4c41d037f183127b46 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Mar 2022 11:48:19 +0200 Subject: [PATCH 1/4] fix(dossiers): exclude deleted dossiers from notifications --- app/models/instructeur.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index 570f5c220..6c74b242c 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -161,6 +161,7 @@ class Instructeur < ApplicationRecord groupe_instructeur_ids = Dossier .send(scope) # :en_cours or :termine (or any other Dossier scope) .merge(followed_dossiers) + .visible_by_administration .with_notifications .select(:groupe_instructeur_id) From c2812a7633543f2fad7ec4d435deccfa0c105b30 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Mar 2022 17:21:31 +0200 Subject: [PATCH 2/4] fix(api): hide deleted dossiers --- app/controllers/api/v1/dossiers_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 222e786dd..694d7fa80 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -53,7 +53,10 @@ class API::V1::DossiersController < APIController end order = ORDER_DIRECTIONS.fetch(params[:order], :asc) - @dossiers = @procedure.dossiers.state_not_brouillon.order_by_created_at(order) + @dossiers = @procedure + .dossiers + .visible_by_administration + .order_by_created_at(order) rescue ActiveRecord::RecordNotFound render json: {}, status: :not_found From 5bafc9122097bf058890283437fa7591c5262f3c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Mar 2022 17:22:39 +0200 Subject: [PATCH 3/4] fix(graphql): hide deleted dossiers --- app/graphql/types/demarche_type.rb | 5 ++++- app/graphql/types/groupe_instructeur_with_dossiers_type.rb | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/graphql/types/demarche_type.rb b/app/graphql/types/demarche_type.rb index 4c69ea966..adb9eaf84 100644 --- a/app/graphql/types/demarche_type.rb +++ b/app/graphql/types/demarche_type.rb @@ -72,7 +72,10 @@ module Types end def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:) - dossiers = object.dossiers.state_not_brouillon.for_api_v2 + dossiers = object + .dossiers + .visible_by_administration + .for_api_v2 if state.present? dossiers = dossiers.where(state: state) diff --git a/app/graphql/types/groupe_instructeur_with_dossiers_type.rb b/app/graphql/types/groupe_instructeur_with_dossiers_type.rb index d8d69e124..1c5675f3f 100644 --- a/app/graphql/types/groupe_instructeur_with_dossiers_type.rb +++ b/app/graphql/types/groupe_instructeur_with_dossiers_type.rb @@ -10,7 +10,10 @@ module Types end def dossiers(updated_since: nil, created_since: nil, state: nil, order:) - dossiers = object.dossiers.state_not_brouillon.for_api_v2 + dossiers = object + .dossiers + .visible_by_administration + .for_api_v2 if state.present? dossiers = dossiers.where(state: state) From 6df18e123410b71c2e31622c07b1c3e87da506b5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Mar 2022 17:24:08 +0200 Subject: [PATCH 4/4] fix(dossier): only expire dossiers visible by user or administration --- app/models/dossier.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 2602fee6d..8bf48e9b8 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -213,6 +213,7 @@ class Dossier < ApplicationRecord .where(hidden_by_administration_at: nil) .merge(visible_by_user.or(state_not_en_construction)) } + scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) } @@ -298,13 +299,18 @@ class Dossier < ApplicationRecord end scope :interval_brouillon_close_to_expiration, -> do - state_brouillon.where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) + state_brouillon + .visible_by_user + .where("dossiers.created_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) end scope :interval_en_construction_close_to_expiration, -> do - state_en_construction.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) + state_en_construction + .visible_by_user_or_administration + .where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) end scope :interval_termine_close_to_expiration, -> do state_termine + .visible_by_user_or_administration .where(procedures: { procedure_expires_when_termine_enabled: true }) .where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION }) end @@ -336,14 +342,17 @@ class Dossier < ApplicationRecord scope :brouillon_expired, -> do state_brouillon + .visible_by_user .where("brouillon_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION }) end scope :en_construction_expired, -> do state_en_construction + .visible_by_user_or_administration .where("en_construction_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION }) end scope :termine_expired, -> do state_termine + .visible_by_user_or_administration .where("termine_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION }) end @@ -361,11 +370,13 @@ class Dossier < ApplicationRecord # select users who have submitted dossier for the given 'procedures.id' users_who_submitted = state_not_brouillon + .visible_by_user .joins(:revision) .where("procedure_revisions.procedure_id = procedures.id") .select(:user_id) # select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier state_brouillon + .visible_by_user .with_notifiable_procedure .where("procedures.auto_archive_on - INTERVAL :before_closing = :now", { now: Time.zone.today, before_closing: INTERVAL_BEFORE_CLOSING }) .where.not(user: users_who_submitted)