Revert "Export de tous les dossier d'une démarche"
This commit is contained in:
parent
4f79c0315d
commit
d9a588b52e
32 changed files with 36 additions and 675 deletions
|
@ -1,71 +0,0 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: archives
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# key :text not null
|
||||
# month :date
|
||||
# status :string not null
|
||||
# time_span_type :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class Archive < ApplicationRecord
|
||||
include AASM
|
||||
|
||||
RETENTION_DURATION = 1.week
|
||||
|
||||
has_and_belongs_to_many :groupe_instructeurs
|
||||
|
||||
has_one_attached :file
|
||||
|
||||
scope :stale, -> { where('updated_at < ?', (Time.zone.now - RETENTION_DURATION)) }
|
||||
scope :for_groupe_instructeur, -> (groupe_instructeur) {
|
||||
joins(:archives_groupe_instructeurs)
|
||||
.where(
|
||||
archives_groupe_instructeurs: { groupe_instructeur: groupe_instructeur }
|
||||
)
|
||||
}
|
||||
|
||||
enum time_span_type: {
|
||||
everything: 'everything',
|
||||
monthly: 'monthly'
|
||||
}
|
||||
|
||||
enum status: {
|
||||
pending: 'pending',
|
||||
generated: 'generated'
|
||||
}
|
||||
|
||||
aasm whiny_persistence: true, column: :status, enum: true do
|
||||
state :pending, initial: true
|
||||
state :generated
|
||||
|
||||
event :make_available do
|
||||
transitions from: :pending, to: :generated
|
||||
end
|
||||
end
|
||||
|
||||
def available?
|
||||
status == 'generated' && file.attached?
|
||||
end
|
||||
|
||||
def filename(procedure)
|
||||
if time_span_type == 'everything'
|
||||
"procedure-#{procedure.id}.zip"
|
||||
else
|
||||
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_or_create_archive(time_span_type, month, groupe_instructeurs)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs)
|
||||
.create_or_find_by(time_span_type: time_span_type, month: month, key: generate_cache_key(groupe_instructeurs))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.generate_cache_key(groupe_instructeurs)
|
||||
groupe_instructeurs.map(&:id).sort.join('-')
|
||||
end
|
||||
end
|
|
@ -172,12 +172,7 @@ class Dossier < ApplicationRecord
|
|||
scope :en_construction, -> { not_archived.state_en_construction }
|
||||
scope :en_instruction, -> { not_archived.state_en_instruction }
|
||||
scope :termine, -> { not_archived.state_termine }
|
||||
scope :processed_in_month, -> (month) do
|
||||
state_termine
|
||||
.joins(:traitements)
|
||||
.where(traitements: { processed_at: month.beginning_of_month..month.end_of_month })
|
||||
end
|
||||
scope :downloadable_sorted, -> {
|
||||
scope :downloadable_sorted, -> {
|
||||
state_not_brouillon
|
||||
.includes(
|
||||
:user,
|
||||
|
|
|
@ -25,7 +25,6 @@ class Instructeur < ApplicationRecord
|
|||
has_many :followed_dossiers, through: :follows, source: :dossier
|
||||
has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier
|
||||
has_many :trusted_device_tokens, dependent: :destroy
|
||||
has_many :archives
|
||||
|
||||
has_one :user, dependent: :nullify
|
||||
|
||||
|
|
|
@ -156,20 +156,6 @@ class Procedure < ApplicationRecord
|
|||
includes(:draft_revision, :published_revision, administrateurs: :user)
|
||||
}
|
||||
|
||||
scope :for_download, -> {
|
||||
includes(
|
||||
:groupe_instructeurs,
|
||||
dossiers: {
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
]
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :administrateurs, presence: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue