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.9.3 app/models/decidim/newsletter.rb
decidim-core-0.9.2 app/models/decidim/newsletter.rb
decidim-core-0.9.1 app/models/decidim/newsletter.rb
decidim-core-0.9.0 app/models/decidim/newsletter.rb
decidim-core-0.8.4 app/models/decidim/newsletter.rb
decidim-core-0.8.3 app/models/decidim/newsletter.rb
decidim-core-0.8.2 app/models/decidim/newsletter.rb
decidim-core-0.8.1 app/models/decidim/newsletter.rb
decidim-core-0.8.0 app/models/decidim/newsletter.rb
decidim-core-0.7.4 app/models/decidim/newsletter.rb
decidim-core-0.7.3 app/models/decidim/newsletter.rb
decidim-core-0.7.2 app/models/decidim/newsletter.rb
decidim-core-0.7.1 app/models/decidim/newsletter.rb
decidim-core-0.7.0 app/models/decidim/newsletter.rb
decidim-core-0.6.8 app/models/decidim/newsletter.rb
decidim-0.6.8 decidim-core/app/models/decidim/newsletter.rb
decidim-core-0.6.7 app/models/decidim/newsletter.rb
decidim-0.6.7 decidim-core/app/models/decidim/newsletter.rb
decidim-core-0.6.6 app/models/decidim/newsletter.rb
decidim-0.6.6 decidim-core/app/models/decidim/newsletter.rb