From 70acb9a7e14828f681890facc90f354a02e861d2 Mon Sep 17 00:00:00 2001 From: shawn-higgins1 <23224097+shawn-higgins1@users.noreply.github.com> Date: Wed, 22 May 2019 13:44:40 -0400 Subject: [PATCH] GRN2-118: Create a setting to require authentication to join a room (#541) * Create a setting to require authentication to join a room * Apply comments --- app/assets/javascripts/admins.js | 5 ++++ app/controllers/admins_controller.rb | 8 ++++- app/controllers/rooms_controller.rb | 11 +++++++ app/helpers/admins_helper.rb | 4 +++ app/models/setting.rb | 2 ++ app/views/rooms/join.html.erb | 30 +++++++++++-------- .../admin_settings/_site_settings.html.erb | 13 ++++++++ config/locales/en.yml | 4 +++ config/routes.rb | 1 + spec/controllers/admins_controller_spec.rb | 17 +++++++++++ spec/controllers/rooms_controller_spec.rb | 8 +++++ 11 files changed, 89 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/admins.js b/app/assets/javascripts/admins.js index 0dff33ee..d59c3e79 100644 --- a/app/assets/javascripts/admins.js +++ b/app/assets/javascripts/admins.js @@ -106,6 +106,11 @@ function changeBrandingImage(path) { $.post(path, {url: url}) } +// Change whether or not user have to be signed in to join a room +function changeRoomAuthentication(checked, path) { + $.post(path, {authenticationRequired: checked}) +} + // Filters by role function filterRole(role) { search = new URL(location.href).searchParams.get('search') diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index e7930169..c118e6c5 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -22,7 +22,7 @@ class AdminsController < ApplicationController include Emailer manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve] - site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken, :registration_method] + site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken, :registration_method, :room_authentication] authorize_resource class: false before_action :find_user, only: manage_users @@ -130,6 +130,12 @@ class AdminsController < ApplicationController redirect_to admins_path end + # POST /admins/meetingAuthentication + def room_authentication + @settings.update_value("Room Authentication", params[:authenticationRequired]) + redirect_to admins_path + end + # POST /admins/registration_method/:method def registration_method new_method = Rails.configuration.registration_methods[params[:method].to_sym] diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 1918474d..cbec3aec 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -98,6 +98,9 @@ class RoomsController < ApplicationController # POST /:room_uid def join + # If this setting is turned on only authenticated users are allowed to join rooms + room_authentication_required + opts = default_meeting_options unless @room.owned_by?(current_user) # Assign join name if passed. @@ -271,4 +274,12 @@ class RoomsController < ApplicationController def verify_user_not_admin redirect_to admins_path if current_user && current_user&.has_role?(:super_admin) end + + def room_authentication_required + if Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" && + current_user.nil? + flash[:alert] = I18n.t("administrator.site_settings.authentication.user-info") + redirect_to signin_path + end + end end diff --git a/app/helpers/admins_helper.rb b/app/helpers/admins_helper.rb index 4ad6bb35..e4065285 100644 --- a/app/helpers/admins_helper.rb +++ b/app/helpers/admins_helper.rb @@ -35,6 +35,10 @@ module AdminsHelper registration_method == Rails.configuration.registration_methods[:approval] end + def room_authentication_required + Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" + end + def registration_method_string case registration_method when Rails.configuration.registration_methods[:open] diff --git a/app/models/setting.rb b/app/models/setting.rb index 3daaa26e..b4f07ff0 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -39,6 +39,8 @@ class Setting < ApplicationRecord Rails.configuration.primary_color_default when "Registration Method" Rails.configuration.registration_method_default + when "Room Authentication" + false end end end diff --git a/app/views/rooms/join.html.erb b/app/views/rooms/join.html.erb index 70c74c82..dd8cea98 100644 --- a/app/views/rooms/join.html.erb +++ b/app/views/rooms/join.html.erb @@ -14,18 +14,22 @@ %> <%= render 'shared/room_event' do %> - <%= form_for room_path(@room), method: :post do |f| %> -