Skip to content

Commit

Permalink
Merge pull request #1837 from mysociety/authority-only-response-gatek…
Browse files Browse the repository at this point in the history
…eeper

Patch authority only response gatekeeper
  • Loading branch information
gbp authored Aug 13, 2024
2 parents fe3d975 + 42c4416 commit ef69b92
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
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

0 comments on commit ef69b92

Please sign in to comment.