From e517f41f55143fb28ba32409099ea559e18ebafe Mon Sep 17 00:00:00 2001 From: Nils Bartels Date: Wed, 20 Dec 2023 10:51:06 +0100 Subject: [PATCH] quick reservation, check if users tenant is nil; rubocop --- app/controllers/profiles_controller.rb | 2 +- app/controllers/reservations_controller.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index cb4d641..dc33564 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -15,7 +15,7 @@ def update render :edit end end - + private # Use callbacks to share common setup or constraints between actions. def set_profile diff --git a/app/controllers/reservations_controller.rb b/app/controllers/reservations_controller.rb index 109f757..123ef03 100644 --- a/app/controllers/reservations_controller.rb +++ b/app/controllers/reservations_controller.rb @@ -38,6 +38,11 @@ def create # quick reservation if patched_params["desk_id"].nil? + if current_user.tenant.nil? + redirect_to root_path, alert: "Cannot create a quick reservation without configured user tenant. Please configure tenant in your profile." + return + end + # the .to_a is important, as we do not want to call .delete on the collection of Desks available_desks = Desk.includes(room: { floor: { location: :tenant } }).all.order("RANDOM()").load_async.to_a available_desks.delete_if { |desk| desk.room.floor.location.tenant.id != current_user.tenant.id }