Chatwoot/app/models/account.rb
Sony Mathew 96efc44b82
Chore: Feature lock email settings in UI (#1065)
* Chore: Feature lock email settings in UI

The email settings under account settings needed to be
feature locked in a way different from teh current way for it
to be enabled for accounts in a self hosted scenario.

Some refactorings were also done along with this change.

1. There was a feature flag defined in code in account model called
domain_emails_enabled was used to check if the inbound emails was
enabled for the account. But there was already a feature flag called
"inbound_emails" defined in features.yml. So changed to use this to
check if inbound emails are enabled for an account.
2. Renamed and re-purposed existing `domain_emails_enabled` to
`custom_email_domain_enabled` to use for feature toggling the UI
for email settings.
3. To enable & disable multiple features using the featurable concern
we were passing an array of values. Changed this to accept a comma
separated set of values.

* Chore: Feature lock email settings in UI

Fixed the specs for accounts controller & removed
unneccessary code from Account seetings component in UI

* Chore: Convert newlines to <br>s

Removed the layout used while sending replies in
conversation continuity.

Converted the newlines in the messages to <br/> tags
for the correct HTML rendering.

* Chore: Bug fix in reply email domain

Renamed the function custom_email_domain_enabled  to
inbound_email_enabled.

Fixed bug on setting reply emails's domain.
2020-07-19 23:08:07 +05:30

92 lines
2.8 KiB
Ruby

# == Schema Information
#
# Table name: accounts
#
# id :integer not null, primary key
# domain :string(100)
# feature_flags :integer default(0), not null
# locale :integer default("en")
# name :string not null
# settings_flags :integer default(0), not null
# support_email :string(100)
# created_at :datetime not null
# updated_at :datetime not null
#
class Account < ApplicationRecord
# used for single column multi flags
include FlagShihTzu
include Events::Types
include Reportable
include Featurable
DEFAULT_QUERY_SETTING = {
flag_query_mode: :bit_operator
}.freeze
ACCOUNT_SETTINGS_FLAGS = {
1 => :custom_email_domain_enabled
}.freeze
validates :name, presence: true
has_many :account_users, dependent: :destroy
has_many :agent_bot_inboxes, dependent: :destroy
has_many :users, through: :account_users
has_many :inboxes, dependent: :destroy
has_many :conversations, dependent: :destroy
has_many :messages, dependent: :destroy
has_many :contacts, dependent: :destroy
has_many :facebook_pages, dependent: :destroy, class_name: '::Channel::FacebookPage'
has_many :telegram_bots, dependent: :destroy
has_many :twilio_sms, dependent: :destroy, class_name: '::Channel::TwilioSms'
has_many :twitter_profiles, dependent: :destroy, class_name: '::Channel::TwitterProfile'
has_many :web_widgets, dependent: :destroy, class_name: '::Channel::WebWidget'
has_many :canned_responses, dependent: :destroy
has_many :webhooks, dependent: :destroy
has_many :labels, dependent: :destroy
has_many :notification_settings, dependent: :destroy
has_many :hooks, dependent: :destroy, class_name: 'Integrations::Hook'
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h
after_create :notify_creation
after_destroy :notify_deletion
def agents
users.where(account_users: { role: :agent })
end
def administrators
users.where(account_users: { role: :administrator })
end
def all_conversation_tags
# returns array of tags
conversation_ids = conversations.pluck(:id)
ActsAsTaggableOn::Tagging.includes(:tag)
.where(context: 'labels',
taggable_type: 'Conversation',
taggable_id: conversation_ids)
.map { |_| _.tag.name }
end
def webhook_data
{
id: id,
name: name
}
end
private
def notify_creation
Rails.configuration.dispatcher.dispatch(ACCOUNT_CREATED, Time.zone.now, account: self)
end
def notify_deletion
Rails.configuration.dispatcher.dispatch(ACCOUNT_DESTROYED, Time.zone.now, account: self)
end
end