forked from External/greenlight
Added setting for admin to limit the number of rooms for the user (#607)
This commit is contained in:
parent
4f2b190239
commit
e4f50026f1
|
@ -46,3 +46,12 @@
|
|||
.authentication-required{
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
#site_settings {
|
||||
.colorinput-color {
|
||||
text-align: center;
|
||||
padding-top: 4px;
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ class AdminsController < ApplicationController
|
|||
|
||||
manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve]
|
||||
site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken,
|
||||
:registration_method, :room_authentication]
|
||||
:registration_method, :room_authentication, :room_limit]
|
||||
|
||||
authorize_resource class: false
|
||||
before_action :find_user, only: manage_users
|
||||
|
@ -153,6 +153,12 @@ class AdminsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# POST /admins/room_limit
|
||||
def room_limit
|
||||
@settings.update_value("Room Limit", params[:limit])
|
||||
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
|
|
|
@ -33,6 +33,8 @@ class RoomsController < ApplicationController
|
|||
def create
|
||||
redirect_to(root_path) && return unless current_user
|
||||
|
||||
return redirect_to current_user.main_room, flash: { alert: I18n.t("room.room_limit") } if room_limit_exceeded
|
||||
|
||||
@room = Room.new(name: room_params[:name])
|
||||
@room.owner = current_user
|
||||
@room.room_settings = create_room_settings_string(room_params[:mute_on_join], room_params[:client])
|
||||
|
@ -279,4 +281,14 @@ class RoomsController < ApplicationController
|
|||
Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" &&
|
||||
current_user.nil?
|
||||
end
|
||||
|
||||
def room_limit_exceeded
|
||||
limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
|
||||
|
||||
# Does not apply to admin
|
||||
# 15+ option is used as unlimited
|
||||
return false if current_user&.has_role?(:admin) || limit == 15
|
||||
|
||||
current_user.rooms.count >= limit
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,4 +53,8 @@ module AdminsHelper
|
|||
I18n.t("administrator.site_settings.registration.methods.approval")
|
||||
end
|
||||
end
|
||||
|
||||
def room_limit_number
|
||||
Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,4 +27,26 @@ module RoomsHelper
|
|||
Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" &&
|
||||
current_user.nil?
|
||||
end
|
||||
|
||||
def number_of_rooms_allowed
|
||||
Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
|
||||
end
|
||||
|
||||
def room_limit_exceeded
|
||||
limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
|
||||
|
||||
# Does not apply to admin or users that aren't signed in
|
||||
# 15+ option is used as unlimited
|
||||
return false if !current_user || current_user&.has_role?(:admin) || limit == 15
|
||||
|
||||
current_user.rooms.length >= limit
|
||||
end
|
||||
|
||||
def current_room_exceeds_limit(room)
|
||||
# Get how many rooms need to be deleted to reach allowed room number
|
||||
limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
|
||||
@diff = current_user.rooms.count - limit
|
||||
|
||||
@diff.positive? && current_user.rooms.pluck(:id).index(room.id) + 1 > limit
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,6 +41,8 @@ class Setting < ApplicationRecord
|
|||
Rails.configuration.registration_method_default
|
||||
when "Room Authentication"
|
||||
false
|
||||
when "Room Limit"
|
||||
Rails.configuration.number_of_rooms_default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,12 @@
|
|||
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
||||
%>
|
||||
|
||||
<% exceeds_limit = current_room_exceeds_limit(@room)%>
|
||||
<% if exceeds_limit%>
|
||||
<div class="alert alert-danger alert-dismissible text-center mb-0">
|
||||
<%= t("room.room_limit_exceeded", difference: @diff) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="background pb-1">
|
||||
<div class="container">
|
||||
<div class="row pt-9">
|
||||
|
@ -27,6 +33,7 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<h4 class="text-left mb-6"><%= @room.sessions %> <%= t("room.sessions") %> | <%= @recordings.length %> <%= t("room.recordings") %></h4>
|
||||
<% unless exceeds_limit %>
|
||||
<label class="form-label"><%= t("room.invite_participants") %></label>
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-12 mt-2 pr-0">
|
||||
|
@ -56,13 +63,16 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="offset-lg-1 col-lg-3 col-sm-12 force-bottom mt-5 pr-0">
|
||||
<% if @is_running %>
|
||||
<%= button_to t("room.join"), room_path(@room), class: "btn btn-primary btn-block px-7 start-button float-right" %>
|
||||
<% else %>
|
||||
<% unless exceeds_limit %>
|
||||
<%= button_to t("room.start"), start_room_path(@room), class: "btn btn-primary btn-block px-7 start-button float-right" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -82,7 +92,9 @@
|
|||
<%= render "shared/modals/delete_room_modal", room: room %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% unless room_limit_exceeded %>
|
||||
<%= render "shared/components/create_room_block"%>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="mb-6 row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label"><%= t("administrator.site_settings.authentication.title") %></label>
|
||||
|
@ -99,4 +99,38 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label"><%= t("administrator.site_settings.rooms.title") %></label>
|
||||
<label class="form-label text-muted"><%= t("administrator.site_settings.rooms.info") %></label>
|
||||
<div class="row gutters-xs">
|
||||
<div class="col-auto">
|
||||
<label class="colorinput">
|
||||
<%= button_to admin_room_limit_path(limit: 1), class: "colorinput-input" do %><% end %>
|
||||
<span class="colorinput-color <%= room_limit_number == 1 ? "btn-primary" : "btn-outline-primary" %>">1</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="colorinput">
|
||||
<%= button_to admin_room_limit_path(limit: 5), class: "colorinput-input" do %><% end %>
|
||||
<span class="colorinput-color <%= room_limit_number == 5 ? "btn-primary" : "btn-outline-primary" %>">5</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="colorinput">
|
||||
<%= button_to admin_room_limit_path(limit: 10), class: "colorinput-input" do %><% end %>
|
||||
<span class="colorinput-color <%= room_limit_number == 10 ? "btn-primary" : "btn-outline-primary" %>">10</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="colorinput">
|
||||
<%= button_to admin_room_limit_path(limit: 15), class: "colorinput-input" do %><% end %>
|
||||
<span class="colorinput-color <%= room_limit_number == 15 ? "btn-primary" : "btn-outline-primary" %>">15+</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -130,6 +130,9 @@ module Greenlight
|
|||
# Default registration method if the user does not specify one
|
||||
config.registration_method_default = config.registration_methods[:open]
|
||||
|
||||
# Default limit on number of rooms users can create
|
||||
config.number_of_rooms_default = 15
|
||||
|
||||
# Default admin password
|
||||
config.admin_password_default = ENV['ADMIN_PASSWORD'] || 'administrator'
|
||||
end
|
||||
|
|
|
@ -55,6 +55,9 @@ en:
|
|||
approval: Approve/Decline
|
||||
invite: Join by Invitation
|
||||
open: Open Registration
|
||||
rooms:
|
||||
info: Limits the number of rooms that a user can have (including Home Room). This setting does not apply to administrators.
|
||||
title: Number of Rooms per User
|
||||
subtitle: Customize Greenlight
|
||||
title: Site Settings
|
||||
flash:
|
||||
|
@ -353,6 +356,8 @@ en:
|
|||
owner: Owner
|
||||
no_sessions: This room has no sessions, yet!
|
||||
recordings: Room Recordings
|
||||
room_limit: You have reached the maximum number of rooms allowed
|
||||
room_limit_exceeded: You have exceeded the number of rooms allowed. Please delete %{difference} room(s) to access this room.
|
||||
sessions: Sessions
|
||||
settings: Room Settings
|
||||
start: Start
|
||||
|
|
|
@ -51,6 +51,7 @@ Rails.application.routes.draw do
|
|||
post '/invite', to: 'admins#invite', as: :invite_user
|
||||
post '/registration_method/:method', to: 'admins#registration_method', as: :admin_change_registration
|
||||
post '/approve/:user_uid', to: 'admins#approve', as: :admin_approve
|
||||
post '/room_limit', to: 'admins#room_limit', as: :admin_room_limit
|
||||
end
|
||||
|
||||
scope '/themes' do
|
||||
|
|
|
@ -247,7 +247,9 @@ describe AdminsController, type: :controller do
|
|||
expect(response).to redirect_to(admins_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Site Settings" do
|
||||
context "POST #registration_method" do
|
||||
it "changes the registration method for the given context" do
|
||||
allow(Rails.configuration).to receive(:enable_email_verification).and_return(true)
|
||||
|
@ -294,5 +296,21 @@ describe AdminsController, type: :controller do
|
|||
expect(response).to redirect_to(admins_path)
|
||||
end
|
||||
end
|
||||
|
||||
context "POST #room_limit" do
|
||||
it "changes the room limit 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
|
||||
|
||||
post :room_limit, params: { limit: 5 }
|
||||
|
||||
feature = Setting.find_by(provider: "provider1").features.find_by(name: "Room Limit")
|
||||
|
||||
expect(feature[:value]).to eq("5")
|
||||
expect(response).to redirect_to(admins_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -129,7 +129,7 @@ describe RoomsController, type: :controller do
|
|||
expect(response).to redirect_to(r)
|
||||
end
|
||||
|
||||
it "it should redirect to root if not logged in" do
|
||||
it "should redirect to root if not logged in" do
|
||||
expect do
|
||||
name = Faker::Games::Pokemon.name
|
||||
post :create, params: { room: { name: name } }
|
||||
|
@ -138,7 +138,7 @@ describe RoomsController, type: :controller do
|
|||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it "it should redirect back to main room with error if it fails" do
|
||||
it "should redirect back to main room with error if it fails" do
|
||||
@request.session[:user_id] = @owner.id
|
||||
|
||||
room_params = { name: "", "client": "html5", "mute_on_join": "1" }
|
||||
|
@ -148,6 +148,19 @@ describe RoomsController, type: :controller do
|
|||
expect(flash[:alert]).to be_present
|
||||
expect(response).to redirect_to(@owner.main_room)
|
||||
end
|
||||
|
||||
it "redirects to main room if room limit is reached" do
|
||||
allow_any_instance_of(Setting).to receive(:get_value).and_return(1)
|
||||
|
||||
@request.session[:user_id] = @owner.id
|
||||
|
||||
room_params = { name: Faker::Games::Pokemon.name, "client": "html5", "mute_on_join": "1" }
|
||||
|
||||
post :create, params: { room: room_params }
|
||||
|
||||
expect(flash[:alert]).to be_present
|
||||
expect(response).to redirect_to(@owner.main_room)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #join" do
|
||||
|
|
Loading…
Reference in New Issue