Skip to content

Commit

Permalink
GRN2-140: Added Email to inform user they've been promoted (bigbluebu…
Browse files Browse the repository at this point in the history
…tton#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
  • Loading branch information
shawn-higgins1 authored and jfederico committed May 22, 2019
1 parent 9638ebc commit 83a9edf
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ def edit_user
# 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

Expand Down
8 changes: 8 additions & 0 deletions app/controllers/concerns/emailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def send_password_reset_email(user)
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
Expand Down
16 changes: 16 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def password_reset(user, url, image, color)
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
Expand Down
39 changes: 39 additions & 0 deletions app/views/user_mailer/user_demoted.html.erb
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions app/views/user_mailer/user_demoted.text.erb
Original file line number Diff line number Diff line change
@@ -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 %>
39 changes: 39 additions & 0 deletions app/views/user_mailer/user_promoted.html.erb
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions app/views/user_mailer/user_promoted.text.erb
Original file line number Diff line number Diff line change
@@ -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 %>
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/admins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
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
Expand All @@ -79,6 +87,16 @@
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
Expand Down
20 changes: 20 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@ def approve_user
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

0 comments on commit 83a9edf

Please sign in to comment.