Skip to content

Commit

Permalink
send an email on account approval
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Nov 22, 2024
1 parent cd4bf11 commit cbecdf2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/settings/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def update
redirect_to [:settings, @user], notice: t(".reset_link_sent")
elsif params[:approve]
@user.update(approved: true)
UserMailer.with(user: @user).account_approved.deliver_later if SiteSettings.email_configured?
redirect_to [:settings, @user], notice: t(".approved")
elsif @user.update(user_params)
redirect_to [:settings, @user], notice: t(".success")
Expand Down
6 changes: 6 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UserMailer < ApplicationMailer
def account_approved
@user = params[:user]
mail to: @user.email
end
end
3 changes: 3 additions & 0 deletions app/views/user_mailer/account_approved.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= translate(".greeting") %>
<%= translate(".message", link: new_user_session_url) %>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ en:
myminifactory: MyMiniFactory
theminiindex: The Mini Index
thingiverse: Thingiverse
user_mailer:
account_approved:
subject: Account approved
greeting: Hi!
message: Your account has been approved; you may now sign in at %{link}.
views:
pagination:
first: "« First"
Expand Down
20 changes: 20 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "rails_helper"

RSpec.describe UserMailer do
describe "account_approved" do
let(:user) { create(:user) }
let(:mail) { described_class.with(user: user).account_approved }

it "sets correct subject" do
expect(mail.subject).to eq("Account approved")
end

it "sends to user" do
expect(mail.to).to eq([user.email])
end

it "renders the body" do
expect(mail.body.encoded).to match("Hi")
end
end
end

0 comments on commit cbecdf2

Please sign in to comment.