Files
docuseal/app/models/submission.rb
T

79 lines
2.3 KiB
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
# == Schema Information
#
# Table name: submissions
#
2023-07-26 09:58:50 +03:00
# id :bigint not null, primary key
# deleted_at :datetime
2023-11-23 20:03:52 +02:00
# preferences :text not null
# slug :string not null
2023-08-05 19:20:06 +03:00
# source :text not null
2023-09-10 02:10:01 +03:00
# submitters_order :string not null
2023-07-26 09:58:50 +03:00
# template_fields :text
# template_schema :text
# template_submitters :text
# created_at :datetime not null
# updated_at :datetime not null
# created_by_user_id :bigint
# template_id :bigint not null
2023-05-21 17:59:36 +03:00
#
# Indexes
#
2023-06-29 02:04:17 +03:00
# index_submissions_on_created_by_user_id (created_by_user_id)
# index_submissions_on_slug (slug) UNIQUE
2023-06-29 02:04:17 +03:00
# index_submissions_on_template_id (template_id)
2023-05-21 17:59:36 +03:00
#
# Foreign Keys
#
2023-06-29 02:04:17 +03:00
# fk_rails_... (created_by_user_id => users.id)
2023-05-31 23:19:20 +03:00
# fk_rails_... (template_id => templates.id)
2023-05-21 17:59:36 +03:00
#
class Submission < ApplicationRecord
2023-05-31 23:19:20 +03:00
belongs_to :template
2023-08-05 15:25:16 +03:00
has_one :account, through: :template
2023-06-29 02:04:17 +03:00
belongs_to :created_by_user, class_name: 'User', optional: true
2023-05-21 17:59:36 +03:00
2023-06-13 00:29:07 +03:00
has_many :submitters, dependent: :destroy
2023-09-10 12:55:41 +03:00
has_many :submission_events, dependent: :destroy
2023-05-21 17:59:36 +03:00
2023-11-23 20:03:52 +02:00
attribute :preferences, :string, default: -> { {} }
2023-07-26 09:58:50 +03:00
serialize :template_fields, JSON
serialize :template_schema, JSON
serialize :template_submitters, JSON
2023-11-23 20:03:52 +02:00
serialize :preferences, JSON
2023-07-26 09:58:50 +03:00
2023-08-05 19:20:06 +03:00
attribute :source, :string, default: 'link'
2023-09-10 02:10:01 +03:00
attribute :submitters_order, :string, default: 'random'
2023-08-05 19:20:06 +03:00
attribute :slug, :string, default: -> { SecureRandom.base58(14) }
2023-09-10 19:25:57 +03:00
has_one_attached :audit_trail
2023-09-01 01:27:13 +03:00
has_many :template_schema_documents,
->(e) { where(uuid: (e.template_schema.presence || e.template.schema).pluck('attachment_uuid')) },
through: :template, source: :documents_attachments
2023-05-21 17:59:36 +03:00
scope :active, -> { where(deleted_at: nil) }
2023-10-19 20:19:52 +03:00
scope :pending, -> { joins(:submitters).where(submitters: { completed_at: nil }).distinct }
2023-11-02 20:32:51 +02:00
scope :completed, -> { where.not(id: pending.select(:submission_id)) }
2023-08-05 19:20:06 +03:00
enum :source, {
invite: 'invite',
api: 'api',
embed: 'embed',
link: 'link'
}, scope: false, prefix: true
2023-09-10 02:10:01 +03:00
enum :submitters_order, {
random: 'random',
preserved: 'preserved'
}, scope: false, prefix: true
2023-11-01 12:17:35 +02:00
def audit_trail_url
audit_trail&.url
end
alias audit_log_url audit_trail_url
2023-05-21 17:59:36 +03:00
end