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
|
end
|
||||||
|
|
||||||
order = ORDER_DIRECTIONS.fetch(params[:order], :asc)
|
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
|
rescue ActiveRecord::RecordNotFound
|
||||||
render json: {}, status: :not_found
|
render json: {}, status: :not_found
|
||||||
|
|
|
@ -72,7 +72,10 @@ module Types
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:)
|
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?
|
if state.present?
|
||||||
dossiers = dossiers.where(state: state)
|
dossiers = dossiers.where(state: state)
|
||||||
|
|
|
@ -10,7 +10,10 @@ module Types
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossiers(updated_since: nil, created_since: nil, state: nil, order:)
|
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?
|
if state.present?
|
||||||
dossiers = dossiers.where(state: state)
|
dossiers = dossiers.where(state: state)
|
||||||
|
|
|
@ -213,6 +213,7 @@ class Dossier < ApplicationRecord
|
||||||
.where(hidden_by_administration_at: nil)
|
.where(hidden_by_administration_at: nil)
|
||||||
.merge(visible_by_user.or(state_not_en_construction))
|
.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_updated_at, -> (order = :desc) { order(updated_at: order) }
|
||||||
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: 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
|
end
|
||||||
|
|
||||||
scope :interval_brouillon_close_to_expiration, -> do
|
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
|
end
|
||||||
scope :interval_en_construction_close_to_expiration, -> do
|
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
|
end
|
||||||
scope :interval_termine_close_to_expiration, -> do
|
scope :interval_termine_close_to_expiration, -> do
|
||||||
state_termine
|
state_termine
|
||||||
|
.visible_by_user_or_administration
|
||||||
.where(procedures: { procedure_expires_when_termine_enabled: true })
|
.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 })
|
.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
|
end
|
||||||
|
@ -336,14 +342,17 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
scope :brouillon_expired, -> do
|
scope :brouillon_expired, -> do
|
||||||
state_brouillon
|
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 })
|
.where("brouillon_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :en_construction_expired, -> do
|
scope :en_construction_expired, -> do
|
||||||
state_en_construction
|
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 })
|
.where("en_construction_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :termine_expired, -> do
|
scope :termine_expired, -> do
|
||||||
state_termine
|
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 })
|
.where("termine_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_EXPIRATION })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -361,11 +370,13 @@ class Dossier < ApplicationRecord
|
||||||
# select users who have submitted dossier for the given 'procedures.id'
|
# select users who have submitted dossier for the given 'procedures.id'
|
||||||
users_who_submitted =
|
users_who_submitted =
|
||||||
state_not_brouillon
|
state_not_brouillon
|
||||||
|
.visible_by_user
|
||||||
.joins(:revision)
|
.joins(:revision)
|
||||||
.where("procedure_revisions.procedure_id = procedures.id")
|
.where("procedure_revisions.procedure_id = procedures.id")
|
||||||
.select(:user_id)
|
.select(:user_id)
|
||||||
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
|
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
|
||||||
state_brouillon
|
state_brouillon
|
||||||
|
.visible_by_user
|
||||||
.with_notifiable_procedure
|
.with_notifiable_procedure
|
||||||
.where("procedures.auto_archive_on - INTERVAL :before_closing = :now", { now: Time.zone.today, before_closing: INTERVAL_BEFORE_CLOSING })
|
.where("procedures.auto_archive_on - INTERVAL :before_closing = :now", { now: Time.zone.today, before_closing: INTERVAL_BEFORE_CLOSING })
|
||||||
.where.not(user: users_who_submitted)
|
.where.not(user: users_who_submitted)
|
||||||
|
|
|
@ -161,6 +161,7 @@ class Instructeur < ApplicationRecord
|
||||||
groupe_instructeur_ids = Dossier
|
groupe_instructeur_ids = Dossier
|
||||||
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
||||||
.merge(followed_dossiers)
|
.merge(followed_dossiers)
|
||||||
|
.visible_by_administration
|
||||||
.with_notifications
|
.with_notifications
|
||||||
.select(:groupe_instructeur_id)
|
.select(:groupe_instructeur_id)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue