Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReferenceRequestPolicy #1843

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module AssessorInterface
class ReferenceRequestsController < BaseController
before_action :authorize_assessor, except: %i[edit update_verify_references]

before_action :set_list_variables, only: %i[index update_verify_references]
before_action :set_individual_variables, only: %i[edit update]

def index
authorize %i[assessor_interface reference_request]

@form =
VerifyReferencesForm.new(
assessment:,
Expand All @@ -18,7 +18,7 @@ def index
end

def update_verify_references
authorize :assessor, :update?
authorize %i[assessor_interface reference_request], :update?

@form =
VerifyReferencesForm.new(assessment:, **verify_references_form_params)
Expand All @@ -31,12 +31,14 @@ def update_verify_references
end

def edit
authorize :assessor, :show?
authorize [:assessor_interface, requestable]

@form = RequestableReviewForm.new(requestable:)
end

def update
authorize [:assessor_interface, requestable]

@form =
RequestableReviewForm.new(
requestable:,
Expand Down
16 changes: 16 additions & 0 deletions app/policies/assessor_interface/reference_request_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class AssessorInterface::ReferenceRequestPolicy < ApplicationPolicy
def index?
user.assess_permission || user.verify_permission
end

def edit?
user.assess_permission || user.verify_permission ||
user.change_work_history_permission
end

def update?
user.assess_permission || user.verify_permission
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssessorInterface::ReferenceRequestPolicy do
it_behaves_like "a policy"

let(:user) { nil }
let(:record) { nil }

subject(:policy) { described_class.new(user, record) }

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

describe "#show?" do
subject(:show?) { policy.show? }

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

describe "#create?" do
subject(:create?) { policy.create? }

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

describe "#new?" do
subject(:new?) { policy.new? }

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

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

describe "#edit?" do
subject(:edit?) { policy.edit? }
it_behaves_like "a policy method requiring the assess permission"
it_behaves_like "a policy method requiring the change work history permission"
it_behaves_like "a policy method requiring the verify permission"
end

describe "#destroy?" do
subject(:destroy?) { policy.destroy? }

let(:user) { create(:staff, :confirmed) }
it { is_expected.to be false }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@

describe "#update?" do
subject(:update?) { policy.update? }
it_behaves_like "a policy method requiring change the work history permission"
it_behaves_like "a policy method requiring the change work history permission"
end

describe "#edit?" do
subject(:edit?) { policy.edit? }
it_behaves_like "a policy method requiring change the work history permission"
it_behaves_like "a policy method requiring the change work history permission"
end

describe "#destroy?" do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
end
end

RSpec.shared_examples "a policy method requiring change the work history permission" do
RSpec.shared_examples "a policy method requiring the change work history permission" do
context "without permission" do
let(:user) { create(:staff) }
it { is_expected.to be false }
Expand Down
Loading