diff --git a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb index ae275e8214b..393bd98f400 100644 --- a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb +++ b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb @@ -5,19 +5,19 @@ module V0 class InProgressFormsController < ApplicationController def update @form = find_form || build_form - authorize @form + authorize(@form, :update?, policy_class: AccreditedRepresentativePortal::InProgressFormPolicy) @form.update!( form_data: params[:form_data], metadata: params[:metadata] ) - render json: InProgressFormSerializer.new(form) + render json: InProgressFormSerializer.new(@form) end def show @form = find_form - authorize @form + authorize(@form, :show?, policy_class: AccreditedRepresentativePortal::InProgressFormPolicy) render json: @form&.data_and_metadata || {} end diff --git a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb index 911f8299664..9b9cdbcceef 100644 --- a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb +++ b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb @@ -27,7 +27,9 @@ def show private def in_progress_forms - policy_scope(InProgressForm).map do |form| + policy_scope( + InProgressForm, policy_scope_class: AccreditedRepresentativePortal::InProgressFormPolicy::Scope + ).map do |form| { form: form.form_id, metadata: form.metadata, diff --git a/modules/accredited_representative_portal/app/policies/in_progress_forms_policy.rb b/modules/accredited_representative_portal/app/policies/accredited_representative_portal/in_progress_form_policy.rb similarity index 83% rename from modules/accredited_representative_portal/app/policies/in_progress_forms_policy.rb rename to modules/accredited_representative_portal/app/policies/accredited_representative_portal/in_progress_form_policy.rb index e35ef7c0087..85053c01878 100644 --- a/modules/accredited_representative_portal/app/policies/in_progress_forms_policy.rb +++ b/modules/accredited_representative_portal/app/policies/accredited_representative_portal/in_progress_form_policy.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module AccreditedRepresentativePortal - class InProgressFormsPolicy < ApplicationPolicy + class InProgressFormPolicy < ApplicationPolicy def update? authorize end @@ -30,7 +30,7 @@ def resolve private def authorize - return false unless @current_user + return false unless user true end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/application_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/application_spec.rb index df7511e38b8..1ad028d0a2f 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/application_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/application_spec.rb @@ -19,6 +19,7 @@ AccreditedRepresentativePortal::Engine.routes.draw do get 'arbitrary', to: 'arbitrary#arbitrary' end + allow_any_instance_of(AccreditedRepresentativePortal::ApplicationController).to receive(:verify_pundit_authorization) end after do diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/form21a_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/form21a_spec.rb index ab55945e6c5..f17d4062b02 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/form21a_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/form21a_spec.rb @@ -21,6 +21,8 @@ let(:representative_user) { create(:representative_user) } before do + # TODO: Remove next line when Pundit authorization is added + allow_any_instance_of(::AccreditedRepresentativePortal::V0::Form21aController).to receive(:verify_pundit_authorization) Flipper.enable(:accredited_representative_portal_pilot) login_as(representative_user) end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb index c6b81b8dd60..622d2bdeaf7 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb @@ -6,6 +6,7 @@ let(:representative_user) { create(:representative_user) } let(:form_id) { '21a' } let(:headers) { { 'Content-Type' => 'application/json' } } + let!(:in_progress_form) { create(:in_progress_form) } before do Flipper.enable(:accredited_representative_portal_pilot)