Compare commits

...

3 commits

Author SHA1 Message Date
Colin Darie
e61466c3ce
Merge pull request #9213 from colinux/robots-super-admins
Tech (seo): disallow /super_admins/
2023-06-20 09:03:00 +00:00
LeSim
d95dde075c
Merge pull request #9214 from demarches-simplifiees/renew_signed_id_blob_tasks
Outillage: ajout d'une tache qui permet d'invalider des blob signed_ids
2023-06-20 08:49:01 +00:00
simon lehericey
6dd6ddd8c6 tools: add task to renew blob signed_ids 2023-06-20 09:39:57 +02:00

37
lib/tasks/blobs.rake Normal file
View file

@ -0,0 +1,37 @@
namespace :blobs do
desc <<~EOD
given a file blob_ids.json with contains { blob_ids: [...] },
download and reattached champ piece_justificative_file to create new blob
and delete the old one, and thus, invalides old signed_ids.
bin/rails 'blobs:renew_signed_ids[blob_ids.json]'
EOD
task :renew_signed_ids, [:file_path] => :environment do |_t, args|
blob_ids = JSON.parse(File.read(args[:file_path]))['blob_ids']
blobs = ActiveStorage::Blob.find(blob_ids)
blobs.each do |blob|
blob.open do |file|
blob.attachments.each do |attachment|
if [attachment.record_type, attachment.name] != ['Champ', 'piece_justificative_file']
raise "not a piece justificative #{attachment.id}"
end
champ = attachment.record
champ_updated_at = champ.updated_at
dossier = champ.dossier
dossier_updated_at = dossier.updated_at
file.rewind
# badly, it updates champ and dossier updated_at attributes
champ.piece_justificative_file.attach(io: file, filename: blob.filename, content_type: blob.content_type)
# it destroys the blob as well
attachment.destroy
champ.update_column(:updated_at, champ_updated_at)
dossier.update_column(:updated_at, dossier_updated_at)
end
end
end
end
end