Sha256: ce00671b486b2b1b4a9dad9055f153cb7446a2b1e5323178c03ba29e2aefafb8

Contents?: true

Size: 636 Bytes

Versions: 45

Compression:

Stored size: 636 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This model holds all the data needed to send a newsletter.
  class Newsletter < ApplicationRecord
    belongs_to :author, class_name: "User"
    belongs_to :organization

    validates :subject, :body, presence: true
    validate :author_belongs_to_organization

    # Returns true if this newsletter was already sent.
    #
    # Returns a Boolean.
    def sent?
      sent_at.present?
    end

    private

    def author_belongs_to_organization
      return if !author || !organization
      errors.add(:author, :invalid) unless author.organization == organization
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
decidim-core-0.4.0 app/models/decidim/newsletter.rb
decidim-core-0.3.2 app/models/decidim/newsletter.rb
decidim-core-0.3.1 app/models/decidim/newsletter.rb
decidim-core-0.3.0 app/models/decidim/newsletter.rb
decidim-core-0.2.0 app/models/decidim/newsletter.rb