models: add a Procedure#with_hidden scope, and remove unscoped usages

This avoids the broad use of `unscoped` to remove the `hidden_at`
clause.
This commit is contained in:
Pierre de La Morinerie 2020-01-28 16:41:15 +01:00
parent 4efea77280
commit 1448d5b098
7 changed files with 28 additions and 6 deletions

View file

@ -12,7 +12,7 @@ namespace :'2017_10_18_regenerate_attestation' do
end
def regenerate_attestations(attestation)
Procedure.unscoped do
Procedure.with_hidden do
Dossier.unscoped do
dossier = attestation.dossier
procedure = dossier.procedure

View file

@ -3,6 +3,6 @@ namespace :'2018_05_15_add_aasm_state_to_procedure' do
Procedure.archivees.update_all(aasm_state: :archivee)
Procedure.publiees.update_all(aasm_state: :publiee)
Procedure.brouillons.update_all(aasm_state: :brouillon)
Procedure.unscoped.where.not(hidden_at: nil).update_all(aasm_state: :hidden)
Procedure.rewhere(hidden_at: nil).update_all(aasm_state: :hidden)
end
end

View file

@ -3,11 +3,11 @@ namespace :after_party do
task create_dummy_paths_for_archived_and_hidden_procedures: :environment do
rake_puts "Running deploy task 'create_dummy_paths_for_archived_procedures'"
Procedure.unscoped.archivees.where(path: nil).each do |p|
Procedure.with_hidden.archivees.where(path: nil).each do |p|
p.update_column(:path, SecureRandom.uuid)
end
Procedure.unscoped.hidden.where(path: nil).each do |p|
Procedure.hidden.where(path: nil).each do |p|
p.update_column(:path, SecureRandom.uuid)
end

View file

@ -2,7 +2,7 @@ namespace :after_party do
desc 'Deployment task: create_default_groupe_instructeur'
task create_default_groupe_instructeur: :environment do
Procedure
.unscoped
.with_hidden
.left_outer_joins(:groupe_instructeurs)
.where('groupe_instructeurs.id is null')
.find_each do |procedure|