Skip to content

Commit

Permalink
add rake task server_tags_sync to clear invalid/disallowed server tag…
Browse files Browse the repository at this point in the history
…s from the database (after changing the config)
  • Loading branch information
Ithanil committed May 14, 2024
1 parent 97a49e7 commit f52b4ba
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 45 additions & 0 deletions lib/tasks/server_tags_sync.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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

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)
role_not_allowed = Rails.configuration.server_tag_roles.key?(tag_value) && Rails.configuration.server_tag_roles[tag_value].exclude?(role_id)
tag_invalid = true if role_not_allowed
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
3 changes: 2 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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)

0 comments on commit f52b4ba

Please sign in to comment.