From 92cb0bbe1e10716bc6b3a7002f5191716a4229bd Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Fri, 16 Aug 2024 08:40:03 +0100 Subject: [PATCH] Add special not_requestable tag Fixes #8365 --- app/helpers/public_body_helper.rb | 4 ++++ app/models/public_body.rb | 23 +++++++++++++++---- spec/factories/public_bodies.rb | 4 ++++ spec/helpers/public_body_helper_spec.rb | 6 +++++ spec/models/public_body_spec.rb | 30 +++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb index e061278d85..b68fea0391 100644 --- a/app/helpers/public_body_helper.rb +++ b/app/helpers/public_body_helper.rb @@ -18,6 +18,10 @@ def public_body_not_requestable_reasons(public_body) reasons.push _('Freedom of Information law does not apply to this authority, so you cannot make a request to it.') end + if public_body.not_requestable? + reasons.push _('We are unable to make requests to this authority.') + end + unless public_body.has_request_email? # Make the authority appear requestable to encourage users to help find # the authority's email address diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 21dbe10819..ada036a6c3 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -68,7 +68,11 @@ def self.admin_title # Any PublicBody tagged with any of the follow tags won't be returned in the # batch authority search results or batch category UI - cattr_accessor :batch_excluded_tags, default: %w[not_apply defunct] + cattr_accessor :batch_excluded_tags, default: %w[ + defunct + not_apply + not_requestable + ] has_many :info_requests, -> { order(created_at: :desc) }, @@ -352,6 +356,13 @@ def defunct? scope :not_defunct, -> { without_tag('defunct') } + # If tagged "not_requestable", then requests can't be made to the authority + def not_requestable? + has_tag?('not_requestable') + end + + scope :requestable, -> { without_tag('not_requestable') } + # Are all requests to this body under the Environmental Information # Regulations? def eir_only? @@ -364,10 +375,12 @@ def site_administration? # Can an FOI (etc.) request be made to this body? def is_requestable? - has_request_email? && !defunct? && !not_apply? + has_request_email? && !defunct? && !not_apply? && !not_requestable? end - scope :is_requestable, -> { with_request_email.not_defunct.foi_applies } + scope :is_requestable, -> { + with_request_email.not_defunct.foi_applies.requestable + } # Strict superset of is_requestable? def is_followupable? @@ -384,6 +397,8 @@ def not_requestable_reason 'defunct' elsif not_apply? 'not_apply' + elsif not_requestable? + 'not_requestable' elsif !has_request_email? 'bad_contact' else @@ -392,7 +407,7 @@ def not_requestable_reason end def special_not_requestable_reason? - defunct? || not_apply? + defunct? || not_apply? || not_requestable? end def created_at_numeric diff --git a/spec/factories/public_bodies.rb b/spec/factories/public_bodies.rb index 9b28268ae7..950fcb6768 100644 --- a/spec/factories/public_bodies.rb +++ b/spec/factories/public_bodies.rb @@ -42,6 +42,10 @@ tag_string { 'not_apply' } end + trait :not_requestable do + tag_string { 'not_requestable' } + end + trait :eir_only do tag_string { 'eir_only' } end diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index fb6426e348..48a29b87cb 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -12,6 +12,12 @@ expect(public_body_not_requestable_reasons(@body)).to eq([]) end + it 'includes a reason if the authority is not requestable' do + @body.tag_string = 'not_requestable' + msg = 'We are unable to make requests to this authority.' + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + it 'includes a reason if the law does not apply to the authority' do @body.tag_string = 'not_apply' msg = 'Freedom of Information law does not apply to this authority, ' \ diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 2838d8b51a..6dc7852af6 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -2112,6 +2112,21 @@ def set_default_attributes(public_body) end end + describe '.requestable' do + subject { PublicBody.requestable } + + let!(:public_body) { FactoryBot.create(:public_body) } + let!(:not_requestable) { FactoryBot.create(:public_body, :not_requestable) } + + it 'include active bodies' do + is_expected.to include(public_body) + end + + it 'does not include not requestable bodies' do + is_expected.to_not include(not_requestable) + end + end + describe '.not_defunct' do subject { PublicBody.not_defunct } @@ -2142,6 +2157,11 @@ def set_default_attributes(public_body) expect(@body.is_requestable?).to eq(false) end + it 'should return false if the body is not requestable' do + allow(@body).to receive(:not_requestable?).and_return true + expect(@body.is_requestable?).to eq(false) + end + it 'should return false there is no request_email' do allow(@body).to receive(:has_request_email?).and_return false expect(@body.is_requestable?).to eq(false) @@ -2164,6 +2184,7 @@ def set_default_attributes(public_body) let!(:blank_body) { FactoryBot.create(:blank_email_public_body) } let!(:defunct_body) { FactoryBot.create(:public_body, :defunct) } let!(:not_apply_body) { FactoryBot.create(:public_body, :not_apply) } + let!(:not_requestable) { FactoryBot.create(:public_body, :not_requestable) } it 'includes return requestable body' do is_expected.to include(public_body) @@ -2180,6 +2201,10 @@ def set_default_attributes(public_body) it 'does not include bodies where FOI/EIR is not applicable' do is_expected.to_not include(not_apply_body) end + + it 'does not include bodies which are not requestable' do + is_expected.to_not include(not_requestable) + end end describe '#is_followupable?' do @@ -2212,6 +2237,11 @@ def set_default_attributes(public_body) expect(@body.not_requestable_reason).to eq('not_apply') end + it 'should return "not_requestable" if the body is not requestable' do + allow(@body).to receive(:not_requestable?).and_return true + expect(@body.not_requestable_reason).to eq('not_requestable') + end + it 'should return "bad_contact" there is no request_email' do allow(@body).to receive(:has_request_email?).and_return false expect(@body.not_requestable_reason).to eq('bad_contact')