Sha256: 2f1bbeb34a5bac649bfef3c7c7bb823ed3ecfa8b47259cea53e91c2d9b95e75c

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

class UserMailer < ApplicationMailer
  include WithCertificateRender

  def welcome_email(user, organization)
    with_locale(user, organization) do
      organization_name = organization.display_name || t(:your_new_organization)
      build_email t(:welcome, name: organization_name), { inline: organization.welcome_email_template }, from: organization.welcome_email_sender
    end
  end

  def we_miss_you_reminder(user, cycles)
    with_locale(user) do
      build_email t(:we_miss_you), "#{cycles.ordinalize}_reminder"
    end
  end

  def no_submissions_reminder(user)
    with_locale(user) do
      build_email t(:start_using_mumuki), 'no_submissions_reminder'
    end
  end

  def certificate(certificate)
    with_locale certificate.user, certificate.organization do
      attachments[certificate.filename] = pdf_for(certificate)
      mail to: certificate.user.email, subject: t(:certificate)
    end
  end

  def with_locale(user, organization = nil, &block)
    @user = user
    @unsubscribe_code = User.unsubscription_verifier.generate(user.id)
    @organization = organization || user.last_organization

    I18n.with_locale(@organization.locale, &block)
  end

  private

  def build_email(subject, template, **options)
    mail options.compact.merge(to: @user.email,
                               subject: subject,
                               content_type: 'text/html',
                               body: render(template))
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mumuki-laboratory-9.7.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.6.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.5.1 app/mailers/user_mailer.rb
mumuki-laboratory-9.5.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.4.1 app/mailers/user_mailer.rb
mumuki-laboratory-9.4.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.3.1 app/mailers/user_mailer.rb
mumuki-laboratory-9.3.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.2.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.1.3 app/mailers/user_mailer.rb
mumuki-laboratory-9.1.2 app/mailers/user_mailer.rb
mumuki-laboratory-9.1.1 app/mailers/user_mailer.rb
mumuki-laboratory-9.1.0 app/mailers/user_mailer.rb
mumuki-laboratory-9.0.6 app/mailers/user_mailer.rb
mumuki-laboratory-9.0.5 app/mailers/user_mailer.rb
mumuki-laboratory-9.0.4 app/mailers/user_mailer.rb
mumuki-laboratory-9.0.3 app/mailers/user_mailer.rb
mumuki-laboratory-9.0.2 app/mailers/user_mailer.rb