diff --git a/Gemfile b/Gemfile index 5de7f90..89aacd4 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ gem 'aws-sdk-s3', require: false gem 'google-api-client' gem 'rack-cors' gem 'sentry-raven' +gem 'sequenced' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index eabe759..329a9b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,6 +197,9 @@ GEM semantic_range (2.3.0) sentry-raven (3.0.0) faraday (>= 1.0) + sequenced (3.2.0) + activerecord (>= 3.0) + activesupport (>= 3.0) signet (0.14.0) addressable (~> 2.3) faraday (>= 0.17.3, < 2.0) @@ -250,6 +253,7 @@ DEPENDENCIES rails sass-rails sentry-raven + sequenced spring spring-watcher-listen turbolinks diff --git a/app/models/submission.rb b/app/models/submission.rb index 899469c..f0e0349 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -2,6 +2,8 @@ class Submission < ApplicationRecord belongs_to :form has_many_attached :files + acts_as_sequenced scope: :form_id + validates_presence_of :data, if: :appended_at? def process_data(submitted_data) @@ -21,6 +23,10 @@ class Submission < ApplicationRecord JSON.dump(value) when 'tinyforms_now' Time.now.utc.to_formatted_s(:rfc822) + when 'tinyforms_token' + form.token + when 'tinyforms_id' + sequential_id when ActionDispatch::Http::UploadedFile # manually create the ActiveStorage attachment because we need the ID of the Attachment to create the URL # first the file needs to be uplaoded then we can create an Attachment diff --git a/db/migrate/20200412165834_add_sequential_id_to_submissions.rb b/db/migrate/20200412165834_add_sequential_id_to_submissions.rb new file mode 100644 index 0000000..5b9c899 --- /dev/null +++ b/db/migrate/20200412165834_add_sequential_id_to_submissions.rb @@ -0,0 +1,5 @@ +class AddSequentialIdToSubmissions < ActiveRecord::Migration[6.0] + def change + add_column :submissions, :sequential_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e875ea..a55b127 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: 2020_04_09_001610) do +ActiveRecord::Schema.define(version: 2020_04_12_165834) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -63,6 +63,7 @@ ActiveRecord::Schema.define(version: 2020_04_09_001610) do t.datetime "updated_at", precision: 6, null: false t.string "remote_ip" t.string "referrer" + t.integer "sequential_id" end create_table "users", force: :cascade do |t|