GRN2-140: Added Email to inform user they've been promoted (#534)

* Added Email to inform user they've been promoted

* Update user_mailer.rb

* Send email when a user is demoted

* Change more-info string
v2
shawn-higgins1 4 years ago committed by Jesus Federico
parent 9638ebcbc5
commit 83a9edf81d
  1. 6
      app/controllers/admins_controller.rb
  2. 8
      app/controllers/concerns/emailer.rb
  3. 16
      app/mailers/user_mailer.rb
  4. 39
      app/views/user_mailer/user_demoted.html.erb
  5. 26
      app/views/user_mailer/user_demoted.text.erb
  6. 39
      app/views/user_mailer/user_promoted.html.erb
  7. 26
      app/views/user_mailer/user_promoted.text.erb
  8. 10
      config/locales/en.yml
  9. 18
      spec/controllers/admins_controller_spec.rb
  10. 20
      test/mailers/previews/user_mailer_preview.rb

@ -48,12 +48,18 @@ class AdminsController < ApplicationController
# POST /admins/promote/:user_uid
def promote
@user.add_role :admin
send_user_promoted_email(@user)
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.promoted") }
end
# POST /admins/demote/:user_uid
def demote
@user.remove_role :admin
send_user_demoted_email(@user)
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.demoted") }
end

@ -31,6 +31,14 @@ module Emailer
UserMailer.password_reset(@user, reset_link, logo_image, user_color).deliver_now
end
def send_user_promoted_email(user)
UserMailer.user_promoted(user, root_url, logo_image, user_color).deliver_now
end
def send_user_demoted_email(user)
UserMailer.user_demoted(user, root_url, logo_image, user_color).deliver_now
end
# Sends inivitation to join
def send_invitation_email(name, email, token)
@token = token

@ -35,6 +35,22 @@ class UserMailer < ApplicationMailer
mail to: user.email, subject: t('reset_password.subtitle')
end
def user_promoted(user, url, image, color)
@url = url
@admin_url = url + "admins"
@image = image
@color = color
mail to: user.email, subject: t('mailer.user.promoted.subtitle')
end
def user_demoted(user, url, image, color)
@url = url
@root_url = url
@image = image
@color = color
mail to: user.email, subject: t('mailer.user.demoted.subtitle')
end
def invite_email(name, email, url, image, color)
@name = name
@email = email

@ -0,0 +1,39 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<div style="text-align:center; font-family:'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif">
<div style="display:inline-block; background-color:#F5F7FB; border:1px solid #d3d3d3; padding: 25px 70px; width: 50%">
<%= image_tag(@image, height: '70') %>
<h1 style="margin-bottom:30px">
<%= t('mailer.user.demoted.subtitle') %>
</h1>
<p>
<%= t('mailer.user.demoted.info', url: @url) %>
</p>
<p style="margin-bottom:45px;">
<%= t('mailer.user.demoted.more-info') %>
</p>
<a style="background: <%= @color %>;color: #ffffff; padding: 10px 15px; box-shadow: 0 2px 4px 0 rgba(0,0,0,.25);border: 1px solid transparent;text-decoration:none;" href="<%= @root_url %>">
<%= t('mailer.user.demoted.root_link') %>
</a>
</div>
</div>

@ -0,0 +1,26 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<%= t('mailer.user.demoted.subtitle') %>
<%= t('mailer.user.demoted.info', url: @url) %>
<%= t('mailer.user.demoted.more-info') %>
<%= @root_url %>

@ -0,0 +1,39 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<div style="text-align:center; font-family:'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif">
<div style="display:inline-block; background-color:#F5F7FB; border:1px solid #d3d3d3; padding: 25px 70px; width: 50%">
<%= image_tag(@image, height: '70') %>
<h1 style="margin-bottom:30px">
<%= t('mailer.user.promoted.subtitle') %>
</h1>
<p>
<%= t('mailer.user.promoted.info', url: @url) %>
</p>
<p style="margin-bottom:45px;">
<%= t('mailer.user.promoted.more-info') %>
</p>
<a style="background: <%= @color %>;color: #ffffff; padding: 10px 15px; box-shadow: 0 2px 4px 0 rgba(0,0,0,.25);border: 1px solid transparent;text-decoration:none;" href="<%= @admin_url %>">
<%= t('mailer.user.promoted.admins_link') %>
</a>
</div>
</div>

@ -0,0 +1,26 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<%= t('mailer.user.promoted.subtitle') %>
<%= t('mailer.user.promoted.info', url: @url) %>
<%= t('mailer.user.promoted.more-info') %>
<%= @admin_url %>

@ -179,6 +179,11 @@ en:
signin_link: Sign In
subject: Account Approved
username: Your username is %{email}.
demoted:
info: You are no longer an administrator on %{url}.
more-info: You now have the same privileges as a regular user and will no longer be able to access any of the Administrator settings.
root_link: Visit the Organization Page
subtitle: Administrator Rights Rescinded
invite:
info: You have been invited to your own personal space by %{name}
signup: To signup using your email, click the button below and follow the steps.
@ -192,6 +197,11 @@ en:
reset_link: Reset Password
expire: This link will expire in two hours.
ignore: You can safely ignore this email if you did not request a password reset.
promoted:
admins_link: Visit the Organization Page
info: You are now an administrator on %{url}.
more-info: As an administrator, you can manage users, their role and configure your site settings by changing the logo and brand colour.
subtitle: Administrator Rights Granted
verify_email:
welcome: Welcome to your personal space, %{name}!
success: Leveraging %{bigbluebutton}, you can create your own rooms to host sessions and collaborate with others.

@ -64,6 +64,14 @@ describe AdminsController, type: :controller do
expect(flash[:success]).to be_present
expect(response).to redirect_to(admins_path)
end
it "sends an email to the user being promoted" do
@request.session[:user_id] = @admin.id
params = { user_uid: @user.uid }
expect { post :promote, params: params }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context "POST #demote" do
@ -79,6 +87,16 @@ describe AdminsController, type: :controller do
expect(flash[:success]).to be_present
expect(response).to redirect_to(admins_path)
end
it "sends an email to the user being demoted" do
@request.session[:user_id] = @admin.id
@user.add_role :admin
params = { user_uid: @user.uid }
expect { post :demote, params: params }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context "POST #ban" do

@ -35,4 +35,24 @@ class UserMailerPreview < ActionMailer::Preview
user = User.first
UserMailer.approve_user(user, "http://example.com/", @logo, @color)
end
# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/user_promoted
def user_promoted
user = User.first
url = "http://example.com"
logo_image = "https://raw.githubusercontent.com/bigbluebutton/greenlight/master/app/assets/images/logo_with_text.png"
user_color = "#467fcf"
UserMailer.user_promoted(user, url, logo_image, user_color)
end
# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/user_demoted
def user_demoted
user = User.first
url = "http://example.com"
logo_image = "https://raw.githubusercontent.com/bigbluebutton/greenlight/master/app/assets/images/logo_with_text.png"
user_color = "#467fcf"
UserMailer.user_demoted(user, url, logo_image, user_color)
end
end