Skip to content

Commit

Permalink
Add global override for tag_required room setting (hiding the UI butt…
Browse files Browse the repository at this point in the history
…ons if used) (#5940)

* add basic backend support for globally configurable tag fallback mode

* add support for global tag fallback mode option in javascript (i.e. hide corresponding room config when override is set)

* handle tag fallback mode in meeting_starter + ensure consistent logic accross rails/js

* final round of fixes and polish
  • Loading branch information
Ithanil authored Feb 7, 2025
1 parent b85c7b6 commit 95c9d76
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 34 deletions.
6 changes: 6 additions & 0 deletions app/controllers/api/v1/server_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def show
allowed_tag_names = tag_names.reject { |tag, _| tag_roles.key?(tag) && tag_roles[tag].exclude?(room.user.role_id) }
render_data data: allowed_tag_names, status: :ok
end

# GET /api/v1/server_tags/fallback_mode.json
# Returns global tag fallback mode (user config or global desired/required)
def fallback_mode
render_data data: Rails.configuration.server_tag_fallback_mode, status: :ok
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import UpdateRoomNameForm from './forms/UpdateRoomNameForm';
import useRoom from '../../../../hooks/queries/rooms/useRoom';
import UnshareRoom from './UnshareRoom';
import useServerTags from '../../../../hooks/queries/rooms/useServerTags';
import useServerTagsFallbackMode from '../../../../hooks/queries/rooms/useServerTagsFallbackMode';
import ServerTagRow from './ServerTagRow';

export default function RoomSettings() {
Expand All @@ -44,6 +45,7 @@ export default function RoomSettings() {
const { data: roomConfigs } = useRoomConfigs();
const { data: room } = useRoom(friendlyId);
const { data: serverTags } = useServerTags(friendlyId);
const { data: serverTagsFallbackMode } = useServerTagsFallbackMode();

const updateMutationWrapper = () => useUpdateRoomSetting(friendlyId);
const deleteMutationWrapper = (args) => useDeleteRoom({ friendlyId, ...args });
Expand Down Expand Up @@ -75,6 +77,7 @@ export default function RoomSettings() {
currentTag={roomSetting?.data?.serverTag}
tagRequired={roomSetting?.data?.serverTagRequired === 'true'}
serverTags={serverTags}
fallbackMode={serverTagsFallbackMode}
description={t('room.settings.server_tag')}
/>
)}
Expand Down
69 changes: 36 additions & 33 deletions app/javascript/components/rooms/room/room_settings/ServerTagRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import SimpleSelect from '../../../shared_components/utilities/SimpleSelect';

export default function ServerTagRow({
updateMutation: useUpdateAPI, currentTag, tagRequired, serverTags, description,
updateMutation: useUpdateAPI, currentTag, tagRequired, serverTags, fallbackMode, description,
}) {
const updateAPI = useUpdateAPI();
const { t } = useTranslation();
Expand Down Expand Up @@ -68,38 +68,40 @@ export default function ServerTagRow({
].concat(dropdownTags)}
</SimpleSelect>
</Col>
<Col>
<ButtonGroup>
<ToggleButton
key="desired"
id="desired"
type="radio"
variant="outline-success"
name="radio"
checked={tagRequired === false}
disabled={updateAPI.isLoading}
onChange={() => {
updateAPI.mutate({ settingName: 'serverTagRequired', settingValue: false });
}}
>
{t('room.settings.server_tag_desired')}
</ToggleButton>
<ToggleButton
key="required"
id="required"
type="radio"
variant="outline-danger"
name="radio"
checked={tagRequired === true}
disabled={updateAPI.isLoading}
onChange={() => {
updateAPI.mutate({ settingName: 'serverTagRequired', settingValue: true });
}}
>
{t('room.settings.server_tag_required')}
</ToggleButton>
</ButtonGroup>
</Col>
{(fallbackMode !== 'desired' && fallbackMode !== 'required') && (
<Col>
<ButtonGroup>
<ToggleButton
key="desired"
id="desired"
type="radio"
variant="outline-success"
name="radio"
checked={tagRequired === false}
disabled={updateAPI.isLoading}
onChange={() => {
updateAPI.mutate({ settingName: 'serverTagRequired', settingValue: false });
}}
>
{t('room.settings.server_tag_desired')}
</ToggleButton>
<ToggleButton
key="required"
id="required"
type="radio"
variant="outline-danger"
name="radio"
checked={tagRequired === true}
disabled={updateAPI.isLoading}
onChange={() => {
updateAPI.mutate({ settingName: 'serverTagRequired', settingValue: true });
}}
>
{t('room.settings.server_tag_required')}
</ToggleButton>
</ButtonGroup>
</Col>
)}
</Row>
);
}
Expand All @@ -114,5 +116,6 @@ ServerTagRow.propTypes = {
currentTag: PropTypes.string,
tagRequired: PropTypes.bool,
serverTags: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
fallbackMode: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
};
25 changes: 25 additions & 0 deletions app/javascript/hooks/queries/rooms/useServerTagsFallbackMode.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 { useQuery } from 'react-query';
import axios from '../../../helpers/Axios';

export default function useServerTagsFallbackMode() {
return useQuery(
'getFallbackMode',
() => axios.get('/server_tags/fallback_mode.json').then((resp) => resp.data.data),
);
}
6 changes: 6 additions & 0 deletions app/services/meeting_starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def handle_server_tag(meeting_options:)
tag_roles = Rails.configuration.server_tag_roles
tag = meeting_options.delete('serverTag')
tag_required = meeting_options.delete('serverTagRequired')
# handle override modes
if Rails.configuration.server_tag_fallback_mode == 'required'
tag_required = 'true'
elsif Rails.configuration.server_tag_fallback_mode == 'desired'
tag_required = 'false'
end

if tag_names.key?(tag) && !(tag_roles.key?(tag) && tag_roles[tag].exclude?(@room.user.role_id))
tag_param = tag_required == 'true' ? "#{tag}!" : tag
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Application < Rails::Application
config.i18n.enforce_available_locales = false

# Handle server tag config
config.server_tag_fallback_mode = ENV.fetch('SERVER_TAG_FALLBACK_MODE', 'config')
config.server_tag_names = ENV.fetch('SERVER_TAG_NAMES', '').split(',').to_h { |pair| pair.split(':') }
config.server_tag_roles = ENV.fetch('SERVER_TAG_ROLES', '').split(',').to_h { |pair| pair.split(':') }
config.server_tag_roles = config.server_tag_roles.transform_values! { |v| v.split('/') }
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
resources :site_settings, only: :index
resources :rooms_configurations, only: %i[index show], param: :name
resources :locales, only: %i[index show], param: :name
resources :server_tags, only: :show, param: :friendly_id
resources :server_tags, only: :show, param: :friendly_id do
collection do
get '/fallback_mode', to: 'server_tags#fallback_mode'
end
end

namespace :admin do
resources :users, only: %i[update] do
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ LOG_LEVEL=info
# 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.
# When this configuration is changed later, disallowed tags can be removed from the DB via `bundle exec rake server_tags_sync`
# For more documentation on the feature, see here: https://github.com/blindsidenetworks/scalelite/blob/master/docs/tags-README.md
# Example configuration (delimiters are , : and /):
# 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)
# SERVER_TAG_FALLBACK_MODE=required # fallback mode, may be 'desired'/'required' (as global overrides), otherwise room config applies

0 comments on commit 95c9d76

Please sign in to comment.