diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 20474f1cf..9e5f8628d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -223,7 +223,7 @@ class Dossier < ApplicationRecord scope :prefilled, -> { where(prefilled: true) } scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) } scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) } - scope :visible_by_user, -> { where(for_procedure_preview: false).or(where(for_procedure_preview: nil)).where(hidden_by_user_at: nil, editing_fork_origin_id: nil) } + scope :visible_by_user, -> { where(for_procedure_preview: false).where(hidden_by_user_at: nil, editing_fork_origin_id: nil) } scope :visible_by_administration, -> { state_not_brouillon .where(hidden_by_administration_at: nil) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0eba2e718..25bb06d75 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -709,7 +709,7 @@ class Procedure < ApplicationRecord close! end - dossiers.visible_by_administration.each do |dossier| + dossiers.visible_by_administration.find_each do |dossier| dossier.hide_and_keep_track!(author, :procedure_removed) end diff --git a/app/models/stat.rb b/app/models/stat.rb index 06dec2a55..9ce8744b6 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -32,7 +32,7 @@ class Stat < ApplicationRecord COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon", COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours", COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours", - COUNT(*) FILTER ( WHERE state = 'brouillon' AND editing_fork_origin_id IS NULL AND (for_procedure_preview IS NULL OR for_procedure_preview = false)) AS "brouillon", + COUNT(*) FILTER ( WHERE state = 'brouillon' AND editing_fork_origin_id IS NULL AND for_procedure_preview = false) AS "brouillon", COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction", COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction", COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines" diff --git a/db/migrate/20231110135532_alter_dossiers_for_procedure_preview_not_nullable.rb b/db/migrate/20231110135532_alter_dossiers_for_procedure_preview_not_nullable.rb new file mode 100644 index 000000000..edcce0a7b --- /dev/null +++ b/db/migrate/20231110135532_alter_dossiers_for_procedure_preview_not_nullable.rb @@ -0,0 +1,5 @@ +class AlterDossiersForProcedurePreviewNotNullable < ActiveRecord::Migration[7.0] + def change + add_check_constraint :dossiers, "for_procedure_preview IS NOT NULL", name: "dossiers_for_procedure_preview_null", validate: false + end +end diff --git a/db/migrate/20231110135533_validate_alter_dossiers_for_procedure_preview_not_nullable.rb b/db/migrate/20231110135533_validate_alter_dossiers_for_procedure_preview_not_nullable.rb new file mode 100644 index 000000000..d08246025 --- /dev/null +++ b/db/migrate/20231110135533_validate_alter_dossiers_for_procedure_preview_not_nullable.rb @@ -0,0 +1,7 @@ +class ValidateAlterDossiersForProcedurePreviewNotNullable < ActiveRecord::Migration[7.0] + def change + validate_check_constraint :dossiers, name: "dossiers_for_procedure_preview_null" + change_column_null :dossiers, :for_procedure_preview, false, false + remove_check_constraint :dossiers, name: "dossiers_for_procedure_preview_null" + end +end diff --git a/db/schema.rb b/db/schema.rb index adcff1293..9c4e8f408 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_07_150217) do +ActiveRecord::Schema[7.0].define(version: 2023_11_10_135533) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -402,7 +402,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_07_150217) do t.datetime "en_construction_at", precision: 6 t.datetime "en_construction_close_to_expiration_notice_sent_at", precision: 6 t.datetime "en_instruction_at", precision: 6 - t.boolean "for_procedure_preview", default: false + t.boolean "for_procedure_preview", default: false, null: false t.boolean "forced_groupe_instructeur", default: false, null: false t.bigint "groupe_instructeur_id" t.datetime "groupe_instructeur_updated_at", precision: 6 diff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rb index 66332df21..049254dda 100644 --- a/spec/models/stat_spec.rb +++ b/spec/models/stat_spec.rb @@ -27,7 +27,6 @@ describe Stat, type: :model do create_list(:dossier, 2, :en_construction, depose_at: 10.days.ago, procedure:) create_list(:dossier, 3, :en_construction, depose_at: 40.days.ago, procedure:) - create_list(:dossier, 3, :brouillon, procedure:, for_procedure_preview: nil) create_list(:dossier, 1, :brouillon, procedure:, for_procedure_preview: false) create_list(:dossier, 6, :en_instruction, procedure:) @@ -48,7 +47,7 @@ describe Stat, type: :model do expect(stats["not_brouillon"]).to eq(18) expect(stats["dossiers_depose_avant_30_jours"]).to eq(2) expect(stats["dossiers_deposes_entre_60_et_30_jours"]).to eq(3) - expect(stats["brouillon"]).to eq(4) + expect(stats["brouillon"]).to eq(1) expect(stats["en_construction"]).to eq(5) expect(stats["en_instruction"]).to eq(6) expect(stats["termines"]).to eq(7)