From 1ab220170e27365071a0ec865dd4239937f0a4c4 Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Mon, 6 May 2024 17:10:39 +0200 Subject: [PATCH] add rake task server_tags_sync to clear invalid/disallowed server tags from the database (after changing the config) --- lib/tasks/server_tags_sync.rake | 46 +++++++++++++++++++++++++++++++++ sample.env | 3 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/server_tags_sync.rake diff --git a/lib/tasks/server_tags_sync.rake b/lib/tasks/server_tags_sync.rake new file mode 100644 index 00000000000..db70ca278f1 --- /dev/null +++ b/lib/tasks/server_tags_sync.rake @@ -0,0 +1,46 @@ +# 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 . + +# frozen_string_literal: true + +desc 'Remove dismissed or disallowed server tags from database' + +task server_tags_sync: :environment do + tag_option = MeetingOption.find_by!(name: 'serverTag') + + RoomMeetingOption.where(meeting_option: tag_option).find_each do |room_tag| + tag_value = room_tag.value + next if tag_value.blank? + + role_id = room_tag.room.user.role_id + tag_invalid = false + if Rails.configuration.server_tag_names.key?(tag_value) + if Rails.configuration.server_tag_roles.key?(tag_value) && Rails.configuration.server_tag_roles[tag_value].exclude?(role_id) + tag_invalid = true + end + else + tag_invalid = true + end + + if tag_invalid + info "Clearing invalid server tag #{tag_value} for room with id #{room_tag.room}." + room_tag.update(value: '') + end + rescue StandardError => e + err "Unable to sync server tag of room:\nID: #{room_tag.room}\nError: #{e}" + end + success 'Successfully sanitized server tags.' +end diff --git a/sample.env b/sample.env index 7b2e391ec39..5b5dc78effe 100644 --- a/sample.env +++ b/sample.env @@ -101,7 +101,8 @@ LOG_LEVEL=info ## Support for Tagged Servers # If your Greenlight instance is connected to Scalelite or another Loadbalancer with enabled support for the 'meta_server-tag' # parameter on create calls, you can use the following variables to configure support for this feature via the Greenlight UI. -# Example (delimiters are , : and /): +# When this configuration is changed later, disallowed tags can be removed from the DB via `bundle exec rake server_tags_sync` +# Example configuration (delimiters are , : and /): # DEFAULT_TAG_NAME=Standard # friendly name for the untagged/default servers # SERVER_TAG_NAMES=tag1:Name 1,tag2:Name2 # defines available tags and their friendly names # SERVER_TAG_ROLES=tag2:xyz-123-321-aaaa-zyx/abc-321-123-zzzz-cba # allow tag only for given role ids (see role ids in DB)