Skip to content

Commit

Permalink
Update ProfessionalStandingRequestPolicy
Browse files Browse the repository at this point in the history
This updates the policy according to the new verification flow, where we
will have three actions to be taken on professional standing requests
(request, verify and review).
  • Loading branch information
thomasleese committed Oct 5, 2023
1 parent faf4589 commit cd8114d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProfessionalStandingRequestsController < BaseController
before_action :set_variables

def edit_location
authorize [:assessor_interface, professional_standing_request]
authorize [:assessor_interface, professional_standing_request], :show?

@form =
ProfessionalStandingRequestLocationForm.new(
Expand All @@ -18,7 +18,7 @@ def edit_location
end

def update_location
authorize [:assessor_interface, professional_standing_request]
authorize [:assessor_interface, professional_standing_request], :show?

@form =
ProfessionalStandingRequestLocationForm.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# frozen_string_literal: true

class AssessorInterface::ProfessionalStandingRequestPolicy < ApplicationPolicy
def update_location?
def show?
true
end

alias_method :edit_location?, :update_location?
def update_request?
user.verify_permission
end

alias_method :edit_request?, :update_request?

def update_verify?
user.verify_permission
end

alias_method :edit_verify?, :update_verify?

def update_review?
user.award_decline_permission
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/staff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
support_console_permission { true }
end

trait :with_verification_permission do
trait :with_verify_permission do
verify_permission { true }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
subject(:show?) { policy.show? }

let(:user) { create(:staff, :confirmed) }
it { is_expected.to be false }
it { is_expected.to be true }
end

describe "#create?" do
Expand Down Expand Up @@ -52,18 +52,24 @@
it { is_expected.to be false }
end

describe "#update_location?" do
subject(:update_location?) { policy.update_location? }
describe "#update_request?" do
subject(:update_request?) { policy.update_request? }
it_behaves_like "a policy method requiring the verify permission"
end

let(:user) { create(:staff, :confirmed) }
it { is_expected.to be true }
describe "#edit_request?" do
subject(:edit_request?) { policy.edit_request? }
it_behaves_like "a policy method requiring the verify permission"
end

describe "#edit_review?" do
subject(:edit_location?) { policy.edit_location? }
describe "#update_verify?" do
subject(:update_review?) { policy.update_verify? }
it_behaves_like "a policy method requiring the verify permission"
end

let(:user) { create(:staff, :confirmed) }
it { is_expected.to be true }
describe "#edit_verify?" do
subject(:edit_review?) { policy.edit_verify? }
it_behaves_like "a policy method requiring the verify permission"
end

describe "#update_review?" do
Expand Down
20 changes: 16 additions & 4 deletions spec/support/shared_examples/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,38 @@
end
end

RSpec.shared_examples "a policy method requiring the withdraw permission" do
RSpec.shared_examples "a policy method requiring the support console permission" do
context "without permission" do
let(:user) { create(:staff) }
it { is_expected.to be false }
end

context "with permission" do
let(:user) { create(:staff, :with_withdraw_permission) }
let(:user) { create(:staff, :with_support_console_permission) }
it { is_expected.to be true }
end
end

RSpec.shared_examples "a policy method requiring the support console permission" do
RSpec.shared_examples "a policy method requiring the verify permission" do
context "without permission" do
let(:user) { create(:staff) }
it { is_expected.to be false }
end

context "with permission" do
let(:user) { create(:staff, :with_support_console_permission) }
let(:user) { create(:staff, :with_verify_permission) }
it { is_expected.to be true }
end
end

RSpec.shared_examples "a policy method requiring the withdraw permission" do
context "without permission" do
let(:user) { create(:staff) }
it { is_expected.to be false }
end

context "with permission" do
let(:user) { create(:staff, :with_withdraw_permission) }
it { is_expected.to be true }
end
end

0 comments on commit cd8114d

Please sign in to comment.