Sha256: 263c7d2e85692641b586776575671e9df6e55644345d722b8192ff169a4baabe

Contents?: true

Size: 795 Bytes

Versions: 24

Compression:

Stored size: 795 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This model holds all the data needed to send a newsletter.
  class Newsletter < ApplicationRecord
    include Decidim::Traceable
    include Decidim::Loggable

    belongs_to :author, class_name: "User"
    belongs_to :organization

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

    def self.log_presenter_class_for(_log)
      Decidim::AdminLog::NewsletterPresenter
    end

    # 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

24 entries across 24 versions & 1 rubygems

Version Path
decidim-core-0.17.2 app/models/decidim/newsletter.rb
decidim-core-0.17.1 app/models/decidim/newsletter.rb
decidim-core-0.16.1 app/models/decidim/newsletter.rb
decidim-core-0.17.0 app/models/decidim/newsletter.rb
decidim-core-0.16.0 app/models/decidim/newsletter.rb
decidim-core-0.15.2 app/models/decidim/newsletter.rb
decidim-core-0.15.1 app/models/decidim/newsletter.rb
decidim-core-0.15.0 app/models/decidim/newsletter.rb
decidim-core-0.14.4 app/models/decidim/newsletter.rb
decidim-core-0.14.3 app/models/decidim/newsletter.rb
decidim-core-0.14.2 app/models/decidim/newsletter.rb
decidim-core-0.14.1 app/models/decidim/newsletter.rb
decidim-core-0.13.1 app/models/decidim/newsletter.rb
decidim-core-0.12.2 app/models/decidim/newsletter.rb
decidim-core-0.13.0 app/models/decidim/newsletter.rb
decidim-core-0.12.1 app/models/decidim/newsletter.rb
decidim-core-0.13.0.pre1 app/models/decidim/newsletter.rb
decidim-core-0.12.0 app/models/decidim/newsletter.rb
decidim-core-0.11.2 app/models/decidim/newsletter.rb
decidim-core-0.12.0.pre app/models/decidim/newsletter.rb