Sha256: 9a1a3cccae8f5c564fc523755277369ea23fd409f94918aaa0f9048c51dcae04

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true
module Decidim
  # A custom mailer for Devise so we can tweak the invitation instructions for
  # each role and use a localised version.
  class DecidimDeviseMailer < Devise::Mailer
    include LocalisedMailer
    include Roadie::Rails::Automatic

    layout "decidim/mailer"

    # Sends an email with the invitation instructions to a new user.
    #
    # user  - The User that has been invited.
    # token - The String to be sent as a token to verify the invitation.
    # opts  - A Hash with options to send the email (optional).
    def invitation_instructions(user, token, opts = {})
      with_user(user) do
        @token = token

        if opts[:invitation_instructions] == "organization_admin_invitation_instructions"
          opts[:subject] = I18n.t("devise.mailer.organization_admin_invitation_instructions.subject", organization: user.organization.name)
        end
      end

      devise_mail(user, opts[:invitation_instructions] || :invitation_instructions, opts)
    end

    private

    # Overwrite devise_mail so we can inject the organization from the user.
    def devise_mail(user, action, opts = {}, &block)
      with_user(user) do
        @organization = user.organization
        super
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.0.1 app/mailers/decidim/decidim_devise_mailer.rb
decidim-core-0.0.1.alpha9 app/mailers/decidim/decidim_devise_mailer.rb
decidim-core-0.0.1.alpha8 app/mailers/decidim/decidim_devise_mailer.rb
decidim-core-0.0.1.alpha7 app/mailers/decidim/decidim_devise_mailer.rb
decidim-core-0.0.1.alpha6 app/mailers/decidim/decidim_devise_mailer.rb
decidim-core-0.0.1.alpha5 app/mailers/decidim/decidim_devise_mailer.rb