initial commit

This commit is contained in:
Alex Turchyn
2023-05-21 17:59:36 +03:00
commit 97c462ead2
159 changed files with 10987 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: accounts
#
# id :bigint not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Account < ApplicationRecord
has_many :users, dependent: :destroy
has_many :encrypted_configs, dependent: :destroy
has_many :flows, dependent: :destroy
has_many :active_users, -> { active }, dependent: :destroy,
inverse_of: :account, class_name: 'User'
end
+7
View File
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
strip_attributes
end
+32
View File
@@ -0,0 +1,32 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: encrypted_configs
#
# id :bigint not null, primary key
# key :string not null
# value :text not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
#
# Indexes
#
# index_encrypted_configs_on_account_id (account_id)
# index_encrypted_configs_on_account_id_and_key (account_id,key) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
#
class EncryptedConfig < ApplicationRecord
FILES_STORAGE_KEY = 'active_storage'
EMAIL_SMTP_KEY = 'action_mailer_smtp'
belongs_to :account
encrypts :value
serialize :value, JSON
end
+45
View File
@@ -0,0 +1,45 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: flows
#
# id :bigint not null, primary key
# deleted_at :datetime
# fields :string not null
# name :string not null
# schema :string not null
# slug :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# author_id :bigint not null
#
# Indexes
#
# index_flows_on_account_id (account_id)
# index_flows_on_author_id (author_id)
# index_flows_on_slug (slug) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (author_id => users.id)
#
class Flow < ApplicationRecord
belongs_to :author, class_name: 'User'
belongs_to :account
attribute :fields, :string, default: -> { [] }
attribute :schema, :string, default: -> { [] }
attribute :slug, :string, default: -> { SecureRandom.base58(8) }
serialize :fields, JSON
serialize :schema, JSON
has_many_attached :documents
has_many :submissions, dependent: :destroy
scope :active, -> { where(deleted_at: nil) }
end
+47
View File
@@ -0,0 +1,47 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: submissions
#
# id :bigint not null, primary key
# completed_at :datetime
# deleted_at :datetime
# email :string not null
# ip :string
# opened_at :datetime
# sent_at :datetime
# slug :string not null
# ua :string
# values :string not null
# created_at :datetime not null
# updated_at :datetime not null
# flow_id :bigint not null
#
# Indexes
#
# index_submissions_on_email (email)
# index_submissions_on_flow_id (flow_id)
# index_submissions_on_slug (slug) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (flow_id => flows.id)
#
class Submission < ApplicationRecord
belongs_to :flow
attribute :values, :string, default: -> { {} }
attribute :slug, :string, default: -> { SecureRandom.base58(8) }
serialize :values, JSON
has_one_attached :archive
has_many_attached :documents
has_many_attached :attachments
has_many_attached :images
has_many_attached :signatures
scope :active, -> { where(deleted_at: nil) }
end
+66
View File
@@ -0,0 +1,66 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# current_sign_in_at :datetime
# current_sign_in_ip :string
# deleted_at :datetime
# email :string not null
# encrypted_password :string not null
# failed_attempts :integer default(0), not null
# first_name :string not null
# last_name :string not null
# last_sign_in_at :datetime
# last_sign_in_ip :string
# locked_at :datetime
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# role :string not null
# sign_in_count :integer default(0), not null
# unlock_token :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
#
# Indexes
#
# index_users_on_account_id (account_id)
# index_users_on_email (email) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_unlock_token (unlock_token) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
#
class User < ApplicationRecord
ROLES = %w[admin].freeze
EMAIL_REGEXP =
/[a-z0-9][.']?(?:(?:[a-z0-9_-]++[.'])*[a-z0-9_-]++)*@(?:[a-z0-9]++[.-])*[a-z0-9]++\.[a-z]{2,}/i
belongs_to :account
devise :database_authenticatable, :recoverable, :rememberable, :validatable, :trackable
devise :registerable # if ENV['APP_MULTITENANT']
attribute :role, :string, default: 'admin'
scope :active, -> { where(deleted_at: nil) }
def active_for_authentication?
!deleted_at?
end
def full_name
[first_name, last_name].join(' ')
end
def friendly_name
"#{full_name} <#{email}>"
end
end