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

Patch authority only response gatekeeper #1837

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
3 changes: 2 additions & 1 deletion lib/alavetelitheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def prepend_theme_assets
'school_late_calculator.rb',
'volunteer_contact_form.rb',
'data_breach.rb',
'excel_analyzer.rb']
'excel_analyzer.rb',
'authority_only_response_gatekeeper.rb']
require File.expand_path "../#{patch}", __FILE__
end

Expand Down
16 changes: 16 additions & 0 deletions lib/authority_only_response_gatekeeper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module AuthorityOnlyResponseGatekeeper
EXTRA_ALLOWED_EMAILS = [
{ public_body_id: 27, email: 'no-reply@cabinetoffice.ecase.co.uk' }
]

def allow?(mail)
public_body_id = info_request.public_body_id
email = MailHandler.get_from_address(mail)

return true if EXTRA_ALLOWED_EMAILS.any? do |a|
a[:public_body_id] == public_body_id && a[:email] == email
end

super
end
end
3 changes: 3 additions & 0 deletions lib/model_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def late_calculator
end
end

InfoRequest::ResponseGatekeeper::AuthorityOnly.
prepend AuthorityOnlyResponseGatekeeper

Legislation.refusals = {
foi: [
's 11', 's 12', 's 14', 's 21', 's 22', 's 30', 's 31', 's 35', 's 38',
Expand Down
38 changes: 38 additions & 0 deletions spec/authority_only_response_gatekeeper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require_relative 'spec_helper'

RSpec.describe AuthorityOnlyResponseGatekeeper do
let(:public_body) do
FactoryBot.create(
:public_body,
id: 27,
name: 'Cabinet Office',
request_email: 'foi@localhost'
)
end

let(:info_request) do
FactoryBot.create(
:info_request,
public_body: public_body,
allow_new_responses_from: 'authority_only'
)
end

def receive_from(from)
info_request.receive Mail.new(from: from), ''
end

it 'allows responses from main request email and extra addresses' do
expect { receive_from('foi@localhost') }.to change {
info_request.incoming_messages.count
}.from(0).to(1)

expect { receive_from('other@example.com') }.to_not change {
info_request.incoming_messages.count
}

expect { receive_from('no-reply@cabinetoffice.ecase.co.uk') }.to change {
info_request.incoming_messages.count
}.from(1).to(2)
end
end
Loading