forked from External/greenlight
Added setting for admin to limit the number of rooms for the user (#607)
This commit is contained in:
committed by
Jesus Federico
parent
4f2b190239
commit
e4f50026f1
@ -45,4 +45,13 @@
|
||||
|
||||
.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,41 +33,45 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<h4 class="text-left mb-6"><%= @room.sessions %> <%= t("room.sessions") %> | <%= @recordings.length %> <%= t("room.recordings") %></h4>
|
||||
<label class="form-label"><%= t("room.invite_participants") %></label>
|
||||
<div class="row">
|
||||
<div class="col-lg-5 col-md-12 mt-2 pr-0">
|
||||
<div class="input-icon invite-link-input">
|
||||
<span class="input-icon-addon">
|
||||
<i class="fas fa-link"></i>
|
||||
</span>
|
||||
<input id="invite-url" type="text" class="form-control w-100" value="<%= request.base_url + @room.invite_path %>" readonly="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-7 col-md-12 pr-0">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<a href="#" id="copy" class="btn btn-primary btn-block mt-2">
|
||||
<i class="fas fa-copy"></i>
|
||||
<%= t("copy") %>
|
||||
</a>
|
||||
<% 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">
|
||||
<div class="input-icon invite-link-input">
|
||||
<span class="input-icon-addon">
|
||||
<i class="fas fa-link"></i>
|
||||
</span>
|
||||
<input id="invite-url" type="text" class="form-control w-100" value="<%= request.base_url + @room.invite_path %>" readonly="">
|
||||
</div>
|
||||
<div class="col-sm-6 pl-0">
|
||||
<% if Rails.configuration.enable_google_calendar_button %>
|
||||
<a href="<%= google_calendar_path %>" target="__blank" id="schedule" class="btn btn-primary btn-block mt-2">
|
||||
<i class="fas fa-calendar-plus"></i>
|
||||
<%= t("add_to_google_calendar") %>
|
||||
</div>
|
||||
<div class="col-lg-7 col-md-12 pr-0">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<a href="#" id="copy" class="btn btn-primary btn-block mt-2">
|
||||
<i class="fas fa-copy"></i>
|
||||
<%= t("copy") %>
|
||||
</a>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="col-sm-6 pl-0">
|
||||
<% if Rails.configuration.enable_google_calendar_button %>
|
||||
<a href="<%= google_calendar_path %>" target="__blank" id="schedule" class="btn btn-primary btn-block mt-2">
|
||||
<i class="fas fa-calendar-plus"></i>
|
||||
<%= t("add_to_google_calendar") %>
|
||||
</a>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</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 %>
|
||||
<%= button_to t("room.start"), start_room_path(@room), class: "btn btn-primary btn-block px-7 start-button float-right" %>
|
||||
<% 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 %>
|
||||
<%= render "shared/components/create_room_block"%>
|
||||
<% 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>
|
||||
|
Reference in New Issue
Block a user