From 83a9edf81ddd573684af6140bf61bc4ba26a35ff Mon Sep 17 00:00:00 2001
From: shawn-higgins1 <23224097+shawn-higgins1@users.noreply.github.com>
Date: Wed, 22 May 2019 13:36:33 -0400
Subject: [PATCH] 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
---
app/controllers/admins_controller.rb | 6 +++
app/controllers/concerns/emailer.rb | 8 ++++
app/mailers/user_mailer.rb | 16 ++++++++
app/views/user_mailer/user_demoted.html.erb | 39 ++++++++++++++++++++
app/views/user_mailer/user_demoted.text.erb | 26 +++++++++++++
app/views/user_mailer/user_promoted.html.erb | 39 ++++++++++++++++++++
app/views/user_mailer/user_promoted.text.erb | 26 +++++++++++++
config/locales/en.yml | 10 +++++
spec/controllers/admins_controller_spec.rb | 18 +++++++++
test/mailers/previews/user_mailer_preview.rb | 20 ++++++++++
10 files changed, 208 insertions(+)
create mode 100644 app/views/user_mailer/user_demoted.html.erb
create mode 100644 app/views/user_mailer/user_demoted.text.erb
create mode 100644 app/views/user_mailer/user_promoted.html.erb
create mode 100644 app/views/user_mailer/user_promoted.text.erb
diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb
index 97b03f0d..4c0600f8 100644
--- a/app/controllers/admins_controller.rb
+++ b/app/controllers/admins_controller.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
diff --git a/app/controllers/concerns/emailer.rb b/app/controllers/concerns/emailer.rb
index c4a22e83..3b2fba4d 100644
--- a/app/controllers/concerns/emailer.rb
+++ b/app/controllers/concerns/emailer.rb
@@ -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
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 7f911b6b..b20b553c 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -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
diff --git a/app/views/user_mailer/user_demoted.html.erb b/app/views/user_mailer/user_demoted.html.erb
new file mode 100644
index 00000000..21c18b93
--- /dev/null
+++ b/app/views/user_mailer/user_demoted.html.erb
@@ -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 .
+%>
+
+
+
+ <%= image_tag(@image, height: '70') %>
+
+
+ <%= t('mailer.user.demoted.subtitle') %>
+
+
+
+ <%= t('mailer.user.demoted.info', url: @url) %>
+
+
+
+ <%= t('mailer.user.demoted.more-info') %>
+
+
+
+ <%= t('mailer.user.demoted.root_link') %>
+
+
+
diff --git a/app/views/user_mailer/user_demoted.text.erb b/app/views/user_mailer/user_demoted.text.erb
new file mode 100644
index 00000000..275ddb7d
--- /dev/null
+++ b/app/views/user_mailer/user_demoted.text.erb
@@ -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 .
+%>
+
+
+<%= t('mailer.user.demoted.subtitle') %>
+
+<%= t('mailer.user.demoted.info', url: @url) %>
+
+<%= t('mailer.user.demoted.more-info') %>
+
+<%= @root_url %>
diff --git a/app/views/user_mailer/user_promoted.html.erb b/app/views/user_mailer/user_promoted.html.erb
new file mode 100644
index 00000000..9121af0a
--- /dev/null
+++ b/app/views/user_mailer/user_promoted.html.erb
@@ -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 .
+%>
+
+
+
+ <%= image_tag(@image, height: '70') %>
+
+
+ <%= t('mailer.user.promoted.subtitle') %>
+
+
+
+ <%= t('mailer.user.promoted.info', url: @url) %>
+
+
+
+ <%= t('mailer.user.promoted.more-info') %>
+
+
+
+ <%= t('mailer.user.promoted.admins_link') %>
+
+
+
diff --git a/app/views/user_mailer/user_promoted.text.erb b/app/views/user_mailer/user_promoted.text.erb
new file mode 100644
index 00000000..f6af8fde
--- /dev/null
+++ b/app/views/user_mailer/user_promoted.text.erb
@@ -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 .
+%>
+
+
+<%= t('mailer.user.promoted.subtitle') %>
+
+<%= t('mailer.user.promoted.info', url: @url) %>
+
+<%= t('mailer.user.promoted.more-info') %>
+
+<%= @admin_url %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 68f4a159..376341a8 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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.
diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb
index 7359092c..05eac84a 100644
--- a/spec/controllers/admins_controller_spec.rb
+++ b/spec/controllers/admins_controller_spec.rb
@@ -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
diff --git a/test/mailers/previews/user_mailer_preview.rb b/test/mailers/previews/user_mailer_preview.rb
index 263eae53..74f437b4 100644
--- a/test/mailers/previews/user_mailer_preview.rb
+++ b/test/mailers/previews/user_mailer_preview.rb
@@ -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