diff --git a/config/application.rb b/config/application.rb
index 06cd5765..7e6f8915 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -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
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f0eb5539..1e444d3c 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index f2a39a23..a99d62cb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb
index 4bdc4aa3..3f55a2c0 100644
--- a/spec/controllers/admins_controller_spec.rb
+++ b/spec/controllers/admins_controller_spec.rb
@@ -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
diff --git a/spec/controllers/rooms_controller_spec.rb b/spec/controllers/rooms_controller_spec.rb
index 1492e84c..b9899079 100644
--- a/spec/controllers/rooms_controller_spec.rb
+++ b/spec/controllers/rooms_controller_spec.rb
@@ -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