Module: CoreAccount

Extended by:
ActiveSupport::Concern
Defined in:
lib/app/models/concerns/core_account.rb

Overview

The Base Account

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/app/models/concerns/core_account.rb', line 9

def self.included(base)
  base.class_eval do
    #
    # Fields
    #
    field :name, type: String
    #
    # Relationships
    #
    has_many :notifications, dependent: :destroy do
      def emails
        where(_type: 'EmailNotification')
      end

      def slacks
        where(_type: 'SlackNotification')
      end

      def sms
        where(_type: 'SmsNotification')
      end
    end
    has_many :templates, dependent: :destroy
    embeds_one :smtp_configuration
  end
end

Instance Method Details

#email_notification_templatesObject

return the email notifications templates, these are custom notifications sent by an admin.



46
47
48
# File 'lib/app/models/concerns/core_account.rb', line 46

def email_notification_templates
  templates.where(_type: 'EmailNotificationTemplate')
end

#email_templatesObject

return the email templates, these are email templates for actions in the system



53
54
55
# File 'lib/app/models/concerns/core_account.rb', line 53

def email_templates
  templates.where(_type: 'EmailTemplate')
end

#fetch_smtp_configurationObject

Return or build the smtp configuration for the account



39
40
41
# File 'lib/app/models/concerns/core_account.rb', line 39

def fetch_smtp_configuration
  smtp_configuration || build_smtp_configuration
end