Skip to content

Commit

Permalink
Clean seperation of pr bigbluebutton#5068 (in backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianAppDev committed Jun 14, 2024
1 parent baab248 commit 245f76c
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 90 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create
room = Room.new(name: room_params[:name], user_id: room_params[:user_id])

if room.save
logger.info "room(friendly_id):#{room.friendly_id} created for user(id):#{room.user_id} with voice brige: #{room.voice_bridge}"
logger.info "room(friendly_id):#{room.friendly_id} created for user(id):#{room.user_id}"
render_data status: :created
else
render_error errors: room.errors.to_a, status: :bad_request
Expand Down Expand Up @@ -160,7 +160,7 @@ def find_room
end

def room_params
params.require(:room).permit(:name, :user_id, :voice_bridge, :presentation)
params.require(:room).permit(:name, :user_id, :presentation)
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module ApplicationHelper
def branding_image
asset_path = SettingGetter.new(setting_name: 'BrandingImage', provider: current_provider).call
asset_url(asset_path)
#"https://jobs.secunet.com/templates/secunet/images/secunet_logo.png"
end

def page_title
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/helpers/ICSDownloadHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const createICSContent = (name, room_name, url, voice_bridge, voice_bridge_phone
const createICSWithoutHTML = (name, room_name, url, voice_bridge, voice_bridge_phone_number, t) => {
let description = `\n\n${t('room.meeting.invite_to_meeting', { name })}\n\n${t('room.meeting.join_by_url')}:\n${url}\n`;

if (typeof voice_bridge !== 'undefined' && typeof voice_bridge_phone_number !== 'undefined') {
if (typeof voice_bridge !== 'undefined' || typeof voice_bridge_phone_number !== 'undefined') {
description += `\n${t('room.meeting.join_by_phone')}: ${voice_bridge_phone_number},,${voice_bridge}\nPIN: ${voice_bridge}`;
}

Expand Down
15 changes: 1 addition & 14 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ class Room < ApplicationRecord
validates :name, presence: true
validates :friendly_id, presence: true, uniqueness: true
validates :meeting_id, presence: true, uniqueness: true
validates :voice_bridge, uniqueness: true
validates :presentation,
content_type: Rails.configuration.uploads[:presentations][:formats],
size: { less_than: Rails.configuration.uploads[:presentations][:max_size] }

validates :name, length: { minimum: 2, maximum: 255 }
validates :recordings_processing, numericality: { only_integer: true, greater_than_or_equal_to: 0 }

before_validation :set_friendly_id, :set_meeting_id, :set_voice_brige, on: :create
before_validation :set_friendly_id, :set_meeting_id, on: :create
after_create :create_meeting_options

attr_accessor :shared, :active, :participants
Expand Down Expand Up @@ -100,16 +99,4 @@ def set_meeting_id
rescue StandardError
retry
end

# Create unique pin for voice brige max 10^5 - 10000 unique ids
def set_voice_brige
if Rails.application.config.voice_bridge_phone_number != nil
id = SecureRandom.random_number((10.pow(5)) - 1)
raise if Room.exists?(voice_bridge: id) || id < 10000

self.voice_bridge = id
end
rescue StandardError
retry
end
end
6 changes: 0 additions & 6 deletions app/serializers/room_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ class RoomSerializer < ApplicationSerializer
attributes :id, :name, :friendly_id, :online, :participants, :last_session

attribute :shared_owner, if: -> { object.shared }
attribute :voice_bridge, if: -> { Rails.application.config.voice_bridge_phone_number }
attribute :voice_bridge_phone_number, if: -> { Rails.application.config.voice_bridge_phone_number }

def shared_owner
object.user.name
end

def voice_bridge_phone_number
Rails.application.config.voice_bridge_phone_number
end
end
2 changes: 1 addition & 1 deletion app/services/meeting_starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(room:, base_url:, current_user:, provider:)

def call
# TODO: amir - Check the legitimately of the action.
options = RoomSettingsGetter.new(room_id: @room.id, provider: @room.user.provider, current_user: @current_user, only_bbb_options: true, voice_bridge: @room.voice_bridge).call
options = RoomSettingsGetter.new(room_id: @room.id, provider: @room.user.provider, current_user: @current_user, only_bbb_options: true).call
viewer_code = RoomSettingsGetter.new(
room_id: @room.id,
provider: @room.user.provider,
Expand Down
11 changes: 1 addition & 10 deletions app/services/room_settings_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ class RoomSettingsGetter
# Hash(`<option_name> => {'true' => <Postive>, 'false' => <Negative>})`
SPECIAL_OPTIONS = { 'guestPolicy' => { 'true' => 'ASK_MODERATOR', 'false' => 'ALWAYS_ACCEPT' } }.freeze

def initialize(room_id:, provider:, current_user:, settings: [], show_codes: false, only_enabled: false, only_bbb_options: false, voice_bridge: nil)
def initialize(room_id:, provider:, current_user:, settings: [], show_codes: false, only_enabled: false, only_bbb_options: false)
@current_user = current_user
@room_id = room_id
@only_bbb_options = only_bbb_options # When used only BBB options (not prefixed with 'gl') will be returned.
@only_enabled = only_enabled # When used only optional and force enabled options will be returned.
@show_codes = show_codes # When used access code values will be returned.
@settings = settings # When given only the settings contained in the Array<String> will be returned.
@voice_bridge = voice_bridge

# Fetching only rooms configs that are not optional to overwrite the settings values.
@rooms_configs = MeetingOption.joins(:rooms_configurations)
Expand All @@ -56,8 +55,6 @@ def call
infer_codes(room_settings:, access_codes:) # Access codes should map their forced values as intended.
infer_can_record(room_settings:) if room_settings['record'] && @rooms_configs['record'].nil?

set_voice_brige(room_settings:)

room_settings
end

Expand Down Expand Up @@ -101,10 +98,4 @@ def infer_can_record(room_settings:)

room_settings['record'] = 'false'
end

def set_voice_brige(room_settings:)
if @voice_bridge != nil
room_settings['voiceBridge'] = "#{@voice_bridge}"
end
end
end
3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ class Application < Rails::Application

config.bigbluebutton_secret = ENV.fetch('BIGBLUEBUTTON_SECRET', '8cd8ef52e8e101574e400365b55e11a6')

config.voice_bridge_phone_number = ENV.fetch('VOICE_BRIDGE_PHONE_NUMBER', nil)

config.relative_url_root = ENV.fetch('RELATIVE_URL_ROOT', '/')
# Fetch 'RELATIVE_URL_ROOT' ENV variable value while removing any trailing slashes.
config.relative_url_root = ENV.fetch('RELATIVE_URL_ROOT', nil)&.sub(%r{/*\z}, '')
config.relative_url_root = '/' if config.relative_url_root.blank?
Expand Down
34 changes: 0 additions & 34 deletions db/data/20230328124724_populate_voice_brige_for_existing_rooms.rb

This file was deleted.

2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataMigrate::Data.define(version: 20230328124724)
DataMigrate::Data.define(version: 20240209155229)
6 changes: 0 additions & 6 deletions db/migrate/20230321125010_add_voice_brige_to_romms.rb

This file was deleted.

13 changes: 7 additions & 6 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ REDIS_URL=
# [en, ar, fr, es, fa_IR]
#DEFAULT_LOCALE=en

# Define the phone number for the voice bridge.
# This number is not sent to bbb and is only displayed in the greenlight UI, but it should match the number in the bbb instance to avoid user confusion.
# If this number is defined, each newly created room will be assigned a static voiceBridge pin.
#VOICE_BRIDGE_PHONE_NUMBER=

# Set this if you like to deploy Greenlight on a relative root path other than /
#RELATIVE_URL_ROOT=/gl

Expand Down

0 comments on commit 245f76c

Please sign in to comment.