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

AP-5442: Implement SCA firm permissions #7422

Merged
merged 6 commits into from
Nov 13, 2024
Merged
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
4 changes: 4 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def update_details_directly
ProviderDetailsCreator.call(self)
end

def sca_permissions?
user_permissions.map(&:role).include?("special_children_act")
end

def user_permissions
permissions.empty? ? firm_permissions : permissions
end
2 changes: 1 addition & 1 deletion app/services/legal_framework/proceeding_types/all.rb
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def call
result = JSON.parse(request.body).map { |pt_hash| ProceedingTypeStruct.new(pt_hash) }
# TODO: remove the below when the SCA feature flag is removed
# filter out SCA applications
result.select!(&:not_sca?) unless Setting.special_childrens_act?
result.select!(&:not_sca?) unless Setting.special_childrens_act? && @legal_aid_application.provider.sca_permissions?

# TODO: remove the below when the PLF feature flag is removed
# Filter out PLF applications
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

<%= form.govuk_radio_buttons_fieldset(:has_national_insurance_number,
legend: { text: page_title, size: "xl", tag: "h1" },
hint: { text: Setting.special_childrens_act? ? nil : t(".hint") }) do %>
hint: { text: Setting.special_childrens_act? && @legal_aid_application.provider.sca_permissions? ? nil : t(".hint") }) do %>

<%= form.govuk_radio_button(
:has_national_insurance_number,
1 change: 1 addition & 0 deletions db/seeds/permissions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class PermissionsPopulator
ROLES = {
# "example.permission.group" => "Description of example group",
"special_children_act" => "Allow the firm to access SCA proceedings",
}.freeze

def self.run

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Feature: Adding an SCA Secure Accommodation Order proceeding sets all client_involvement_types to Child
@javascript @vcr
Scenario: When a provider is adding proceedings and only adds a
Scenario: When a provider is adding proceedings and only adds a Secure Accommodation Order
Given I start the journey as far as the applicant page
And the feature flag for special_childrens_act is enabled
And the provider has SCA permissions

When I enter name 'Test', 'User'
Then I choose 'No'
6 changes: 6 additions & 0 deletions features/step_definitions/debug_steps.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,12 @@
Setting.setting.update!("#{flag}": value)
end

And(/^the provider has SCA permissions$/) do
# TODO: Remove when removing Setting.special_children_act
sca_permission = Permission.find_by(role: "special_children_act") || create(:permission, :special_children_act)
@registered_provider.firm.permissions << sca_permission
end

And(/^the MTR-A start date is in the past$/) do
# TODO: Remove when removing Setting.means_test_review_a
allow(Rails.configuration.x).to receive(:mtr_a_start_date).and_return(Date.yesterday)
8 changes: 8 additions & 0 deletions spec/factories/firms.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,14 @@
name { Faker::Company.name }
end

trait :with_sca_permissions do
permissions do
sca = Permission.find_by(role: "special_children_act")
sca = create(:permission, :special_children_act) if sca.nil?
[sca]
end
end

trait :with_no_permissions do
permissions { [] }
end
5 changes: 5 additions & 0 deletions spec/factories/permissions.rb
Original file line number Diff line number Diff line change
@@ -2,5 +2,10 @@
factory :permission do
sequence(:role) { |n| "role_#{n}" }
sequence(:description) { |n| "The description for role_#{n}" }

trait :special_children_act do
role { "special_children_act" }
description { "Allow the firm to access SCA proceedings" }
end
end
end
29 changes: 29 additions & 0 deletions spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
@@ -40,6 +40,35 @@
expect(provider.user_permissions).to be_empty
end
end

context "when the firm has SCA permissions" do
let(:firm) { create(:firm, :with_sca_permissions) }
let(:provider) { create(:provider, :with_no_permissions, firm:) }

it "returns a value" do
expect(provider.user_permissions).to be_a(ActiveRecord::Relation)
end
end
end

describe "sca_permissions?" do
context "with no permissions for provider and their firm" do
let(:firm) { create(:firm, :with_no_permissions) }
let(:provider) { create(:provider, :with_no_permissions, firm:) }

it "returns false" do
expect(provider.sca_permissions?).to be false
end
end

context "when the firm has SCA permissions" do
let(:firm) { create(:firm, :with_sca_permissions) }
let(:provider) { create(:provider, :with_no_permissions, firm:) }

it "returns a value" do
expect(provider.sca_permissions?).to be true
end
end
end

describe "#cms_apply_role?" do
32 changes: 28 additions & 4 deletions spec/services/legal_framework/proceeding_types/all_spec.rb
Original file line number Diff line number Diff line change
@@ -21,8 +21,20 @@
context "when the special children act setting is on" do
let(:sca_enabled) { true }

it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PB003]
context "and the firm has SCA permissions enabled" do
let(:firm) { create(:firm, :with_sca_permissions) }
let(:provider) { create(:provider, :with_no_permissions, firm:) }
let(:legal_aid_application) { create :legal_aid_application, provider: }

it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PB003]
end
end

context "and the firm does not have SCA permissions enabled" do
it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006]
end
end
end

@@ -44,8 +56,20 @@
let(:sca_enabled) { true }
let(:plf_enabled) { true }

it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PB003 PBM01]
context "and the firm has SCA permissions enabled" do
let(:firm) { create(:firm, :with_sca_permissions) }
let(:provider) { create(:provider, :with_no_permissions, firm:) }
let(:legal_aid_application) { create :legal_aid_application, provider: }

it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PB003 PBM01]
end
end

context "and the firm does not have SCA permissions enabled" do
it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PBM01]
end
end
end
end