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

[#8365] Add special not_requestable tag #8366

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions app/helpers/public_body_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% on the phrasing here but don't have an immediate suggestion. @HelenWDTK any thoughts?

end

unless public_body.has_request_email?
# Make the authority appear requestable to encourage users to help find
# the authority's email address
Expand Down
23 changes: 19 additions & 4 deletions app/models/public_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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?
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_requestable and requestable scopes feel quite prone to confusion. I'd be inclined to go with:

with_request_email.not_defunct.foi_applies.without_tag('not_requestable')

}

# Strict superset of is_requestable?
def is_followupable?
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/public_bodies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/public_body_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' \
Expand Down
30 changes: 30 additions & 0 deletions spec/models/public_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
Loading