Skip to content

Commit

Permalink
Add room setting to require moderator approval (bigbluebutton#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-higgins1 authored and jfederico committed Jul 23, 2019
1 parent f7c88cf commit 7b96d5a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/room.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $(document).on('turbolinks:load', function(){
$("#createRoomModal form").attr("action", $("body").data('relative-root'))
updateDropdown($(".dropdown-item[value='default']"))
$("#room_mute_on_join").prop("checked", false)
$("#room_require_moderator_approval").prop("checked", false)
$("#room_anyone_can_start").prop("checked", false)

//show all elements & their children with a create-only class
Expand Down Expand Up @@ -105,6 +106,12 @@ $(document).on('turbolinks:load', function(){
$("#room_mute_on_join").prop("checked", false)
}

if(settings.requireModeratorApproval){
$("#room_require_moderator_approval").prop("checked", true)
} else { //default option
$("#room_require_moderator_approval").prop("checked", false)
}

if(settings.anyoneCanStart){
$("#room_anyone_can_start").prop("checked", true)
} else { //default option
Expand Down
13 changes: 9 additions & 4 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create
@room = Room.new(name: room_params[:name], access_code: room_params[:access_code])
@room.owner = current_user
@room.room_settings = create_room_settings_string(room_params[:mute_on_join], room_params[:client],
room_params[:anyone_can_start])
room_params[:require_moderator_approval], room_params[:anyone_can_start])

if @room.save
if room_params[:auto_join] == "1"
Expand Down Expand Up @@ -148,6 +148,7 @@ def start
room_settings = JSON.parse(@room[:room_settings])
opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]

begin
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
Expand Down Expand Up @@ -203,18 +204,20 @@ def update_room_attributes(update_type)
@room.update_attributes(name: params[:room_name] || room_params[:name])
elsif update_type.eql? "settings"
room_settings_string = create_room_settings_string(room_params[:mute_on_join], room_params[:client],
room_params[:anyone_can_start])
room_params[:require_moderator_approval], room_params[:anyone_can_start])
@room.update_attributes(room_settings: room_settings_string)
elsif update_type.eql? "access_code"
@room.update_attributes(access_code: room_params[:access_code])
end
end
end

def create_room_settings_string(mute_res, client_res, start_res)
def create_room_settings_string(mute_res, client_res, require_approval_res, start_res)
room_settings = {}
room_settings["muteOnStart"] = mute_res == "1"

room_settings["requireModeratorApproval"] = require_approval_res == "1"

if client_res.eql? "html5"
room_settings["joinViaHtml5"] = true
elsif client_res.eql? "flash"
Expand All @@ -227,7 +230,8 @@ def create_room_settings_string(mute_res, client_res, start_res)
end

def room_params
params.require(:room).permit(:name, :auto_join, :mute_on_join, :client, :access_code, :anyone_can_start)
params.require(:room).permit(:name, :auto_join, :mute_on_join, :client, :access_code,
:require_moderator_approval, :anyone_can_start)
end

# Find the room from the uid.
Expand Down Expand Up @@ -305,6 +309,7 @@ def join_room(opts)

# Check if the user has specified which client to use
opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]

if current_user
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
Expand Down
4 changes: 4 additions & 0 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def start_session(options = {})
"meta_bbb-origin-server-name": options[:host]
}

create_options[:guestPolicy] = "ASK_MODERATOR" if options[:require_moderator_approval]

# Send the create request.
begin
meeting = bbb(owner.provider).create_meeting(name, bbb_id, create_options)
Expand Down Expand Up @@ -104,6 +106,8 @@ def join_path(name, options = {}, uid = nil)
join_opts[:userID] = uid if uid
join_opts[:joinViaHtml5] = options[:join_via_html5] if options[:join_via_html5]

join_opts[:guest] = true if options[:require_moderator_approval] && !options[:user_is_moderator]

bbb(owner.provider).join_meeting_url(bbb_id, name, password, join_opts)
end

Expand Down
8 changes: 8 additions & 0 deletions app/views/shared/modals/_create_room_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
</label>
<% end %>
<% if Rails.configuration.room_features.include? "require-moderator-approval" %>
<label class="custom-switch pl-0 mt-3 mb-3 w-100 text-left d-inline-block">
<span class="custom-switch-description"><%= t("modal.room_settings.require_approval")%></span>
<%= f.check_box :require_moderator_approval, class: "custom-switch-input", checked: false %>
<span class="custom-switch-indicator float-right"></span>
</label>
<% end %>
<% if Rails.configuration.room_features.include? "anyone-can-start" %>
<label class="custom-switch pl-0 mt-3 mb-3 w-100 text-left d-inline-block">
<span class="custom-switch-description"><%= t("modal.room_settings.start")%></span>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ en:
update: Update Room
client: Select client type
mute: Mute users when they join
require_approval: Require moderator approval before joining
start: Allow any user to start this meeting
default: Default
html: HTML5
Expand Down
3 changes: 2 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ RELATIVE_URL_ROOT=/b
# Current settings available:
# default-client: Room owners can decide between the Flash Client and the HTML5 Client for a room
# mute-on-join: Automatically mute users by default when they join a room
# require-moderator-approval: Require moderators to approve new users before they can join the room
# anyone-can-start: Allows anyone with the join url to start the room in BigBlueButton
ROOM_FEATURES=default-client,mute-on-join,anyone-can-start
ROOM_FEATURES=default-client,mute-on-join,require-moderator-approval,anyone-can-start

# Specify the maximum number of records to be sent to the BigBlueButton API in one call
# Default is set to 25 records
Expand Down
10 changes: 6 additions & 4 deletions spec/controllers/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ def random_valid_room_params
@request.session[:user_id] = @owner.id
name = Faker::Games::Pokemon.name

room_params = { name: name, "client": "html5", "mute_on_join": "1", "anyone_can_start": "1" }
json_room_settings = "{\"muteOnStart\":true,\"joinViaHtml5\":true,\"anyoneCanStart\":true}"
room_params = { name: name, "client": "html5", "mute_on_join": "1",
"require_moderator_approval": "1", "anyone_can_start": "1" }
json_room_settings = "{\"muteOnStart\":true,\"requireModeratorApproval\":true," \
"\"joinViaHtml5\":true,\"anyoneCanStart\":true}"

post :create, params: { room: room_params }

Expand Down Expand Up @@ -357,8 +359,8 @@ def random_valid_room_params
@request.session[:user_id] = @user.id

room_params = { "client": "html5", "mute_on_join": "1", "name": @secondary_room.name }
formatted_room_params = "{\"muteOnStart\":true,\"joinViaHtml5\":true,\"anyoneCanStart\":false}"
# JSON string format
formatted_room_params = "{\"muteOnStart\":true,\"requireModeratorApproval\":false," \
"\"joinViaHtml5\":true,\"anyoneCanStart\":false}" # JSON string format

expect { post :update_settings, params: { room_uid: @secondary_room.uid, room: room_params } }
.to change { @secondary_room.reload.room_settings }
Expand Down

0 comments on commit 7b96d5a

Please sign in to comment.