-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Scalelite Tagged Servers (#5790)
* init server tags prototype with config variable and corresponding dropdown in room settings * moved ServerTag row to separate file + rubocop * eslint happiness * add db migration for room option meta_server-tag * split the meta_server-tag parameter into two 'virtual' room options in GL: serverTag and serverTagRequired * dynamically render the server tag Dropdown from the config string + hide it entirely when the string is empty * now actually reflect and mutate the serverTag setting in DB via the Dropdown selection + tweaks&fixes * now use server tag room option as actual parameter on create call * rename config SERVER_TAGS_MAP->SERVER_TAG_NAMES and now handle it in Rails config * add config variable for tags<->roles and document the full server tag config in sample.env * fully implemented the tag<->role restriction as per config variable * add configurable default tag name for untagged servers * added checkbox to set if server tag is required * add logic to handle serverTagRequired in meeting_starter service * rubocop + change tagRequired toggle to react-bootstrap Radio buttons inside Cols * eslint + add description above server tag row * make tags Dropdown drop up + cleanpu * finalized DB migration for the server tags options * final polish (including translated strings) * add rake task server_tags_sync to clear invalid/disallowed server tags from the database (after changing the config) * adds translated string for default tag name / DEFAULT_TAG_NAME env now serves as override * show a specific error message when a required server type is unavailable (based on blindsidenetworks/scalelite#1091) * move tag fetching logic from CurrentUserSerializer to new ServerTagsController * refactor ServerTagRow and remove tags-related env variables completely from react * remove DEFAULT_TAG_NAME from sample.env * now silently fall back to untagged if an invalid/forbidden tag is used in meeting_starter.rb (which matches what the user would see in terms of UI, namely the default tag name) * check room owner's role_id instead of current user's for role restrictions of tags / list of allowed tags * improve guarding for the cases of disabled tags or invalid room_ids in ServerTagsController * avoid checking serverTags.isLoading * streamline server tags migration * massively increase performance of server tags migration if database is in the expected state (i.e. no tags related options present) --------- Co-authored-by: Ahmad Farhat <[email protected]>
- Loading branch information
1 parent
77873eb
commit f123946
Showing
15 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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 | ||
|
||
module Api | ||
module V1 | ||
class ServerTagsController < ApiController | ||
# GET /api/v1/server_tags/:friendly_id | ||
# Returns a list of all allowed tags&names for the room's owner | ||
def show | ||
tag_names = Rails.configuration.server_tag_names | ||
tag_roles = Rails.configuration.server_tag_roles | ||
return render_data data: {}, status: :ok if tag_names.blank? | ||
|
||
room = Room.find_by(friendly_id: params[:friendly_id]) | ||
return render_data data: {}, status: :ok if room.nil? | ||
|
||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
app/javascript/components/rooms/room/room_settings/ServerTagRow.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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 { useTranslation } from 'react-i18next'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Row, Col, Dropdown, ButtonGroup, ToggleButton, | ||
} from 'react-bootstrap'; | ||
import SimpleSelect from '../../../shared_components/utilities/SimpleSelect'; | ||
|
||
export default function ServerTagRow({ | ||
updateMutation: useUpdateAPI, currentTag, tagRequired, serverTags, description, | ||
}) { | ||
const updateAPI = useUpdateAPI(); | ||
const { t } = useTranslation(); | ||
|
||
function getDefaultTagName() { | ||
return t('room.settings.default_tag_name'); | ||
} | ||
|
||
function getTagName(tag) { | ||
if (tag in serverTags) { | ||
return serverTags[tag]; | ||
} | ||
return getDefaultTagName(); | ||
} | ||
|
||
const dropdownTags = Object.entries(serverTags).map(([tagString, tagName]) => ( | ||
( | ||
<Dropdown.Item | ||
key={tagString} | ||
value={tagName} | ||
onClick={() => updateAPI.mutate({ settingName: 'serverTag', settingValue: tagString })} | ||
> | ||
{tagName} | ||
</Dropdown.Item> | ||
) | ||
)); | ||
|
||
return ( | ||
<Row> | ||
<h6 className="text-brand">{description}</h6> | ||
<Col> | ||
<SimpleSelect defaultValue={getTagName(currentTag)} dropUp> | ||
{[ | ||
<Dropdown.Item | ||
key="" | ||
value={getDefaultTagName()} | ||
disabled={updateAPI.isLoading} | ||
onClick={() => updateAPI.mutate({ settingName: 'serverTag', settingValue: '' })} | ||
> | ||
{getDefaultTagName()} | ||
</Dropdown.Item>, | ||
].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> | ||
</Row> | ||
); | ||
} | ||
|
||
ServerTagRow.defaultProps = { | ||
currentTag: '', | ||
tagRequired: false, | ||
}; | ||
|
||
ServerTagRow.propTypes = { | ||
updateMutation: PropTypes.func.isRequired, | ||
currentTag: PropTypes.string, | ||
tagRequired: PropTypes.bool, | ||
serverTags: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
description: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 useServerTags(friendlyId) { | ||
return useQuery( | ||
['getServerTags', friendlyId], | ||
() => axios.get(`/server_tags/${friendlyId}.json`).then((resp) => resp.data.data), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# 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 CreateServerTagsOption < ActiveRecord::Migration[7.0] | ||
def up | ||
MeetingOption.create!(name: 'serverTag', default_value: '') unless MeetingOption.exists?(name: 'serverTag') | ||
tag_option = MeetingOption.find_by!(name: 'serverTag') | ||
MeetingOption.create!(name: 'serverTagRequired', default_value: 'false') unless MeetingOption.exists?(name: 'serverTagRequired') | ||
tag_required_option = MeetingOption.find_by!(name: 'serverTagRequired') | ||
|
||
unless RoomsConfiguration.exists?(meeting_option: tag_option, provider: 'greenlight') | ||
RoomsConfiguration.create!(meeting_option: tag_option, value: 'optional', provider: 'greenlight') | ||
end | ||
unless RoomsConfiguration.exists?(meeting_option: tag_required_option, provider: 'greenlight') | ||
RoomsConfiguration.create!(meeting_option: tag_required_option, value: 'optional', provider: 'greenlight') | ||
end | ||
Tenant.all.each do |tenant| | ||
unless RoomsConfiguration.exists?(meeting_option: tag_option, provider: tenant.name) | ||
RoomsConfiguration.create!(meeting_option: tag_option, value: 'optional', provider: tenant.name) | ||
end | ||
unless RoomsConfiguration.exists?(meeting_option: tag_required_option, provider: tenant.name) | ||
RoomsConfiguration.create!(meeting_option: tag_required_option, value: 'optional', provider: tenant.name) | ||
end | ||
end | ||
|
||
if RoomMeetingOption.exists?(meeting_option: tag_option) || RoomMeetingOption.exists?(meeting_option: tag_required_option) | ||
# slow variant that works with existing tag options | ||
Room.find_each do |room| | ||
RoomMeetingOption.find_or_create_by!(room:, meeting_option: tag_option) | ||
unless RoomMeetingOption.exists?(room:, meeting_option: tag_required_option) | ||
RoomMeetingOption.create!(room:, meeting_option: tag_required_option, value: 'false') | ||
end | ||
end | ||
else | ||
# much faster variant without checks/validation | ||
Room.find_in_batches do |batch| | ||
tag_options_batch = batch.map { |room| { room_id: room.id, meeting_option_id: tag_option.id } } | ||
tag_required_options_batch = batch.map { |room| { room_id: room.id, meeting_option_id: tag_required_option.id, value: 'false' } } | ||
# rubocop:disable Rails/SkipsModelValidations | ||
RoomMeetingOption.insert_all!(tag_options_batch) | ||
RoomMeetingOption.insert_all!(tag_required_options_batch) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
end | ||
end | ||
|
||
def down | ||
tag_option = MeetingOption.find_by!(name: 'serverTag') | ||
RoomMeetingOption.destroy_by(meeting_option: tag_option) | ||
RoomsConfiguration.destroy_by(meeting_option: tag_option) | ||
tag_option.destroy | ||
|
||
tag_required_option = MeetingOption.find_by!(name: 'serverTagRequired') | ||
RoomMeetingOption.destroy_by(meeting_option: tag_required_option) | ||
RoomsConfiguration.destroy_by(meeting_option: tag_required_option) | ||
tag_required_option.destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20240209155229) | ||
DataMigrate::Data.define(version: 20240423162700) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ esbuild.context({ | |
}).catch((e) => { | ||
console.error('build failed:', e); | ||
process.exit(1) | ||
}) | ||
}) |
Oops, something went wrong.