Skip to content

Commit

Permalink
Implement dashboard setting for defining inactivity duration leading …
Browse files Browse the repository at this point in the history
…to user ban
  • Loading branch information
AlexanderUngefug committed Jun 13, 2024
1 parent b4e507c commit 5763f42
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/assets/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@
"allow_users_to_preupload_presentation": "Präsentationen können hochgeladen werden",
"allow_users_to_preupload_presentation_description": "Nutzer:innen können eine Präsentation im Voraus hochladen, die dann als Standard für diesen Raum genutzt wird.",
"activate_automated_deletion_of_expired_rooms": "Automatisches Löschen von abgelaufenen Räumen",
"activate_automated_deletion_of_expired_rooms_description": "Wenn das aktiviert ist, werden Räume automatisch gelöscht, wenn das Löschdatum erreicht ist."
"activate_automated_deletion_of_expired_rooms_description": "Wenn das aktiviert ist, werden Räume automatisch gelöscht, wenn das Löschdatum erreicht ist.",
"set_automated_ban_time_from_inactive_users": "Automatische Sperrung von inaktiven Nutzer:innen",
"set_automated_ban_time_from_inactive_users_description": "Nutzer:innen werden automatisch gesperrt, wenn sie sich für die angegebene Anzahl an Tagen nicht einloggen. 0 deaktiviert diese Funktion."
},
"registration": {
"registration": "Registrierung",
Expand Down
4 changes: 3 additions & 1 deletion app/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@
"allow_users_to_preupload_presentation": "Allow Users to Preupload Presentations",
"allow_users_to_preupload_presentation_description": "Users can preupload a presentation to be used as the default presentation for that specific room",
"activate_automated_deletion_of_expired_rooms": "Automated Deletion of Expired Rooms",
"activate_automated_deletion_of_expired_rooms_description": "Automatically delete rooms that have expired based on the room deletion date"
"activate_automated_deletion_of_expired_rooms_description": "Automatically delete rooms that have expired based on the room deletion date",
"set_automated_ban_time_from_inactive_users": "Automated Ban Time from Inactive Users",
"set_automated_ban_time_from_inactive_users_description": "Automatically ban users that have been inactive for a certain amount of time in days. Set to 0 to disable"
},
"registration": {
"registration": "Registration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function SettingsRow({

return (
<Stack direction="horizontal">
<Stack>
<Stack className='pe-2'>
<strong> {title} </strong>
{description}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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/>.

import React from 'react';
import PropTypes from 'prop-types';
import { Stack } from 'react-bootstrap';
import useUpdateSiteSetting from '../../../hooks/mutations/admin/site_settings/useUpdateSiteSetting';

export default function SettingsRow({
name, title, description, value,
}) {
const updateSiteSetting = useUpdateSiteSetting(name);

return (
<Stack direction="horizontal">
<Stack className='pe-2'>
<strong> {title} </strong>
{description}
</Stack>
<div className="">
<input
className="room-limit fs-5"
type="number"
min='0'
value={value}
onChange={(event) => {
updateSiteSetting.mutate({ value: event.target.value });
}}
/>
</div>
</Stack>
);
}

SettingsRow.defaultProps = {
value: '',
};

SettingsRow.propTypes = {
name: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
description: PropTypes.node.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import useSiteSettings from '../../../../hooks/queries/admin/site_settings/useSiteSettings';
import SettingsRow from '../SettingsRow';
import SettingsRowNumberInput from '../SettingsRowNumberInput';

export default function Settings() {
const { t } = useTranslation();
const { data: siteSettings, isLoading } = useSiteSettings(['ShareRooms', 'PreuploadPresentation', 'AutomatedDeletionOfExpiredRooms']);
const { data: siteSettings, isLoading } = useSiteSettings(['ShareRooms', 'PreuploadPresentation', 'AutomatedDeletionOfExpiredRooms', 'AutomatedUserBanTime']);
if (isLoading) return null;

return (
Expand Down Expand Up @@ -56,6 +57,16 @@ export default function Settings() {
)}
value={siteSettings?.AutomatedDeletionOfExpiredRooms}
/>
<SettingsRowNumberInput
name="AutomatedUserBanTime"
title={t('admin.site_settings.settings.set_automated_ban_time_from_inactive_users')}
description={(
<p className="text-muted">
{t('admin.site_settings.settings.set_automated_ban_time_from_inactive_users_description')}
</p>
)}
value={siteSettings?.AutomatedUserBanTime}
/>
</>
);
}
29 changes: 29 additions & 0 deletions db/data/20240613166290_add_automated_user_ban_time_site_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 AddAutomatedUserBanTimeSiteSetting < ActiveRecord::Migration[7.1]
def up
setting = Setting.create!(name: 'AutomatedUserBanTime')
values = [{ provider: 'greenlight', setting_id: setting.id, value: '0' }]
SiteSetting.create! values
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
8 changes: 6 additions & 2 deletions lib/tasks/block_inactive_users.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace :users do
desc 'Block inactive Users'
task block_inactive: :environment do
days = ENV['USER_BLOCK_INACTIVITY'].to_i || 30
puts "A User is considered inactive if they have not logged in for #{days} days."
setting_id = Setting.find_by(name: 'AutomatedUserBanTime')&.id
days = SiteSetting.find_by(setting_id: setting_id)&.value.to_i
if days.nil? || days.zero?
puts 'Automated user blocking is disabled.'
next
end
inactive_users = User.where('users.status !=2 AND users.last_login < ?',
days.days.ago).or(User.where('users.status !=2 AND users.last_login IS NULL AND users.created_at < ?',
days.days.ago))
Expand Down

0 comments on commit 5763f42

Please sign in to comment.