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
@ -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
|
||||
|
Reference in New Issue
Block a user