forked from External/greenlight
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:
committed by
farhatahmad
parent
984e5cc085
commit
09de6b6739
@ -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
|
||||
|
Reference in New Issue
Block a user