Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new role permission for receiving an email on user signup #5529

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@
"manage_site_settings": "Allow users with this role to manage site settings",
"manage_roles": "Allow users with this role to edit other roles",
"shared_list": "Include users with this role in the dropdown for sharing rooms",
"room_limit": "Room Limit"
"room_limit": "Room Limit",
"email_on_signup": "Receive an email when a new user signs up"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def create
UserMailer.with(user:,
activation_url: activate_account_url(token), base_url: request.base_url,
provider: current_provider).activate_account_email.deliver_later

UserMailer.with(user:, admin_panel_url:, provider: current_provider)
.new_user_signup_email.deliver_later
end

create_default_room(user)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/concerns/client_routable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ def reset_password_url(token)
def pending_path
"#{root_path}pending"
end

def admin_panel_url
"#{root_url}admin/users"
end
end
7 changes: 7 additions & 0 deletions app/javascript/components/admin/roles/forms/EditRoleForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ export default function EditRoleForm({ role }) {
defaultValue={rolePermissions?.SharedList === 'true'}
/>

<RolePermissionRow
permissionName="EmailOnSignup"
description={t('admin.roles.edit.email_on_signup')}
roleId={role?.id}
defaultValue={rolePermissions?.EmailOnSignup === 'true'}
/>

<Form methods={methodsLimit} onBlur={methodsLimit.handleSubmit(updatePermissionAPI.mutate)}>
<Stack direction="horizontal">
<div className="text-muted me-auto">
Expand Down
21 changes: 20 additions & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ def invitation_email
@email = params[:email]
@name = params[:name]
@signup_url = params[:signup_url]
@email = params[:email]

mail(to: @email, subject: t('email.invitation.invitation_to_join'))
end

def new_user_signup_email
@user = params[:user]
@admin_panel_url = params[:admin_panel_url]
emails = admin_emails

return if emails.blank? # Dont send anything if no-one has EmailOnSignup enabled

mail(to: emails, subject: t('email.new_user_signup.new_user'))
end

private

def preset
Expand All @@ -59,4 +68,14 @@ def branding
@brand_image = ActionController::Base.helpers.image_url(branding_hash['BrandingImage'], host: @base_url)
@brand_color = branding_hash['PrimaryColor']
end

def admin_emails
# Find all the roles that have EmailOnSignup enabled
role_ids = Role.joins(role_permissions: :permission)
.with_provider(@provider)
.where(role_permissions: { value: 'true' }, permission: { name: 'EmailOnSignup' })
.pluck(:id)

User.where(role_id: role_ids).pluck(:email)
end
end
30 changes: 30 additions & 0 deletions app/views/user_mailer/new_user_signup_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.-->

<!--Copyright (c) 2022 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.-->

<!--Greenlight 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 Greenlight; if not, see <http://www.gnu.org/licenses/>.-->

<div style="padding-left: 80px; padding-right: 80px;">
<p style="font-size: 40px; margin-bottom: 20px; font-weight: 600;"><%= t('email.new_user_signup.new_user') %></p>

<p style="font-size: 24px;"><%= t('email.new_user_signup.new_user_description') %></p>

<p style="font-size: 20px;"><%= t('email.new_user_signup.name', name: @user.name) %></p>
<p style="font-size: 20px;"><%= t('email.new_user_signup.email', email: @user.email) %></p>

<p style="font-size: 24px;"><%= t('email.new_user_signup.take_action') %></p>

<a href="<%= @signup_url %>" target="_blank" style="background-color: <%= @brand_color %>; border-radius: 8px; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; font-weight: 600; margin-top: 16px; margin-bottom: 64px;">
<%= t('email.new_user_signup.admin_panel') %>
</a>
</div>
26 changes: 26 additions & 0 deletions app/views/user_mailer/new_user_signup_email.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) 2022 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.

Greenlight 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 Greenlight; if not, see http://www.gnu.org/licenses/.
%>

---
<%= t('email.new_user_signup.new_user') %>
<%= t('email.new_user_signup.new_user_description' %>
<%= t('email.new_user_signup.name', name: @user.name) %>
<%= t('email.new_user_signup.email', email: @user.email) %>
<%= t('email.new_user_signup.take_action') %>
<%= @signup_url %>
---
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ en:
get_started: To sign up, please click the button below and follow the steps.
valid_invitation: The invitation is valid for 24 hours.
sign_up: Sign Up
new_user_signup:
new_user: New User Signup
new_user_description: A new user has signed up to use BigBlueButton.
name: "Name: %{name}"
email: "Email: %{email}"
admin_panel: "Administrator Panel"
take_action: "To view the new user or to take the necessary action, visit the Administrator Panel"
reset:
password_reset: Reset Password
password_reset_requested: A password reset has been requested for %{email}.
Expand Down
36 changes: 36 additions & 0 deletions db/data/20231117151542_add_email_on_sign_up_permission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2022 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.
#
# Greenlight 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 Greenlight; if not, see <http://www.gnu.org/licenses/>.

# frozen_string_literal: true

class AddEmailOnSignUpPermission < ActiveRecord::Migration[7.1]
def up
email_permission = Permission.create!(name: 'EmailOnSignup')
admin = Role.find_by(name: 'Administrator')

values = [{ role: admin, permission: email_permission, value: 'true' }]

Role.where.not(name: 'Administrator').each do |role|
values.push({ role:, permission: email_permission, value: 'false' })
end

RolePermission.create! values
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataMigrate::Data.define(version: 20231030185844)
DataMigrate::Data.define(version: 20231117151542)
10 changes: 10 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
expect(User.find_by(email: user_params[:user][:email]).role.name).to eq('User')
end

context 'EmailOnSignup' do
it 'emails all admins that a new user has signed up' do
post :create, params: user_params

expect(ActionMailer::MailDeliveryJob).to have_been_enqueued
.at(:no_wait).exactly(:once)
.with('UserMailer', 'new_user_signup_email', 'deliver_now', Hash)
end
end

context 'User language' do
it 'Persists the user language in the user record' do
post :create, params: user_params
Expand Down
6 changes: 6 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ def invitation_email

UserMailer.with(user: fake_user.new('user', 'user@users'), invitation_url: 'https://example.com/invite').invitation_email
end

def new_user_signup_email
fake_user = Struct.new(:name, :email)

UserMailer.with(user: fake_user.new('user', 'user@users')).new_user_signup_email
end
end