-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1837 from mysociety/authority-only-response-gatek…
…eeper Patch authority only response gatekeeper
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |