Merge pull request #2098 from betagouv/fred/support_tooling
Support script to change procedure ownership
This commit is contained in:
commit
f614e88a99
2 changed files with 40 additions and 0 deletions
|
@ -134,6 +134,12 @@ Une fois `overmind` lancé, et un breakpoint `byebug` inséré dans le code, il
|
|||
- supprimer un compte super admin :
|
||||
`bin/rake admin:delete_admin[email-du-compte-github@exemple.com]`
|
||||
|
||||
|
||||
## Tâches d’aide au support
|
||||
|
||||
Des tâches d’aide au support sont prévues dans le namespace `support`.
|
||||
Pour les lister: `bin/rake -D support:`.
|
||||
|
||||
## Compatibilité navigateurs
|
||||
|
||||
L'application supporte les navigateurs récents Firefox, Chrome, Internet Explorer (Edge, 11).
|
||||
|
|
34
lib/tasks/support.rake
Normal file
34
lib/tasks/support.rake
Normal file
|
@ -0,0 +1,34 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :support do
|
||||
desc <<~EOD
|
||||
Give procedure #PROCEDURE_ID a new owner.
|
||||
The owner can be specified with NEW_OWNER_ID or NEW_OWNER_MAIL.
|
||||
EOD
|
||||
task transfer_procedure_ownership: :environment do
|
||||
new_owner_id = ENV['NEW_OWNER_ID']
|
||||
new_owner_mail = ENV['NEW_OWNER_MAIL']
|
||||
|
||||
new_owner = nil
|
||||
if new_owner_id.present?
|
||||
new_owner = Administrateur.find(new_owner_id)
|
||||
elsif new_owner_mail.present?
|
||||
new_owner = Administrateur.find_by(email: new_owner_mail)
|
||||
end
|
||||
|
||||
if new_owner.blank?
|
||||
fail "Must specify a new owner"
|
||||
end
|
||||
|
||||
procedure_id = ENV['PROCEDURE_ID']
|
||||
procedure = Procedure.find(procedure_id)
|
||||
|
||||
rake_puts("Changing owner of procedure ##{procedure_id} from ##{procedure.administrateur_id} to ##{new_owner.id}")
|
||||
procedure.update(administrateur: new_owner)
|
||||
|
||||
ProcedurePath.where(procedure_id: procedure_id).each do |pp|
|
||||
rake_puts("Changing owner of procedure_path #{pp.path} from ##{pp.administrateur_id} to ##{new_owner.id}")
|
||||
pp.update(administrateur: new_owner)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue