Sha256: c2587987560210ec931b3b11c63e5afdbbe4af80145d4cb9b5a51fb953a322f9

Contents?: true

Size: 1.46 KB

Versions: 15

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  class NewsletterMailer < ApplicationMailer
    helper Decidim::SanitizeHelper
    helper Decidim::TranslationsHelper

    include Decidim::NewslettersHelper

    layout "decidim/newsletter_base"

    helper_method :cell

    def newsletter(user, newsletter, preview: false)
      return if user.email.blank?

      @organization = user.organization
      @newsletter = newsletter
      @user = user
      @preview = preview

      @custom_url_for_mail_root =
        if @preview
          "#"
        elsif Decidim.config.track_newsletter_links
          custom_url_for_mail_root(@organization, @newsletter.id)
        end
      @encrypted_token = Decidim::NewsletterEncryptor.sent_at_encrypted(@user.id, @newsletter.sent_at)

      with_user(user) do
        uninterpolated_subject =
          @newsletter.subject[I18n.locale.to_s].presence || @newsletter.subject[@organization.default_locale]

        @subject = parse_interpolations(uninterpolated_subject, user, @newsletter.id)

        mail(to: "#{user.name} <#{user.email}>", subject: @subject)
      end
    end

    private

    def cell
      @cell ||= ::Decidim::ViewModel.cell(
        @newsletter.template.cell,
        @newsletter.template,
        organization: @organization,
        newsletter: @newsletter,
        recipient_user: @user,
        custom_url_for_mail_root: @custom_url_for_mail_root,
        context: {
          controller: self
        }
      )
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.9 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.3 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.8 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.2 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.7 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.1 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.6 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.0 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.5 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.0.rc5 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.28.0.rc4 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.4 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.3 app/mailers/decidim/newsletter_mailer.rb
decidim-core-0.27.2 app/mailers/decidim/newsletter_mailer.rb