From e3409e50e14a7513d81a3168cdd453b880174efb Mon Sep 17 00:00:00 2001 From: Tamara Temple Date: Mon, 25 Jan 2021 06:50:24 -0600 Subject: [PATCH] [750] Un-refactor edit action a bit Shows logic inherent in permissions, moves logic based on status to private method. This passes rubocop's length rules while keeping the necessary logic in front --- app/controllers/orders_controller.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index e735f8fa..dd5cbadf 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -35,7 +35,13 @@ def create def edit @order = Order.includes(order_details: :item).find(params[:id]) - determine_edit_view + if current_user.can_edit_order?(@order) + render_status_or_edit + elsif current_user.can_view_order?(@order) + render :show + else + redirect_to orders_path + end end def update @@ -45,15 +51,11 @@ def update private - def determine_edit_view - if current_user.can_edit_order?(@order) - if Rails.root.join("app/views/orders/status/#{@order.status}.html.erb").exist? - render "orders/status/#{@order.status}" - end - elsif current_user.can_view_order?(@order) - render :show + def render_status_or_edit + if Rails.root.join("app/views/orders/status/#{@order.status}.html.erb").exist? + render "orders/status/#{@order.status}" else - redirect_to orders_path + render :edit end end end