Merge pull request #4649 from tchak/cleanup-archive

Cleanup demarche archivee state
This commit is contained in:
Paul Chavard 2020-01-07 11:51:33 +01:00 committed by GitHub
commit 0ef25ef36c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 22 deletions

View file

@ -10,7 +10,7 @@ module Instructeurs
.procedures .procedures
.with_attached_logo .with_attached_logo
.includes(:defaut_groupe_instructeur) .includes(:defaut_groupe_instructeur)
.order(closed_at: :desc, archived_at: :desc, unpublished_at: :desc, published_at: :desc, created_at: :desc) .order(closed_at: :desc, unpublished_at: :desc, published_at: :desc, created_at: :desc)
dossiers = current_instructeur.dossiers.joins(:groupe_instructeur) dossiers = current_instructeur.dossiers.joins(:groupe_instructeur)
@dossiers_count_per_procedure = dossiers.all_state.group('groupe_instructeurs.procedure_id').reorder(nil).count @dossiers_count_per_procedure = dossiers.all_state.group('groupe_instructeurs.procedure_id').reorder(nil).count

View file

@ -14,7 +14,7 @@ class Administrateur < ApplicationRecord
before_validation -> { sanitize_email(:email) } before_validation -> { sanitize_email(:email) }
scope :inactive, -> { joins(:user).where(users: { last_sign_in_at: nil }) } scope :inactive, -> { joins(:user).where(users: { last_sign_in_at: nil }) }
scope :with_publiees_ou_closes, -> { joins(:procedures).where(procedures: { aasm_state: [:publiee, :archivee, :close, :depubliee] }) } scope :with_publiees_ou_closes, -> { joins(:procedures).where(procedures: { aasm_state: [:publiee, :close, :depubliee] }) }
# validate :password_complexity, if: Proc.new { |a| Devise.password_length.include?(a.password.try(:size)) } # validate :password_complexity, if: Proc.new { |a| Devise.password_length.include?(a.password.try(:size)) }

View file

@ -1,7 +1,7 @@
require Rails.root.join('lib', 'percentile') require Rails.root.join('lib', 'percentile')
class Procedure < ApplicationRecord class Procedure < ApplicationRecord
self.ignored_columns = ['logo', 'logo_secure_token', 'test_started_at'] self.ignored_columns = ['archived_at']
include ProcedureStatsConcern include ProcedureStatsConcern
@ -46,8 +46,8 @@ class Procedure < ApplicationRecord
default_scope { where(hidden_at: nil) } default_scope { where(hidden_at: nil) }
scope :brouillons, -> { where(aasm_state: :brouillon) } scope :brouillons, -> { where(aasm_state: :brouillon) }
scope :publiees, -> { where(aasm_state: :publiee) } scope :publiees, -> { where(aasm_state: :publiee) }
scope :closes, -> { where(aasm_state: [:archivee, :close, :depubliee]) } scope :closes, -> { where(aasm_state: [:close, :depubliee]) }
scope :publiees_ou_closes, -> { where(aasm_state: [:publiee, :close, :archivee, :depubliee]) } scope :publiees_ou_closes, -> { where(aasm_state: [:publiee, :close, :depubliee]) }
scope :by_libelle, -> { order(libelle: :asc) } scope :by_libelle, -> { order(libelle: :asc) }
scope :created_during, -> (range) { where(created_at: range) } scope :created_during, -> (range) { where(created_at: range) }
scope :cloned_from_library, -> { where(cloned_from_library: true) } scope :cloned_from_library, -> { where(cloned_from_library: true) }
@ -233,9 +233,8 @@ class Procedure < ApplicationRecord
end end
def validate_for_publication def validate_for_publication
old_attributes = self.slice(:aasm_state, :archived_at, :closed_at) old_attributes = self.slice(:aasm_state, :closed_at)
self.aasm_state = :publiee self.aasm_state = :publiee
self.archived_at = nil
self.closed_at = nil self.closed_at = nil
is_valid = validate is_valid = validate
@ -279,14 +278,6 @@ class Procedure < ApplicationRecord
update(csv_export_queued: false, xlsx_export_queued: false, ods_export_queued: false) update(csv_export_queued: false, xlsx_export_queued: false, ods_export_queued: false)
end end
def closed_at
read_attribute(:closed_at).presence || archived_at
end
def close?
aasm_state == 'close' || aasm_state == 'archivee'
end
def locked? def locked?
publiee? || close? || depubliee? publiee? || close? || depubliee?
end end
@ -383,7 +374,6 @@ class Procedure < ApplicationRecord
}, &method(:clone_attachments)) }, &method(:clone_attachments))
procedure.path = SecureRandom.uuid procedure.path = SecureRandom.uuid
procedure.aasm_state = :brouillon procedure.aasm_state = :brouillon
procedure.archived_at = nil
procedure.closed_at = nil procedure.closed_at = nil
procedure.unpublished_at = nil procedure.unpublished_at = nil
procedure.published_at = nil procedure.published_at = nil
@ -622,7 +612,7 @@ class Procedure < ApplicationRecord
end end
def before_publish def before_publish
update!(archived_at: nil, closed_at: nil, unpublished_at: nil) update!(closed_at: nil, unpublished_at: nil)
end end
def after_publish def after_publish
@ -631,7 +621,7 @@ class Procedure < ApplicationRecord
def after_close def after_close
now = Time.zone.now now = Time.zone.now
update!(archived_at: now, closed_at: now) update!(closed_at: now)
purge_export_files purge_export_files
end end

View file

@ -32,8 +32,7 @@ class ProcedureSerializer < ActiveModel::Serializer
end end
def state def state
state = object.aasm_state object.aasm_state
state == 'close' ? 'archivee' : state
end end
def geographic_information def geographic_information

View file

@ -0,0 +1,6 @@
class AddProceduresPathClosedAtHiddenAtIndex < ActiveRecord::Migration[5.2]
def change
add_index :procedures, [:path, :closed_at, :hidden_at], unique: true
remove_index :procedures, [:path, :archived_at, :hidden_at]
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_11_113341) do ActiveRecord::Schema.define(version: 2019_12_18_103727) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -505,7 +505,7 @@ ActiveRecord::Schema.define(version: 2019_12_11_113341) do
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state" t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at" t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id" t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
t.index ["path", "archived_at", "hidden_at"], name: "index_procedures_on_path_and_archived_at_and_hidden_at", unique: true t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true
t.index ["service_id"], name: "index_procedures_on_service_id" t.index ["service_id"], name: "index_procedures_on_service_id"
end end