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/assets/stylesheets/rooms.scss b/app/assets/stylesheets/rooms.scss index e30a2e11..ec6b664f 100644 --- a/app/assets/stylesheets/rooms.scss +++ b/app/assets/stylesheets/rooms.scss @@ -109,3 +109,7 @@ text-decoration: line-through; } +.enabled-setting { + background: lightgray; + pointer-events: none; +} 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 445d2b20..3295de21 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) @@ -94,6 +94,29 @@ module Joiner } 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 + private def fetch_guest_id diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index e1bc1fdb..7d2d048b 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -62,7 +62,8 @@ class RoomsController < ApplicationController # GET /:room_uid def show - @anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"] + @room_settings = @room[:room_settings] + @anyone_can_start = room_setting_with_config("anyoneCanStart") @room_running = room_running?(@room.bbb_id) @shared_room = room_shared_with_user @@ -160,9 +161,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 @@ +