Merge pull request #7093 from tchak/fix-deleted-notifications
Corrige la visibilité des dossiers
This commit is contained in:
commit
1db5503500
5 changed files with 26 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue