chore: General fixes and clean up (#1169)
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
class Account < ApplicationRecord
|
||||
# used for single column multi flags
|
||||
include FlagShihTzu
|
||||
|
||||
include Events::Types
|
||||
include Reportable
|
||||
include Featurable
|
||||
|
||||
@@ -54,7 +52,7 @@ class Account < ApplicationRecord
|
||||
|
||||
enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h
|
||||
|
||||
after_create :notify_creation
|
||||
after_create_commit :notify_creation
|
||||
after_destroy :notify_deletion
|
||||
|
||||
def agents
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#
|
||||
|
||||
class AccountUser < ApplicationRecord
|
||||
include Events::Types
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :user
|
||||
belongs_to :inviter, class_name: 'User', optional: true
|
||||
@@ -33,7 +31,7 @@ class AccountUser < ApplicationRecord
|
||||
enum role: { agent: 0, administrator: 1 }
|
||||
accepts_nested_attributes_for :account
|
||||
|
||||
after_create :notify_creation, :create_notification_setting
|
||||
after_create_commit :notify_creation, :create_notification_setting
|
||||
after_destroy :notify_deletion, :destroy_notification_setting
|
||||
|
||||
validates :user_id, uniqueness: { scope: :account_id }
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
include Events::Types
|
||||
self.abstract_class = true
|
||||
|
||||
# the models that exposed in email templates through liquid
|
||||
DROPPABLES = %w[Account Channel Conversation Inbox User].freeze
|
||||
|
||||
# ModelDrop class should exist in app/drops
|
||||
def to_drop
|
||||
return unless DROPPABLES.include?(self.class.name)
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ class Contact < ApplicationRecord
|
||||
include Pubsubable
|
||||
include Avatarable
|
||||
include AvailabilityStatusable
|
||||
include Events::Types
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
#
|
||||
|
||||
class Conversation < ApplicationRecord
|
||||
include Events::Types
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :inbox_id, presence: true
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#
|
||||
|
||||
class Message < ApplicationRecord
|
||||
include Events::Types
|
||||
|
||||
NUMBER_OF_PERMITTED_ATTACHMENTS = 15
|
||||
|
||||
validates :account_id, presence: true
|
||||
@@ -105,6 +103,7 @@ class Message < ApplicationRecord
|
||||
created_at: created_at,
|
||||
message_type: message_type,
|
||||
content_type: content_type,
|
||||
private: private,
|
||||
content_attributes: content_attributes,
|
||||
source_id: source_id,
|
||||
sender: sender.try(:webhook_data),
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
class Plan
|
||||
attr_accessor :key, :attributes
|
||||
|
||||
def initialize(key, attributes = {})
|
||||
@key = key.to_sym
|
||||
@attributes = attributes
|
||||
end
|
||||
|
||||
def name
|
||||
attributes[:name]
|
||||
end
|
||||
|
||||
def id
|
||||
attributes[:id]
|
||||
end
|
||||
|
||||
def price
|
||||
attributes[:price]
|
||||
end
|
||||
|
||||
def active
|
||||
attributes[:active]
|
||||
end
|
||||
|
||||
def version
|
||||
attributes[:version]
|
||||
end
|
||||
|
||||
class << self
|
||||
def config
|
||||
Hashie::Mash.new(PLAN_CONFIG)
|
||||
end
|
||||
|
||||
def default_trial_period
|
||||
(config['trial_period'] || 14).days
|
||||
end
|
||||
|
||||
def default_pricing_version
|
||||
config['default_pricing_version']
|
||||
end
|
||||
|
||||
def default_plans
|
||||
load_active_plans + load_inactive_plans
|
||||
end
|
||||
|
||||
def all_plans
|
||||
default_plans
|
||||
end
|
||||
|
||||
def active_plans
|
||||
all_plans.select(&:active)
|
||||
end
|
||||
|
||||
def paid_plan
|
||||
active_plans.first
|
||||
end
|
||||
|
||||
def inactive_plans
|
||||
all_plans.reject(&:active)
|
||||
end
|
||||
|
||||
def trial_plan
|
||||
all_plans.detect { |plan| plan.key == :trial }
|
||||
end
|
||||
|
||||
def plans_of_version(version)
|
||||
all_plans.select { |plan| plan.version == version }
|
||||
end
|
||||
|
||||
def find_by_key(key)
|
||||
key = key.to_sym
|
||||
all_plans.detect { |plan| plan.key == key }.dup
|
||||
end
|
||||
|
||||
# #helpers
|
||||
|
||||
def load_active_plans
|
||||
result = []
|
||||
Plan.config.active.each_pair do |version, plans|
|
||||
plans.each_pair do |key, attributes|
|
||||
result << Plan.new(key, attributes.merge(active: true, version: version))
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def load_inactive_plans
|
||||
result = []
|
||||
Plan.config.inactive.each_pair do |version, plans|
|
||||
plans.each_pair do |key, attributes|
|
||||
result << Plan.new(key, attributes.merge(active: false, version: version))
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -41,7 +41,6 @@ class User < ApplicationRecord
|
||||
include Avatarable
|
||||
# Include default devise modules.
|
||||
include DeviseTokenAuth::Concerns::User
|
||||
include Events::Types
|
||||
include Pubsubable
|
||||
include Rails.application.routes.url_helpers
|
||||
include Reportable
|
||||
@@ -78,7 +77,7 @@ class User < ApplicationRecord
|
||||
|
||||
before_validation :set_password_and_uid, on: :create
|
||||
|
||||
after_create :create_access_token
|
||||
after_create_commit :create_access_token
|
||||
after_save :update_presence_in_redis, if: :saved_change_to_availability?
|
||||
|
||||
scope :order_by_full_name, -> { order('lower(name) ASC') }
|
||||
|
||||
Reference in New Issue
Block a user