add folders structure

This commit is contained in:
Alex Turchyn
2023-09-22 02:20:38 +03:00
parent f8712a9da9
commit 380f553a17
30 changed files with 405 additions and 56 deletions
+4 -5
View File
@@ -17,7 +17,7 @@ class Account < ApplicationRecord
has_many :account_configs, dependent: :destroy
has_many :templates, dependent: :destroy
has_many :template_folders, dependent: :destroy
has_one :default_folder, -> { where(name: TemplateFolder::DEFAULT_NAME) },
has_one :default_template_folder, -> { where(name: TemplateFolder::DEFAULT_NAME) },
class_name: 'TemplateFolder', dependent: :destroy, inverse_of: :account
has_many :submissions, through: :templates
has_many :submitters, through: :submissions
@@ -27,9 +27,8 @@ class Account < ApplicationRecord
attribute :timezone, :string, default: 'UTC'
attribute :locale, :string, default: 'en-US'
def default_folder
super || template_folders.new(name: TemplateFolder::DEFAULT_NAME,
author_id: users.minimum(:id))
.tap(&:save!)
def default_template_folder
super || build_default_template_folder(name: TemplateFolder::DEFAULT_NAME,
author_id: users.minimum(:id)).tap(&:save!)
end
end