Add room setting to require moderator approval (#660)

This commit is contained in:
shawn-higgins1 2019-07-23 16:16:14 -04:00 committed by Jesus Federico
parent f7c88cfc6a
commit 7b96d5ae41
7 changed files with 37 additions and 9 deletions

View File

@ -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
@ -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

View File

@ -39,7 +39,7 @@ class RoomsController < ApplicationController
@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"
@ -148,6 +148,7 @@ class RoomsController < ApplicationController
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)
@ -203,7 +204,7 @@ class RoomsController < ApplicationController
@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])
@ -211,10 +212,12 @@ class RoomsController < ApplicationController
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"
@ -227,7 +230,8 @@ class RoomsController < ApplicationController
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.
@ -305,6 +309,7 @@ class RoomsController < ApplicationController
# 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)

View File

@ -62,6 +62,8 @@ class Room < ApplicationRecord
"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)
@ -104,6 +106,8 @@ class Room < ApplicationRecord
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

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -119,8 +119,10 @@ describe RoomsController, type: :controller do
@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 }
@ -357,8 +359,8 @@ describe RoomsController, type: :controller do
@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 }