Sha256: 3acacccf7befa2be9060ea98baa9f4f195130926fcce3936fd56457f1f5e30ca

Contents?: true

Size: 1.14 KB

Versions: 44

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: :delete do
        def emails
          where(_type: 'EmailNotification')
        end

        def slacks
          where(_type: 'SlackNotification')
        end

        def sms
          where(_type: 'SmsNotification')
        end
      end
      has_many :templates, dependent: :delete
      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

44 entries across 44 versions & 1 rubygems

Version Path
web47core-1.1.8 lib/app/models/concerns/core_account.rb
web47core-1.1.7 lib/app/models/concerns/core_account.rb
web47core-1.1.6 lib/app/models/concerns/core_account.rb
web47core-1.1.5 lib/app/models/concerns/core_account.rb
web47core-1.1.4 lib/app/models/concerns/core_account.rb
web47core-1.1.3 lib/app/models/concerns/core_account.rb
web47core-1.1.2 lib/app/models/concerns/core_account.rb
web47core-1.1.1 lib/app/models/concerns/core_account.rb
web47core-1.1.0 lib/app/models/concerns/core_account.rb
web47core-1.0.18 lib/app/models/concerns/core_account.rb
web47core-1.0.17 lib/app/models/concerns/core_account.rb
web47core-1.0.16 lib/app/models/concerns/core_account.rb
web47core-1.0.15 lib/app/models/concerns/core_account.rb
web47core-1.0.14 lib/app/models/concerns/core_account.rb
web47core-1.0.13 lib/app/models/concerns/core_account.rb
web47core-1.0.12 lib/app/models/concerns/core_account.rb
web47core-1.0.11 lib/app/models/concerns/core_account.rb
web47core-1.0.10 lib/app/models/concerns/core_account.rb
web47core-1.0.8 lib/app/models/concerns/core_account.rb
web47core-1.0.7 lib/app/models/concerns/core_account.rb