mirror of
https://github.com/docusealco/docuseal.git
synced 2026-06-23 04:10:11 +00:00
add template variables
This commit is contained in:
@@ -184,6 +184,7 @@ module Api
|
||||
:send_email, :send_sms, :bcc_completed, :completed_redirect_url, :reply_to, :go_to_last,
|
||||
:require_phone_2fa, :expire_at, :name,
|
||||
{
|
||||
variables: {},
|
||||
message: %i[subject body],
|
||||
submitters: [[:send_email, :send_sms, :completed_redirect_url, :uuid, :name, :email, :role,
|
||||
:completed, :phone, :application_key, :external_id, :reply_to, :go_to_last,
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# template_fields :text
|
||||
# template_schema :text
|
||||
# template_submitters :text
|
||||
# variables :text
|
||||
# variables_schema :text
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
@@ -50,6 +52,8 @@ class Submission < ApplicationRecord
|
||||
serialize :template_fields, coder: JSON
|
||||
serialize :template_schema, coder: JSON
|
||||
serialize :template_submitters, coder: JSON
|
||||
serialize :variables_schema, coder: JSON
|
||||
serialize :variables, coder: JSON
|
||||
serialize :preferences, coder: JSON
|
||||
|
||||
attribute :source, :string, default: 'link'
|
||||
|
||||
+18
-16
@@ -4,22 +4,23 @@
|
||||
#
|
||||
# Table name: templates
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# archived_at :datetime
|
||||
# fields :text not null
|
||||
# name :string not null
|
||||
# preferences :text not null
|
||||
# schema :text not null
|
||||
# shared_link :boolean default(FALSE), not null
|
||||
# slug :string not null
|
||||
# source :text not null
|
||||
# submitters :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# author_id :bigint not null
|
||||
# external_id :string
|
||||
# folder_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# archived_at :datetime
|
||||
# fields :text not null
|
||||
# name :string not null
|
||||
# preferences :text not null
|
||||
# schema :text not null
|
||||
# shared_link :boolean default(FALSE), not null
|
||||
# slug :string not null
|
||||
# source :text not null
|
||||
# submitters :text not null
|
||||
# variables_schema :text
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# author_id :bigint not null
|
||||
# external_id :string
|
||||
# folder_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
@@ -57,6 +58,7 @@ class Template < ApplicationRecord
|
||||
|
||||
serialize :preferences, coder: JSON
|
||||
serialize :fields, coder: JSON
|
||||
serialize :variables_schema, coder: JSON
|
||||
serialize :schema, coder: JSON
|
||||
serialize :submitters, coder: JSON
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTemplateVariables < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :templates, :variables_schema, :text
|
||||
add_column :submissions, :variables_schema, :text
|
||||
add_column :submissions, :variables, :text
|
||||
end
|
||||
end
|
||||
+4
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_09_01_110606) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_09_12_090605) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "btree_gin"
|
||||
enable_extension "plpgsql"
|
||||
@@ -305,6 +305,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_01_110606) do
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "expire_at"
|
||||
t.text "name"
|
||||
t.text "variables_schema"
|
||||
t.text "variables"
|
||||
t.index ["account_id", "id"], name: "index_submissions_on_account_id_and_id"
|
||||
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id", where: "(archived_at IS NULL)"
|
||||
t.index ["account_id", "template_id", "id"], name: "index_submissions_on_account_id_and_template_id_and_id_archived", where: "(archived_at IS NOT NULL)"
|
||||
@@ -389,6 +391,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_01_110606) do
|
||||
t.string "external_id"
|
||||
t.text "preferences", null: false
|
||||
t.boolean "shared_link", default: false, null: false
|
||||
t.text "variables_schema"
|
||||
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"
|
||||
|
||||
@@ -70,6 +70,7 @@ module Submissions
|
||||
|
||||
def update_template_fields!(submission)
|
||||
submission.template_fields = submission.template.fields
|
||||
submission.variables_schema = submission.template.variables_schema
|
||||
submission.template_schema = submission.template.schema
|
||||
submission.template_submitters = submission.template.submitters if submission.template_submitters.blank?
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ module Submissions
|
||||
account_id: user.account_id,
|
||||
preferences: set_submission_preferences,
|
||||
name: with_template ? attrs[:name] : (attrs[:name] || template.name),
|
||||
variables: attrs[:variables] || {},
|
||||
expire_at:,
|
||||
template_submitters: [], submitters_order:)
|
||||
|
||||
@@ -139,8 +140,9 @@ module Submissions
|
||||
end
|
||||
|
||||
if template_fields != (submission.template_fields || submission.template.fields) ||
|
||||
submitters_attrs.any? { |e| e[:completed].present? } || !with_template
|
||||
submitters_attrs.any? { |e| e[:completed].present? } || !with_template || submission.variables.present?
|
||||
submission.template_fields = template_fields
|
||||
submission.variables_schema = submission.template.variables_schema if submission.variables_schema.blank?
|
||||
submission.template_schema = submission.template.schema if submission.template_schema.blank?
|
||||
end
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ module Submissions
|
||||
|
||||
json = submission.as_json(SERIALIZE_PARAMS)
|
||||
|
||||
json['variables'] = (submission.variables || {}).as_json
|
||||
json['created_by_user'] ||= nil
|
||||
|
||||
if with_events
|
||||
|
||||
@@ -35,8 +35,7 @@ module Submitters
|
||||
'audit_log_url' => submitter.submission.audit_log_url(expires_at:),
|
||||
'submission_url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
|
||||
'template' => submission.template.as_json(
|
||||
only: %i[id name external_id created_at updated_at],
|
||||
methods: %i[folder_name]
|
||||
only: %i[id name external_id created_at updated_at], methods: %i[folder_name]
|
||||
),
|
||||
'submission' => {
|
||||
'id' => submission.id,
|
||||
@@ -44,6 +43,7 @@ module Submitters
|
||||
'combined_document_url' => submission.combined_document_url(expires_at:),
|
||||
'status' => build_submission_status(submission),
|
||||
'url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
|
||||
'variables' => (submission.variables || {}).as_json,
|
||||
'created_at' => submission.created_at.as_json
|
||||
})
|
||||
end
|
||||
|
||||
@@ -298,6 +298,7 @@ describe 'Submission API' do
|
||||
completed_at: nil,
|
||||
created_at: submission.created_at,
|
||||
updated_at: submission.updated_at,
|
||||
variables: {},
|
||||
archived_at: nil,
|
||||
status: 'pending',
|
||||
submitters:,
|
||||
@@ -358,6 +359,7 @@ describe 'Submission API' do
|
||||
completed_at: nil,
|
||||
created_at: submission.created_at,
|
||||
updated_at: submission.updated_at,
|
||||
variables: {},
|
||||
archived_at: nil,
|
||||
submitters:,
|
||||
template: {
|
||||
|
||||
Reference in New Issue
Block a user