Skip to content

Commit

Permalink
Implementation of the setting for notifications by automatically bloc…
Browse files Browse the repository at this point in the history
…king inactive users
  • Loading branch information
AlexanderUngefug committed Jun 12, 2024
1 parent f80168f commit 00dce12
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 42 deletions.
4 changes: 3 additions & 1 deletion app/assets/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@
"manage_site_settings": "Nutzer:innen mit dieser Rolle erlauben, die Webseiteneinstellungen zu verwalten",
"manage_roles": "Nutzer:innen mit dieser Rolle erlauben, andere Rollen zu bearbeiten",
"shared_list": "Nutzer:innen mit dieser Rolle in die Auswahlliste für die gemeinsame Nutzung von Räumen aufnehmen",
"room_limit": "Raumlimit"
"room_limit": "Raumlimit",
"email_on_signup": "E-Mail bei Registrierung eines Nutzers",
"email_on_automated_banned": "E-Mail bei automatischer Sperrung eines Nutzers"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion app/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@
"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",
"email_on_signup": "Receive an email when a new user signs up"
"email_on_signup": "Receive an email when a new user signs up",
"email_on_automated_banned": "Receive an email when a user is automatically banned due to inactivity"
}
}
},
Expand Down
37 changes: 22 additions & 15 deletions app/javascript/components/admin/roles/forms/EditRoleForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function EditRoleForm({ role }) {
return (
<div>
<Modal
modalButton={<Button variant="delete" className="float-end my-4"> { t('admin.roles.delete_role') } </Button>}
modalButton={<Button variant="delete" className="float-end my-4"> {t('admin.roles.delete_role')} </Button>}
body={<DeleteRoleForm role={role} />}
/>
</div>
Expand All @@ -68,7 +68,7 @@ export default function EditRoleForm({ role }) {
{
isLoadingRoomConfigs || isLoading
? (
// eslint-disable-next-line react/no-array-index-key
// eslint-disable-next-line react/no-array-index-key
[...Array(9)].map((val, idx) => <RolePermissionRowPlaceHolder key={idx} />)
)
: (
Expand All @@ -83,12 +83,12 @@ export default function EditRoleForm({ role }) {
defaultValue={rolePermissions?.CreateRoom === 'true'}
/>
{['optional', 'default_enabled'].includes(roomConfigs?.record) && (
<RolePermissionRow
permissionName="CanRecord"
description={t('admin.roles.edit.record')}
roleId={role?.id}
defaultValue={rolePermissions?.CanRecord === 'true'}
/>
<RolePermissionRow
permissionName="CanRecord"
description={t('admin.roles.edit.record')}
roleId={role?.id}
defaultValue={rolePermissions?.CanRecord === 'true'}
/>
)}
<RolePermissionRow
permissionName="ManageUsers"
Expand Down Expand Up @@ -116,12 +116,12 @@ export default function EditRoleForm({ role }) {
/>
{/* Don't show ManageRoles if current_user is editing their own role */}
{(currentUser.role.id !== role?.id) && (
<RolePermissionRow
permissionName="ManageRoles"
description={t('admin.roles.edit.manage_roles')}
roleId={role?.id}
defaultValue={rolePermissions?.ManageRoles === 'true'}
/>
<RolePermissionRow
permissionName="ManageRoles"
description={t('admin.roles.edit.manage_roles')}
roleId={role?.id}
defaultValue={rolePermissions?.ManageRoles === 'true'}
/>
)}
<RolePermissionRow
permissionName="SharedList"
Expand All @@ -137,6 +137,13 @@ export default function EditRoleForm({ role }) {
defaultValue={rolePermissions?.EmailOnSignup === 'true'}
/>

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

<Form methods={methodsLimit} onBlur={methodsLimit.handleSubmit(updatePermissionAPI.mutate)}>
<Stack direction="horizontal">
<div className="text-muted me-auto">
Expand All @@ -155,7 +162,7 @@ export default function EditRoleForm({ role }) {
</Form>
</div>
)
}
}

{
deleteRoleButton()
Expand Down
33 changes: 8 additions & 25 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def invitation_email
def new_user_signup_email
@user = params[:user]
@admin_panel_url = params[:admin_panel_url]
emails = admin_emails
emails = admin_emails('EmailOnSignup')

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

Expand All @@ -63,15 +63,11 @@ def new_user_signup_email

def inform_admins_blocked_users_inactivity_email
@user = params[:user]
Rails.logger.debug { "[UserMailer] Blocked user: #{@user.email}" }
emails = get_all_admin_emails
Rails.logger.debug { "[UserMailer] Admin emaild #{emails}" }
emails = admin_emails('EmailOnAutomatedBanned')

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

email = mail(to: emails, subject: t('email.blocked.account_blocked'))
if email.present?
Rails.logger.debug '[UserMailer] Email has been queued for delivery.'
else
Rails.logger.debug '[UserMailer] Failed to queue email for delivery.'
end
end

private
Expand All @@ -87,25 +83,12 @@ def branding
@brand_color = branding_hash['PrimaryColor']
end

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

User.where(role_id: role_ids).pluck(:email)
end

def get_all_admin_emails
# Find the role that corresponds to 'Administrator'
admin_role = Role.find_by(name: 'Administrator')

# Get all users with the 'Administrator' role
admins = User.where(role: admin_role)

# Return their email addresses
admin_emails = admins.pluck(:email)

admin_emails
end
end
36 changes: 36 additions & 0 deletions db/data/20240612116290_add_email_on_automated_banned_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 AddEmailOnAutomatedBannedPermission < ActiveRecord::Migration[7.1]
def up
email_permission = Permission.create!(name: 'EmailOnAutomatedBanned')
admin = Role.find_by(name: 'Administrator')

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

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

RolePermission.create! values
end

def down
raise ActiveRecord::IrreversibleMigration
end
end

0 comments on commit 00dce12

Please sign in to comment.