Skip to content

Commit

Permalink
Add admin email notification when new account is created
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel committed Nov 24, 2023
1 parent 6c6b6c3 commit 01585cb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def create
account = Account.create! account_params.merge(owner: current_user, users: [current_user])
current_user.update! role: :investor
investor = Investor.create! investor_params.merge(account: account)
Admin.all.each { |admin| AdminMailer.investor_created(admin, investor).deliver_later }
render json: InvestorSerializer.new(
investor,
params: {current_user: current_user, current_ability: current_ability}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def create
account = Account.create! account_params.merge(owner: current_user, users: [current_user])
current_user.update! role: :project_developer
project_developer = ProjectDeveloper.create! project_developer_params.merge(account: account)
Admin.all.each { |admin| AdminMailer.project_developer_created(admin, project_developer).deliver_later }
render json: ProjectDeveloperSerializer.new(
project_developer,
params: {current_user: current_user, current_ability: current_ability}
Expand Down
18 changes: 18 additions & 0 deletions backend/app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ def first_time_login_instructions(admin)
end
end

def project_developer_created(admin, project_developer)
@admin = admin
@project_developer = project_developer

I18n.with_locale admin.locale do
mail to: admin.email
end
end

def investor_created(admin, investor)
@admin = admin
@investor = investor

I18n.with_locale admin.locale do
mail to: admin.email
end
end

private

def set_reset_password_token(admin)
Expand Down
3 changes: 3 additions & 0 deletions backend/app/views/admin_mailer/investor_created.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h3><%= t "admin_mailer.greetings", full_name: @admin.full_name %></h3>
<p><%= t "admin_mailer.investor_created.content_html", new_investor_url: link_to(backoffice_investor_url(@investor)) %></p>
<p><%= t "admin_mailer.farewell_html" %></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h3><%= t "admin_mailer.greetings", full_name: @admin.full_name %></h3>
<p><%= t "admin_mailer.project_developer_created.content_html", new_pd_url: link_to(backoffice_project_developer_url(@project_developer)) %></p>
<p><%= t "admin_mailer.farewell_html" %></p>
6 changes: 6 additions & 0 deletions backend/config/locales/zu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ zu:
subject: Your HeCo Invest Admin account was created!
content_html: "To login for first time, please %{reset_password_link}."
reset_password_link: setup your new password
investor_created:
subject: New Investor account created!
content_html: "A new Investor account has been created and needs your inspection for approval. Please, review the account: %{new_investor_url} "
project_developer_created:
subject: New Project developer account created!
content_html: "A new Project developer account has been created and needs your inspection for approval. Please, review the account: %{new_pd_url} "
project_developer_mailer:
greetings: Dear %{full_name},
farewell_html: Best Regards,<br />Your HeCo Invest Team
Expand Down
7 changes: 7 additions & 0 deletions backend/spec/requests/api/v1/accounts/investors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
expect(investor.public_send("#{attr}_#{investor_params[:language]}")).to eq(investor_params[attr])
end
end

it "queues email notification" do |example|
investor = Investor.find response_json["data"]["id"]
Admin.all.each do |admin|
expect(AdminMailer).to have_enqueued_mail(:investor_created).with(admin, investor)
end
end
end

response "422", "User already have account" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
submit_request example.metadata
}.to have_enqueued_job(TranslateJob).at_least(:once)
end

it "queues email notification" do |example|
submit_request example.metadata
project_developer = ProjectDeveloper.find response_json["data"]["id"]
Admin.all.each do |admin|
expect(AdminMailer).to have_enqueued_mail(:project_developer_created).with(admin, project_developer)
end
end
end

response "422", "User already have account" do
Expand Down

0 comments on commit 01585cb

Please sign in to comment.