diff --git a/lib/alavetelitheme.rb b/lib/alavetelitheme.rb index 8ffe3d1b..7ccd518c 100644 --- a/lib/alavetelitheme.rb +++ b/lib/alavetelitheme.rb @@ -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 diff --git a/lib/authority_only_response_gatekeeper.rb b/lib/authority_only_response_gatekeeper.rb new file mode 100644 index 00000000..1c3bcb87 --- /dev/null +++ b/lib/authority_only_response_gatekeeper.rb @@ -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 diff --git a/lib/model_patches.rb b/lib/model_patches.rb index 56a1b9e4..1f172e4e 100644 --- a/lib/model_patches.rb +++ b/lib/model_patches.rb @@ -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', diff --git a/spec/authority_only_response_gatekeeper_spec.rb b/spec/authority_only_response_gatekeeper_spec.rb new file mode 100644 index 00000000..7d819371 --- /dev/null +++ b/spec/authority_only_response_gatekeeper_spec.rb @@ -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