Cleanup demarche archivee state

This commit is contained in:
Paul Chavard 2019-12-18 13:28:29 +01:00
parent 4527124755
commit fa2eea81aa
6 changed files with 17 additions and 22 deletions

View file

@ -10,7 +10,7 @@ module Instructeurs
.procedures
.with_attached_logo
.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_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) }
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)) }

View file

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

View file

@ -32,8 +32,7 @@ class ProcedureSerializer < ActiveModel::Serializer
end
def state
state = object.aasm_state
state == 'close' ? 'archivee' : state
object.aasm_state
end
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.
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
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 ["hidden_at"], name: "index_procedures_on_hidden_at"
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"
end