forked from External/greenlight
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
This commit is contained in:
parent
996518eea7
commit
70acb9a7e1
|
@ -106,6 +106,11 @@ function changeBrandingImage(path) {
|
||||||
$.post(path, {url: url})
|
$.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
|
// Filters by role
|
||||||
function filterRole(role) {
|
function filterRole(role) {
|
||||||
search = new URL(location.href).searchParams.get('search')
|
search = new URL(location.href).searchParams.get('search')
|
||||||
|
|
|
@ -22,7 +22,7 @@ class AdminsController < ApplicationController
|
||||||
include Emailer
|
include Emailer
|
||||||
|
|
||||||
manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve]
|
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
|
authorize_resource class: false
|
||||||
before_action :find_user, only: manage_users
|
before_action :find_user, only: manage_users
|
||||||
|
@ -130,6 +130,12 @@ class AdminsController < ApplicationController
|
||||||
redirect_to admins_path
|
redirect_to admins_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# POST /admins/meetingAuthentication
|
||||||
|
def room_authentication
|
||||||
|
@settings.update_value("Room Authentication", params[:authenticationRequired])
|
||||||
|
redirect_to admins_path
|
||||||
|
end
|
||||||
|
|
||||||
# POST /admins/registration_method/:method
|
# POST /admins/registration_method/:method
|
||||||
def registration_method
|
def registration_method
|
||||||
new_method = Rails.configuration.registration_methods[params[:method].to_sym]
|
new_method = Rails.configuration.registration_methods[params[:method].to_sym]
|
||||||
|
|
|
@ -98,6 +98,9 @@ class RoomsController < ApplicationController
|
||||||
|
|
||||||
# POST /:room_uid
|
# POST /:room_uid
|
||||||
def join
|
def join
|
||||||
|
# If this setting is turned on only authenticated users are allowed to join rooms
|
||||||
|
room_authentication_required
|
||||||
|
|
||||||
opts = default_meeting_options
|
opts = default_meeting_options
|
||||||
unless @room.owned_by?(current_user)
|
unless @room.owned_by?(current_user)
|
||||||
# Assign join name if passed.
|
# Assign join name if passed.
|
||||||
|
@ -271,4 +274,12 @@ class RoomsController < ApplicationController
|
||||||
def verify_user_not_admin
|
def verify_user_not_admin
|
||||||
redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
|
redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -35,6 +35,10 @@ module AdminsHelper
|
||||||
registration_method == Rails.configuration.registration_methods[:approval]
|
registration_method == Rails.configuration.registration_methods[:approval]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def room_authentication_required
|
||||||
|
Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true"
|
||||||
|
end
|
||||||
|
|
||||||
def registration_method_string
|
def registration_method_string
|
||||||
case registration_method
|
case registration_method
|
||||||
when Rails.configuration.registration_methods[:open]
|
when Rails.configuration.registration_methods[:open]
|
||||||
|
|
|
@ -39,6 +39,8 @@ class Setting < ApplicationRecord
|
||||||
Rails.configuration.primary_color_default
|
Rails.configuration.primary_color_default
|
||||||
when "Registration Method"
|
when "Registration Method"
|
||||||
Rails.configuration.registration_method_default
|
Rails.configuration.registration_method_default
|
||||||
|
when "Room Authentication"
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,18 +14,22 @@
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%= render 'shared/room_event' do %>
|
<%= render 'shared/room_event' do %>
|
||||||
<%= form_for room_path(@room), method: :post do |f| %>
|
<% if room_authentication_required && current_user.nil? %>
|
||||||
<div class="input-group join-input">
|
<h2><%= t("administrator.site_settings.authentication.user-info") %></h2>
|
||||||
<%= f.hidden_field(:search, :value => params[:search])%>
|
<% else %>
|
||||||
<%= f.hidden_field(:column, :value => params[:column])%>
|
<%= form_for room_path(@room), method: :post do |f| %>
|
||||||
<%= f.hidden_field(:direction, :value => params[:direction])%>
|
<div class="input-group join-input">
|
||||||
<%= f.text_field :join_name,
|
<%= f.hidden_field(:search, :value => params[:search])%>
|
||||||
required: true,
|
<%= f.hidden_field(:column, :value => params[:column])%>
|
||||||
class: "form-control join-form",
|
<%= f.hidden_field(:direction, :value => params[:direction])%>
|
||||||
placeholder: t("enter_your_name"),
|
<%= f.text_field :join_name,
|
||||||
value: "#{@name}",
|
required: true,
|
||||||
readonly: !current_user.nil? %>
|
class: "form-control join-form",
|
||||||
<%= f.submit t("room.join"), class: "btn btn-primary btn-sm col-sm-3 form-control join-form" %>
|
placeholder: t("enter_your_name"),
|
||||||
</div>
|
value: "#{@name}",
|
||||||
|
readonly: !current_user.nil? %>
|
||||||
|
<%= f.submit t("room.join"), class: "btn btn-primary btn-sm col-sm-3 form-control join-form" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -28,6 +28,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="mb-7 form-group">
|
||||||
|
<label class="form-label"><%= t("administrator.site_settings.authentication.title") %></label>
|
||||||
|
<div class="row gutters-xs">
|
||||||
|
<label class="custom-control custom-checkbox ml-1">
|
||||||
|
<%= check_box_tag "room_authentication", '', room_authentication_required, class: 'custom-control-input', onchange: "changeRoomAuthentication(this.checked, '#{admin_room_authentication_path}')"%>
|
||||||
|
<span class="custom-control-label text-muted pt-1"><%= t("administrator.site_settings.authentication.info") %></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="mb-7 form-group">
|
<div class="mb-7 form-group">
|
||||||
|
|
|
@ -23,6 +23,10 @@ en:
|
||||||
accepted_terms: "Terms and Conditions"
|
accepted_terms: "Terms and Conditions"
|
||||||
administrator:
|
administrator:
|
||||||
site_settings:
|
site_settings:
|
||||||
|
authentication:
|
||||||
|
info: Only allow authenticated users to join a room
|
||||||
|
title: Require Authentication for Rooms
|
||||||
|
user-info: You must sign in to Greenlight to join this room
|
||||||
branding:
|
branding:
|
||||||
change: Change Image
|
change: Change Image
|
||||||
info: Change the branding image that appears in the top left corner
|
info: Change the branding image that appears in the top left corner
|
||||||
|
|
|
@ -39,6 +39,7 @@ Rails.application.routes.draw do
|
||||||
scope '/admins' do
|
scope '/admins' do
|
||||||
post '/branding', to: 'admins#branding', as: :admin_branding
|
post '/branding', to: 'admins#branding', as: :admin_branding
|
||||||
post '/coloring', to: 'admins#coloring', as: :admin_coloring
|
post '/coloring', to: 'admins#coloring', as: :admin_coloring
|
||||||
|
post '/room_authentication', to: 'admins#room_authentication', as: :admin_room_authentication
|
||||||
post '/coloring_lighten', to: 'admins#coloring_lighten', as: :admin_coloring_lighten
|
post '/coloring_lighten', to: 'admins#coloring_lighten', as: :admin_coloring_lighten
|
||||||
post '/coloring_darken', to: 'admins#coloring_darken', as: :admin_coloring_darken
|
post '/coloring_darken', to: 'admins#coloring_darken', as: :admin_coloring_darken
|
||||||
post '/signup', to: 'admins#signup', as: :admin_signup
|
post '/signup', to: 'admins#signup', as: :admin_signup
|
||||||
|
|
|
@ -278,5 +278,22 @@ describe AdminsController, type: :controller do
|
||||||
expect(response).to redirect_to(admins_path)
|
expect(response).to redirect_to(admins_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "POST #room_authentication" do
|
||||||
|
it "changes the room authentication required setting" do
|
||||||
|
allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(true)
|
||||||
|
allow_any_instance_of(User).to receive(:greenlight_account?).and_return(true)
|
||||||
|
|
||||||
|
@request.session[:user_id] = @admin.id
|
||||||
|
checked = true
|
||||||
|
|
||||||
|
post :room_authentication, params: { authenticationRequired: checked }
|
||||||
|
|
||||||
|
feature = Setting.find_by(provider: "provider1").features.find_by(name: "Room Authentication")
|
||||||
|
|
||||||
|
expect(feature[:value]).to eq(checked.to_s)
|
||||||
|
expect(response).to redirect_to(admins_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -206,6 +206,14 @@ describe RoomsController, type: :controller do
|
||||||
expect(flash[:alert]).to be_present
|
expect(flash[:alert]).to be_present
|
||||||
expect(response).to redirect_to(root_path)
|
expect(response).to redirect_to(root_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not allow the user to join if the user isn't signed in and room authentication is required" do
|
||||||
|
allow_any_instance_of(Setting).to receive(:get_value).and_return("true")
|
||||||
|
|
||||||
|
post :join, params: { room_uid: @room }
|
||||||
|
|
||||||
|
expect(response).to redirect_to(signin_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE #destroy" do
|
describe "DELETE #destroy" do
|
||||||
|
|
Loading…
Reference in New Issue