feat: Added portal logo and the updated the JSON (#4996)

This commit is contained in:
Tejaswini Chile
2022-07-11 12:43:24 +05:30
committed by GitHub
parent 9d4b77533e
commit 23ac1c0334
10 changed files with 101 additions and 11 deletions

View File

@@ -21,6 +21,8 @@
# index_portals_on_slug (slug) UNIQUE
#
class Portal < ApplicationRecord
include Rails.application.routes.url_helpers
belongs_to :account
has_many :categories, dependent: :destroy_async
has_many :folders, through: :categories
@@ -33,12 +35,35 @@ class Portal < ApplicationRecord
class_name: :User,
dependent: :nullify,
source: :user
has_one_attached :logo
validates :account_id, presence: true
validates :name, presence: true
validates :slug, presence: true, uniqueness: true
validate :config_json_format
accepts_nested_attributes_for :members
scope :active, -> { where(archived: false) }
CONFIG_JSON_KEYS = %w[allowed_locales].freeze
def file_base_data
{
id: logo.id,
portal_id: id,
file_type: logo.content_type,
account_id: account_id,
file_url: url_for(logo),
blob_id: logo.blob_id,
filename: logo.filename.to_s
}
end
private
def config_json_format
denied_keys = config.keys - CONFIG_JSON_KEYS
errors.add(:cofig, "in portal on #{denied_keys.join(',')} is not supported.") if denied_keys.any?
end
end