From 687233ebb171798baffb4bcd8078c1b4b30d6929 Mon Sep 17 00:00:00 2001 From: Mausam Pun Date: Tue, 17 Sep 2024 15:43:42 +0545 Subject: [PATCH] Fix the fetching of the vendor questions --- .../api/v2/vendor/product_questions_controller.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/spree/api/v2/vendor/product_questions_controller.rb b/app/controllers/spree/api/v2/vendor/product_questions_controller.rb index a6edf30..3bcb8cb 100644 --- a/app/controllers/spree/api/v2/vendor/product_questions_controller.rb +++ b/app/controllers/spree/api/v2/vendor/product_questions_controller.rb @@ -5,6 +5,7 @@ module Api module V2 module Vendor class ProductQuestionsController < ResourceController + before_action :load_vendor before_action :require_vendor_access # GET /api/v2/vendor/vendors/:vendor_id/questions @@ -64,13 +65,15 @@ def product_question_params end def resource - Spree::ProductQuestion.vendor_product_questions(params[:vendor_id]) + Spree::ProductQuestion.vendor_product_questions(@vendor.id) end - def require_vendor_access - vendor = Spree::Vendor.friendly.find(params[:vendor_id]) + def load_vendor + @vendor ||= Spree::Vendor.friendly.find(params[:vendor_id]) + end - raise CanCan::AccessDenied unless vendor.users.include?(spree_current_user) + def require_vendor_access + raise CanCan::AccessDenied unless @vendor.users.include?(spree_current_user) end end end