From 5c7062d7c9c23993cfb5bcde924cbcbc6972f057 Mon Sep 17 00:00:00 2001 From: farhatahmad Date: Mon, 6 Apr 2020 15:48:42 -0400 Subject: [PATCH] Added room configuration tab to admin panel --- app/assets/javascripts/room.js | 19 ++-- app/controllers/admins_controller.rb | 14 +++ app/controllers/concerns/joiner.rb | 33 +++++- app/controllers/rooms_controller.rb | 6 +- app/helpers/admins_helper.rb | 29 ++++- app/helpers/rooms_helper.rb | 4 + app/models/ability.rb | 3 +- app/models/setting.rb | 17 +++ .../admins/components/_menu_buttons.html.erb | 3 + .../admins/components/_room_settings.html.erb | 101 ++++++++++++++++++ app/views/admins/room_configuration.html.erb | 27 +++++ .../shared/modals/_create_room_modal.html.erb | 22 ++-- config/locales/en.yml | 15 +++ config/routes.rb | 3 + 14 files changed, 264 insertions(+), 32 deletions(-) create mode 100644 app/views/admins/components/_room_settings.html.erb create mode 100644 app/views/admins/room_configuration.html.erb diff --git a/app/assets/javascripts/room.js b/app/assets/javascripts/room.js index b7ef5396..6186aaca 100644 --- a/app/assets/javascripts/room.js +++ b/app/assets/javascripts/room.js @@ -144,10 +144,11 @@ function showCreateRoom(target) { $("#room_access_code").val(null) $("#createRoomModal form").attr("action", $("body").data('relative-root')) - $("#room_mute_on_join").prop("checked", false) - $("#room_require_moderator_approval").prop("checked", false) - $("#room_anyone_can_start").prop("checked", false) - $("#room_all_join_moderator").prop("checked", false) + + $("#room_mute_on_join").prop("checked", $("#room_mute_on_join").data("default")) + $("#room_require_moderator_approval").prop("checked", $("#room_require_moderator_approval").data("default")) + $("#room_anyone_can_start").prop("checked", $("#room_anyone_can_start").data("default")) + $("#room_all_join_moderator").prop("checked", $("#room_all_join_moderator").data("default")) //show all elements & their children with a create-only class $(".create-only").each(function() { @@ -203,11 +204,11 @@ function showDeleteRoom(target) { function updateCurrentSettings(settings_path){ // Get current room settings and set checkbox $.get(settings_path, function(room_settings) { - var settings = JSON.parse(room_settings) - $("#room_mute_on_join").prop("checked", settings.muteOnStart) - $("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval) - $("#room_anyone_can_start").prop("checked", settings.anyoneCanStart) - $("#room_all_join_moderator").prop("checked", settings.joinModerator) + var settings = JSON.parse(room_settings) + $("#room_mute_on_join").prop("checked", $("#room_mute_on_join").data("default") || settings.muteOnStart) + $("#room_require_moderator_approval").prop("checked", $("#room_require_moderator_approval").data("default") || settings.requireModeratorApproval) + $("#room_anyone_can_start").prop("checked", $("#room_anyone_can_start").data("default") || settings.anyoneCanStart) + $("#room_all_join_moderator").prop("checked", $("#room_all_join_moderator").data("default") || settings.joinModerator) }) } diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 52f8b7d3..083bb1f5 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -73,6 +73,10 @@ class AdminsController < ApplicationController @pagy, @rooms = pagy_array(server_rooms_list) end + # GET /admins/room_configuration + def room_configuration + end + # MANAGE USERS # GET /admins/edit/:user_uid @@ -241,6 +245,16 @@ class AdminsController < ApplicationController redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } end + # ROOM CONFIGURATION + # POST /admins/update_room_configuration + def update_room_configuration + @settings.update_value(params[:setting], params[:value]) + + flash_message = I18n.t("administrator.flash.room_configuration") + + redirect_to admin_room_configuration_path, flash: { success: flash_message } + end + # ROLES # GET /admins/roles diff --git a/app/controllers/concerns/joiner.rb b/app/controllers/concerns/joiner.rb index 22643122..6b6e4622 100644 --- a/app/controllers/concerns/joiner.rb +++ b/app/controllers/concerns/joiner.rb @@ -48,15 +48,15 @@ module Joiner end def join_room(opts) - room_settings = JSON.parse(@room[:room_settings]) + @room_settings = JSON.parse(@room[:room_settings]) - if room_running?(@room.bbb_id) || @room.owned_by?(current_user) || room_settings["anyoneCanStart"] + if room_running?(@room.bbb_id) || @room.owned_by?(current_user) || room_setting_with_config("anyoneCanStart") # Determine if the user needs to join as a moderator. - opts[:user_is_moderator] = @room.owned_by?(current_user) || room_settings["joinModerator"] || @shared_room + opts[:user_is_moderator] = @room.owned_by?(current_user) || room_setting_with_config("joinModerator") || @shared_room - opts[:require_moderator_approval] = room_settings["requireModeratorApproval"] - opts[:mute_on_start] = room_settings["muteOnStart"] + opts[:require_moderator_approval] = room_setting_with_config("requireModeratorApproval") + opts[:mute_on_start] = room_setting_with_config("muteOnStart") if current_user redirect_to join_path(@room, current_user.name, opts, current_user.uid) @@ -92,4 +92,27 @@ module Joiner recording_default_visibility: @settings.get_value("Default Recording Visibility") == "public" } end + + # Gets the room setting based on the option set in the room configuration + def room_setting_with_config(name) + config = case name + when "muteOnStart" + "Room Configuration Mute On Join" + when "requireModeratorApproval" + "Room Configuration Require Moderator" + when "joinModerator" + "Room Configuration All Join Moderator" + when "anyoneCanStart" + "Room Configuration Allow Any Start" + end + + case @settings.get_value(config) + when "enabled" + true + when "optional" + @room_settings[name] + when "disabled" + false + end + end end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index e1bc1fdb..07c2f87c 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -160,9 +160,9 @@ class RoomsController < ApplicationController opts[:user_is_moderator] = true # Include the user's choices for the room settings - room_settings = JSON.parse(@room[:room_settings]) - opts[:mute_on_start] = room_settings["muteOnStart"] - opts[:require_moderator_approval] = room_settings["requireModeratorApproval"] + @room_settings = JSON.parse(@room[:room_settings]) + opts[:mute_on_start] = room_setting_with_config("muteOnStart") + opts[:require_moderator_approval] = room_setting_with_config("requireModeratorApproval") begin redirect_to join_path(@room, current_user.name, opts, current_user.uid) diff --git a/app/helpers/admins_helper.rb b/app/helpers/admins_helper.rb index 86f8571f..6976a66b 100644 --- a/app/helpers/admins_helper.rb +++ b/app/helpers/admins_helper.rb @@ -19,11 +19,20 @@ module AdminsHelper include Pagy::Frontend + # Server Rooms + # Gets the email of the room owner to which the recording belongs to def recording_owner_email(room_id) Room.find_by(bbb_id: room_id).owner.email.presence || Room.find_by(bbb_id: room_id).owner.username end + # Get the room status to display in the Server Rooms table + def room_is_running(id) + @running_room_bbb_ids.include?(id) + end + + # Site Settings + def admin_invite_registration controller_name == "admins" && action_name == "index" && @settings.get_value("Registration Method") == Rails.configuration.registration_methods[:invite] @@ -85,12 +94,22 @@ module AdminsHelper @settings.get_value("Room Limit").to_i end + # Room Configuration + + def room_configuration_string(name) + case @settings.get_value(name) + when "enabled" + t("administrator.room_configuration.options.enabled") + when "optional" + t("administrator.room_configuration.options.optional") + when "disabled" + t("administrator.room_configuration.options.disabled") + end + end + + # Roles + def edit_disabled @edit_disabled ||= @selected_role.priority <= current_user.highest_priority_role.priority end - - # Get the room status to display in the Server Rooms table - def room_is_running(id) - @running_room_bbb_ids.include?(id) - end end diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb index d98f772f..bae0053d 100644 --- a/app/helpers/rooms_helper.rb +++ b/app/helpers/rooms_helper.rb @@ -37,4 +37,8 @@ module RoomsHelper @diff = current_user.rooms.count - limit @diff.positive? && current_user.rooms.pluck(:id).index(room.id) + 1 > limit end + + def room_configuration(name) + @settings.get_value(name) + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index a4f98ab8..559d69f5 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -27,7 +27,8 @@ class Ability else highest_role = user.highest_priority_role if highest_role.get_permission("can_edit_site_settings") - can [:site_settings, :update_settings, :coloring, :registration_method], :admin + can [:site_settings, :room_configuration, :update_settings, + :update_room_configuration, :coloring, :registration_method], :admin end if highest_role.get_permission("can_edit_roles") diff --git a/app/models/setting.rb b/app/models/setting.rb index d657ad36..e38ee036 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -58,6 +58,23 @@ class Setting < ApplicationRecord Rails.configuration.number_of_rooms_default when "Shared Access" Rails.configuration.shared_access_default + when "Room Configuration Mute On Join" + room_config_setting("mute-on-join") + when "Room Configuration Require Moderator" + room_config_setting("require-moderator-approval") + when "Room Configuration Allow Any Start" + room_config_setting("anyone-can-start") + when "Room Configuration All Join Moderator" + room_config_setting("all-join-moderator") + end + end + + # Check if the room setting is currently enabled in .env, return disabled if not and return optional if it is + def room_config_setting(name) + if Rails.configuration.room_features.include?(name) + "optional" + else + "disabled" end end end diff --git a/app/views/admins/components/_menu_buttons.html.erb b/app/views/admins/components/_menu_buttons.html.erb index 3af09532..af8f3f12 100644 --- a/app/views/admins/components/_menu_buttons.html.erb +++ b/app/views/admins/components/_menu_buttons.html.erb @@ -33,6 +33,9 @@ <%= link_to admin_site_settings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "site_settings"}" do %> <%= t("administrator.site_settings.title") %> <% end %> + <%= link_to admin_room_configuration_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "room_configuration"}" do %> + <%= t("administrator.room_configuration.title") %> + <% end %> <% end %> <% if highest_role.get_permission("can_edit_roles") || highest_role.name == "super_admin" %> <%= link_to admin_roles_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "roles"}" do %> diff --git a/app/views/admins/components/_room_settings.html.erb b/app/views/admins/components/_room_settings.html.erb new file mode 100644 index 00000000..19a00959 --- /dev/null +++ b/app/views/admins/components/_room_settings.html.erb @@ -0,0 +1,101 @@ +
+
+
+
+ + + +
+
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+ + + +
+
+
+
\ No newline at end of file diff --git a/app/views/admins/room_configuration.html.erb b/app/views/admins/room_configuration.html.erb new file mode 100644 index 00000000..ef78b358 --- /dev/null +++ b/app/views/admins/room_configuration.html.erb @@ -0,0 +1,27 @@ +<% +# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. +# Copyright (c) 2018 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. +# +# BigBlueButton 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 BigBlueButton; if not, see . +%> + +
+ <%= render "shared/components/subtitle", subtitle: t("administrator.title"), search: false %> + +
+
+ <%= render "admins/components/menu_buttons" %> +
+
+ <%= render "admins/components/setting_view", setting_id: "room_settings", setting_title: t("administrator.room_configuration.title"), search: false %> +
+
+
diff --git a/app/views/shared/modals/_create_room_modal.html.erb b/app/views/shared/modals/_create_room_modal.html.erb index 696ffe72..4804d6d7 100644 --- a/app/views/shared/modals/_create_room_modal.html.erb +++ b/app/views/shared/modals/_create_room_modal.html.erb @@ -43,34 +43,38 @@ - <% if Rails.configuration.room_features.include? "mute-on-join" %> + <% mute = room_configuration("Room Configuration Mute On Join") %> + <% if mute != "disabled" %> <% end %> - <% if Rails.configuration.room_features.include? "require-moderator-approval" %> + <% require_approval = room_configuration("Room Configuration Require Moderator") %> + <% if require_approval != "disabled" %> <% end %> - - <% if Rails.configuration.room_features.include? "anyone-can-start" %> + + <% any_start = room_configuration("Room Configuration Allow Any Start") %> + <% if any_start != "disabled" %> <% end %> - <% if Rails.configuration.room_features.include? "all-join-moderator" %> + <% moderator = room_configuration("Room Configuration All Join Moderator") %> + <% if moderator != "disabled" %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index ee55901d..bcf1cae3 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -101,6 +101,7 @@ en: registration_method_updated: Registration method successfully updated reset_password: The user has been sent an email to reset their password. (Please ask them to check their spam folder if they haven't received it) restored: User has been successfully restored + room_configuration: Room Configuration successfully changed settings: Site Settings successfully changed unauthorized: You are not authorized to perform actions on this user recordings: @@ -127,6 +128,20 @@ en: colour: title: Role Colour info: Set the colour that will be associated with the role + room_configuration: + title: Room Configuration + mute: + info: Automatically mutes the user when they join the BigBlueButton meeting + require_moderator: + info: Prompts the moderator of the BigBlueButton meeting when a user tries to join. If the user is approved, they will be able to join the meeting. + allow_any: + info: Allows any user to start the meeting at any time. By default, only the room owner can start the meeting. + all_moderator: + info: Gives all users moderator priveleges in BigBlueButton when they join the meeting. + options: + disabled: Disabled + enabled: Always Enabled + optional: Optional rooms: title: Server Rooms table: diff --git a/config/routes.rb b/config/routes.rb index c5af3050..dea1a367 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,6 +41,7 @@ Rails.application.routes.draw do get '/rooms', to: 'admins#server_rooms', as: :admin_rooms get '/recordings', to: 'admins#server_recordings', as: :admin_recordings get '/site_settings', to: 'admins#site_settings', as: :admin_site_settings + get '/room_configuration', to: 'admins#room_configuration', as: :admin_room_configuration get '/roles', to: 'admins#roles', as: :admin_roles # Manage Users get '/edit/:user_uid', to: 'admins#edit_user', as: :admin_edit_user @@ -58,6 +59,8 @@ Rails.application.routes.draw do post '/clear_cache', to: 'admins#clear_cache', as: :admin_clear_cache post '/clear_auth', to: 'admins#clear_auth', as: :admin_clear_auth post '/log_level', to: 'admins#log_level', as: :admin_log_level + # Room Configuration + post '/update_room_configuration', to: 'admins#update_room_configuration', as: :admin_update_room_configuration # Roles post '/role', to: 'admins#new_role', as: :admin_new_role patch 'roles/order', to: 'admins#change_role_order', as: :admin_roles_order