From ea2827134e8a6bec4cafd80bbcae174ab0b9e7b6 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 18 Oct 2017 14:29:12 +0200 Subject: [PATCH] [fix #850] Use UUID as a uniq identifier for the attestation --- app/uploaders/attestation_uploader.rb | 10 ++++++++++ ...5_add_content_secure_token_column_to_attestation.rb | 5 +++++ db/schema.rb | 9 +++++---- spec/models/attestation_template_spec.rb | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20171019085515_add_content_secure_token_column_to_attestation.rb diff --git a/app/uploaders/attestation_uploader.rb b/app/uploaders/attestation_uploader.rb index 2697d330a..c00d523cd 100644 --- a/app/uploaders/attestation_uploader.rb +++ b/app/uploaders/attestation_uploader.rb @@ -17,4 +17,14 @@ class AttestationUploader < BaseUploader "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end + + def filename + "attestation-#{secure_token}.pdf" + end + + private + + def secure_token + model.content_secure_token ||= SecureRandom.uuid + end end diff --git a/db/migrate/20171019085515_add_content_secure_token_column_to_attestation.rb b/db/migrate/20171019085515_add_content_secure_token_column_to_attestation.rb new file mode 100644 index 000000000..8b5f8821f --- /dev/null +++ b/db/migrate/20171019085515_add_content_secure_token_column_to_attestation.rb @@ -0,0 +1,5 @@ +class AddContentSecureTokenColumnToAttestation < ActiveRecord::Migration[5.0] + def change + add_column :attestations, :content_secure_token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index f08c3a1c4..92b37cf27 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.define(version: 20170927092716) do +ActiveRecord::Schema.define(version: 20171019085515) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -87,9 +87,10 @@ ActiveRecord::Schema.define(version: 20170927092716) do create_table "attestations", force: :cascade do |t| t.string "pdf" t.string "title" - t.integer "dossier_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "dossier_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "content_secure_token" t.index ["dossier_id"], name: "index_attestations_on_dossier_id", using: :btree end diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index 4f0768d54..210871dc5 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -142,7 +142,7 @@ describe AttestationTemplate, type: :model do it 'provides a pseudo file' do expect(attestation.pdf.file).to exist - expect(attestation.pdf.filename).to eq('attestation') + expect(attestation.pdf.filename).to start_with('attestation') end context 'when the dossier and the procedure has an individual' do