@@ -29,9 +29,9 @@
<% if room == current_user.main_room %>
- <%= t("home_room") %>
+ <%= t("home_room") %>
<% else %>
- <%= room.name %>
+ <%= room.name %>
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3602630c..06533a02 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -93,6 +93,7 @@ en:
invalid_create: There was a problem creating a new role. Please check the role values and try again
invalid_order: There was a problem updating the priority of the role. Please check the values and try again
invalid_update: There was a problem updating the permissions of the role. Please check the values and try again
+ manage_rooms_recordings: Allow users with this role to manage server rooms and recordings
name: Role Name
new_role: Create a new role
role_has_users: This role is assigned to %{user_count} accounts. Please remove all accounts from this role before deleting it.
@@ -106,6 +107,14 @@ en:
colour:
title: Role Colour
info: Set the colour that will be associated with the role
+ rooms:
+ title: Server Rooms
+ table:
+ id: ID
+ not_running: Not Running
+ running: Running
+ status: Status
+ view: View
title: Organization Settings
users:
invite: Invite User
@@ -418,6 +427,10 @@ en:
create_room: Create a Room
create_room_error: There was an error creating the room
create_room_success: Room created successfully
+ delete:
+ home_room: Can't delete user's Home Room
+ success: Room deleted successfully
+ fail: Failed to delete room (%{error})
enter_the_access_code: Enter the room's access code
invalid_provider: You have entered an invalid url. Please check the url and try again.
invited: You have been invited to join
diff --git a/config/routes.rb b/config/routes.rb
index e33b96a5..47b8fd69 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -38,6 +38,7 @@ Rails.application.routes.draw do
scope '/admins' do
# Panel Tabs
+ get '/rooms', to: 'admins#server_rooms', as: :admin_rooms
get '/recordings', to: 'admins#server_recordings', as: :admin_recordings
get '/site_settings', to: 'admins#site_settings', as: :admin_site_settings
get '/roles', to: 'admins#roles', as: :admin_roles
diff --git a/db/migrate/20191023172511_add_manage_room_recordings_to_permissions.rb b/db/migrate/20191023172511_add_manage_room_recordings_to_permissions.rb
new file mode 100644
index 00000000..31f2920e
--- /dev/null
+++ b/db/migrate/20191023172511_add_manage_room_recordings_to_permissions.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class MigrationProduct < ActiveRecord::Base
+ self.table_name = :roles
+end
+
+class SubMigrationProduct < ActiveRecord::Base
+ self.table_name = :role_permissions
+end
+
+class AddManageRoomRecordingsToPermissions < ActiveRecord::Migration[5.2]
+ def change
+ reversible do |dir|
+ dir.up do
+ MigrationProduct.all.each do |role|
+ SubMigrationProduct.create(role_id: role.id, name: "can_manage_rooms_recordings",
+ value: SubMigrationProduct.find_by(role_id: role.id, name: "can_manage_users").value, enabled: true)
+ end
+ end
+
+ dir.down do
+ MigrationProduct.all.each do |role|
+ SubMigrationProduct.find_by(role_id: role.id, name: "can_manage_rooms_recordings").destroy
+ end
+ end
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 921e3f4e..4879d815 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_28_153347) do
+ActiveRecord::Schema.define(version: 2019_10_23_172511) do
create_table "features", force: :cascade do |t|
t.integer "setting_id"
diff --git a/spec/controllers/rooms_controller_spec.rb b/spec/controllers/rooms_controller_spec.rb
index de2ec06e..9a5bb744 100644
--- a/spec/controllers/rooms_controller_spec.rb
+++ b/spec/controllers/rooms_controller_spec.rb
@@ -342,6 +342,45 @@ describe RoomsController, type: :controller do
delete :destroy, params: { room_uid: @user.main_room }
end.to change { Room.count }.by(0)
end
+
+ it "allows admin to delete room" do
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ expect do
+ delete :destroy, params: { room_uid: @secondary_room }
+ end.to change { Room.count }.by(-1)
+
+ expect(response).to redirect_to(@admin.main_room)
+ end
+
+ it "does not allow admin to delete a users home room" do
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ expect do
+ delete :destroy, params: { room_uid: @user.main_room }
+ end.to change { Room.count }.by(0)
+
+ expect(flash[:alert]).to be_present
+ expect(response).to redirect_to(@admin.main_room)
+ end
+
+ it "does not allow an admin from a different context to delete room" do
+ allow_any_instance_of(User).to receive(:admin_of?).and_return(false)
+
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ expect do
+ delete :destroy, params: { room_uid: @secondary_room }
+ end.to change { Room.count }.by(0)
+
+ expect(response).to redirect_to(root_path)
+ end
end
describe "POST #start" do
@@ -374,6 +413,27 @@ describe RoomsController, type: :controller do
expect(response).to redirect_to(root_path)
end
+
+ it "redirects to join path if admin" do
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ post :start, params: { room_uid: @user.main_room }
+
+ expect(response).to redirect_to(join_path(@user.main_room, @admin.name, { user_is_moderator: true }, @admin.uid))
+ end
+
+ it "redirects to root path if not admin of current user" do
+ allow_any_instance_of(User).to receive(:admin_of?).and_return(false)
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ post :start, params: { room_uid: @user.main_room }
+
+ expect(response).to redirect_to(root_path)
+ end
end
describe "POST #update_settings" do
@@ -413,6 +473,35 @@ describe RoomsController, type: :controller do
expect(response).to redirect_to(@secondary_room)
end
+
+ it "allows admin to update room settings" do
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ room_params = { "mute_on_join": "1", "name": @secondary_room.name }
+ formatted_room_params = "{\"muteOnStart\":true,\"requireModeratorApproval\":false," \
+ "\"anyoneCanStart\":false,\"joinModerator\":false}" # JSON string format
+
+ expect { post :update_settings, params: { room_uid: @secondary_room.uid, room: room_params } }
+ .to change { @secondary_room.reload.room_settings }
+ .from(@secondary_room.room_settings).to(formatted_room_params)
+ expect(response).to redirect_to(@secondary_room)
+ end
+
+ it "does not allow admins from a different context to update room settings" do
+ allow_any_instance_of(User).to receive(:admin_of?).and_return(false)
+ @admin = create(:user)
+ @admin.add_role :admin
+ @request.session[:user_id] = @admin.id
+
+ room_params = { "mute_on_join": "1", "name": @secondary_room.name }
+
+ expect { post :update_settings, params: { room_uid: @secondary_room.uid, room: room_params } }
+ .not_to change { @secondary_room.reload.room_settings }
+
+ expect(response).to redirect_to(root_path)
+ end
end
describe "GET #logout" do
|