Use secure token to create attachment links

The link is public but protected by a secure token.

This extends the activesupport Attachment model to automatically
generate a token
This commit is contained in:
2020-04-12 23:47:56 +02:00
parent ad317e917d
commit 73c184a4a0
5 changed files with 14 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
class AddTokenToAttachments < ActiveRecord::Migration[6.0]
def change
add_column :active_storage_attachments, :token, :string
add_index :active_storage_attachments, :token, unique: true
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_12_165834) do
ActiveRecord::Schema.define(version: 2020_04_12_214304) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -21,8 +21,10 @@ ActiveRecord::Schema.define(version: 2020_04_12_165834) do
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.string "token"
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
t.index ["token"], name: "index_active_storage_attachments_on_token", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|