From d881b9242c749c1dde5aebbf9eb73bb58af7f1cb Mon Sep 17 00:00:00 2001 From: Mikhael Rakauskas Date: Thu, 3 Jul 2025 16:28:59 -0400 Subject: [PATCH] misc id changes --- app/controllers/api/submissions_controller.rb | 2 +- app/controllers/api/templates_controller.rb | 7 ++++--- app/controllers/templates_controller.rb | 7 ++++--- app/models/template.rb | 10 +++------- ...0703143236_add_external_data_fields_to_templates.rb | 2 +- db/schema.rb | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/controllers/api/submissions_controller.rb b/app/controllers/api/submissions_controller.rb index af784ba2..1bef7f4e 100644 --- a/app/controllers/api/submissions_controller.rb +++ b/app/controllers/api/submissions_controller.rb @@ -193,7 +193,7 @@ module Api submitters: [[:send_email, :send_sms, :completed_redirect_url, :uuid, :name, :email, :role, :completed, :phone, :application_key, :external_id, :reply_to, :go_to_last, { metadata: {}, values: {}, roles: [], readonly_fields: [], message: %i[subject body], - fields: [:name, :uuid, :default_value, :value, :title, :description, + fields: [:name, :uuid, :question_id, :default_value, :value, :title, :description, :readonly, :required, :validation_pattern, :invalid_message, { default_value: [], value: [], preferences: {} }] }]] } diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index 2af022e7..5262fe04 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -109,15 +109,16 @@ module Api :external_id, :shared_link, { + external_data_fields: {}, submitters: [%i[name uuid is_requester invite_by_uuid optional_invite_by_uuid linked_to_uuid email]], - fields: [[:uuid, :submitter_uuid, :name, :type, + fields: [[:uuid, :question_id, :submitter_uuid, :name, :type, :required, :readonly, :default_value, :title, :description, { preferences: {}, conditions: [%i[field_uuid value action operation]], - options: [%i[value uuid]], + options: [%i[value uuid answer_id]], validation: %i[message pattern], - areas: [%i[x y w h cell_w attachment_uuid option_uuid page]] }]] + areas: [%i[x y w h cell_w attachment_uuid option_uuid answer_id page]] }]] } ] diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 14b36709..2828ce58 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -121,14 +121,15 @@ class TemplatesController < ApplicationController :name, { schema: [[:attachment_uuid, :name, { conditions: [%i[field_uuid value action operation]] }]], submitters: [%i[name uuid is_requester linked_to_uuid invite_by_uuid optional_invite_by_uuid email]], - fields: [[:uuid, :submitter_uuid, :name, :type, + external_data_fields: {}, + fields: [[:uuid, :question_id, :submitter_uuid, :name, :type, :required, :readonly, :default_value, :title, :description, { preferences: {}, conditions: [%i[field_uuid value action operation]], - options: [%i[value uuid]], + options: [%i[value uuid answer_id]], validation: %i[message pattern], - areas: [%i[x y w h cell_w attachment_uuid option_uuid page]] }]] } + areas: [%i[x y w h cell_w attachment_uuid option_uuid answer_id page]] }]] } ) end diff --git a/app/models/template.rb b/app/models/template.rb index 73c54313..a2d7fd19 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -6,7 +6,7 @@ # # id :bigint not null, primary key # archived_at :datetime -# external_data_fields :string +# external_data_fields :text # fields :text not null # name :string not null # preferences :text not null @@ -52,6 +52,7 @@ class Template < ApplicationRecord attribute :preferences, :string, default: -> { {} } attribute :fields, :string, default: -> { [] } attribute :schema, :string, default: -> { [] } + attribute :external_data_fields, :string, default: -> { {} } attribute :submitters, :string, default: -> { [{ name: I18n.t(:first_party), uuid: SecureRandom.uuid }] } attribute :slug, :string, default: -> { SecureRandom.base58(14) } attribute :source, :string, default: 'native' @@ -60,6 +61,7 @@ class Template < ApplicationRecord serialize :fields, coder: JSON serialize :schema, coder: JSON serialize :submitters, coder: JSON + serialize :external_data_fields, coder: JSON has_many_attached :documents @@ -79,12 +81,6 @@ class Template < ApplicationRecord external_id end - def external_data_fields - return {} if self[:external_data_fields].blank? - - JSON.parse(self[:external_data_fields]) - end - private def maybe_set_default_folder diff --git a/db/migrate/20250703143236_add_external_data_fields_to_templates.rb b/db/migrate/20250703143236_add_external_data_fields_to_templates.rb index f286278c..75861b27 100644 --- a/db/migrate/20250703143236_add_external_data_fields_to_templates.rb +++ b/db/migrate/20250703143236_add_external_data_fields_to_templates.rb @@ -1,5 +1,5 @@ class AddExternalDataFieldsToTemplates < ActiveRecord::Migration[8.0] def change - add_column :templates, :external_data_fields, :string + add_column :templates, :external_data_fields, :text end end diff --git a/db/schema.rb b/db/schema.rb index d2f8780d..9a97cf4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -393,7 +393,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_03_143236) do t.string "external_id" t.text "preferences", null: false t.boolean "shared_link", default: false, null: false - t.string "external_data_fields" + t.text "external_data_fields" t.index ["account_id", "folder_id", "id"], name: "index_templates_on_account_id_and_folder_id_and_id", where: "(archived_at IS NULL)" t.index ["account_id", "id"], name: "index_templates_on_account_id_and_id_archived", where: "(archived_at IS NOT NULL)" t.index ["account_id"], name: "index_templates_on_account_id"