Sha256: 61e10851757ae2e559cc6a5d4c8e6073dac3dd066c260f62c94cabd004b42ecb

Contents?: true

Size: 1.14 KB

Versions: 43

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

#
# The Base Account
#
module CoreAccount
  extend ActiveSupport::Concern

  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

  #
  # Return or build the smtp configuration for the account
  #
  def fetch_smtp_configuration
    smtp_configuration || build_smtp_configuration
  end

  #
  # return the email notifications templates, these are custom notifications sent by an admin.
  #
  def email_notification_templates
    templates.where(_type: 'EmailNotificationTemplate')
  end

  #
  # return the email templates, these are email templates for actions in the system
  #
  def email_templates
    templates.where(_type: 'EmailTemplate')
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
web47core-3.2.20 lib/app/models/concerns/core_account.rb
web47core-3.2.19 lib/app/models/concerns/core_account.rb
web47core-3.2.18 lib/app/models/concerns/core_account.rb
web47core-3.2.17 lib/app/models/concerns/core_account.rb
web47core-3.2.16 lib/app/models/concerns/core_account.rb
web47core-3.2.15 lib/app/models/concerns/core_account.rb
web47core-3.2.14 lib/app/models/concerns/core_account.rb
web47core-3.2.13 lib/app/models/concerns/core_account.rb
web47core-3.2.12 lib/app/models/concerns/core_account.rb
web47core-3.2.9 lib/app/models/concerns/core_account.rb
web47core-3.2.8 lib/app/models/concerns/core_account.rb
web47core-3.2.7 lib/app/models/concerns/core_account.rb
web47core-3.2.6 lib/app/models/concerns/core_account.rb
web47core-3.2.5 lib/app/models/concerns/core_account.rb
web47core-3.2.4 lib/app/models/concerns/core_account.rb
web47core-2.2.20 lib/app/models/concerns/core_account.rb
web47core-2.2.19 lib/app/models/concerns/core_account.rb
web47core-3.2.3 lib/app/models/concerns/core_account.rb
web47core-3.2.2 lib/app/models/concerns/core_account.rb
web47core-2.2.15 lib/app/models/concerns/core_account.rb