Skip to content
Snippets Groups Projects
Unverified Commit 265ce2d8 authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

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

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

* Fix text email

* rubo
parent 6a766425
No related branches found
No related tags found
No related merge requests found
......@@ -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"
}
}
},
......
......@@ -76,6 +76,9 @@ module Api
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)
......
......@@ -33,4 +33,8 @@ module ClientRoutable
def pending_path
"#{root_path}pending"
end
def admin_panel_url
"#{root_url}admin/users"
end
end
......@@ -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">
......
......@@ -42,11 +42,20 @@ class UserMailer < ApplicationMailer
@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
......@@ -59,4 +68,14 @@ class UserMailer < ApplicationMailer
@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
<!--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>
<%#
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 %>
---
......@@ -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}.
......
# 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
DataMigrate::Data.define(version: 20231030185844)
DataMigrate::Data.define(version: 20231117151542)
......@@ -66,6 +66,16 @@ RSpec.describe Api::V1::UsersController, type: :controller do
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
......
......@@ -38,4 +38,10 @@ class UserMailerPreview < ActionMailer::Preview
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment