GRN2-128: Added the ability to manage rooms (#848)

* Added the ability to manage rooms

* Small fixes

* Fixed travis complaints

* Fixed issues with role permissions

* Fixed issue with delete room

* Fixed rubocop and added testcases
This commit is contained in:
Ahmad Farhat
2020-01-09 11:05:17 -05:00
committed by farhatahmad
parent 984e5cc085
commit 09de6b6739
20 changed files with 394 additions and 35 deletions

View File

@ -61,6 +61,23 @@ class AdminsController < ApplicationController
@pagy, @recordings = pagy_array(recs)
end
# GET /admins/rooms
def server_rooms
@search = params[:search] || ""
@order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
@order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"
server_rooms = if Rails.configuration.loadbalanced_configuration
Room.includes(:owner).where(users: { provider: @user_domain })
.admins_search(@search)
.admins_order(@order_column, @order_direction)
else
Room.all.admins_search(@search).admins_order(@order_column, @order_direction)
end
@pagy, @rooms = pagy_array(server_rooms)
end
# MANAGE USERS
# GET /admins/edit/:user_uid
@ -283,4 +300,10 @@ class AdminsController < ApplicationController
invite
end
# Get the room status to display in the Server Rooms table
def room_is_running(id)
room_running?(id)
end
helper_method :room_is_running
end

View File

@ -141,7 +141,8 @@ module Rolify
role_params = params.require(:role).permit(:name)
permission_params = params.require(:role).permit(:can_create_rooms, :send_promoted_email,
:send_demoted_email, :can_edit_site_settings, :can_edit_roles, :can_manage_users, :colour)
:send_demoted_email, :can_edit_site_settings, :can_edit_roles, :can_manage_users,
:can_manage_rooms_recordings, :colour)
permission_params.transform_values! do |v|
if v == "0"

View File

@ -25,7 +25,7 @@ class RoomsController < ApplicationController
before_action :validate_verified_email, except: [:show, :join],
unless: -> { !Rails.configuration.enable_email_verification }
before_action :find_room, except: [:create, :join_specific_room]
before_action :verify_room_ownership, only: [:destroy, :start, :update_settings]
before_action :verify_room_ownership_or_admin, only: [:start, :update_settings, :destroy]
before_action :verify_room_owner_verified, only: [:show, :join],
unless: -> { !Rails.configuration.enable_email_verification }
before_action :verify_user_not_admin, only: [:show]
@ -112,10 +112,16 @@ class RoomsController < ApplicationController
# DELETE /:room_uid
def destroy
# Don't delete the users home room.
@room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
redirect_to current_user.main_room
begin
# Don't delete the users home room.
raise I18n.t("room.delete.home_room") if @room == @room.owner.main_room
@room.destroy
rescue => e
flash[:alert] = I18n.t("room.delete.fail", error: e)
else
flash[:success] = I18n.t("room.delete.success")
end
redirect_back fallback_location: current_user.main_room
end
# POST /room/join
@ -162,7 +168,7 @@ class RoomsController < ApplicationController
begin
options = params[:room].nil? ? params : params[:room]
raise "Room name can't be blank" if options[:name].blank?
raise "Unauthorized Request" if !@room.owned_by?(current_user) || @room == current_user.main_room
raise "Unauthorized Request" if @room == current_user.main_room
# Update the rooms values
room_settings_string = create_room_settings_string(options)
@ -179,7 +185,7 @@ class RoomsController < ApplicationController
flash[:alert] = I18n.t("room.update_settings_error")
end
redirect_to room_path
redirect_back fallback_location: room_path(@room)
end
# GET /:room_uid/logout
@ -222,9 +228,9 @@ class RoomsController < ApplicationController
@room = Room.find_by!(uid: params[:room_uid])
end
# Ensure the user is logged into the room they are accessing.
def verify_room_ownership
return redirect_to root_path unless @room.owned_by?(current_user)
# Ensure the user either owns the room or is an admin of the room owner
def verify_room_ownership_or_admin
return redirect_to root_path if !@room.owned_by?(current_user) && !current_user&.admin_of?(@room.owner)
end
def validate_accepted_terms