Skip to content

Commit

Permalink
Update mailer abilities
Browse files Browse the repository at this point in the history
Prevent requesters of old requests from being notified when their
request has been classified.

Fixes #2733
  • Loading branch information
gbp committed Feb 11, 2025
1 parent 92e3fd1 commit be93bab
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/mailers/mailer_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@ def initialize(user, **params)
@params = params

can :receive, :all

cannot :receive, 'request_mailer#old_unclassified_updated' do
info_request.created_at <= 6.months.ago
end
end

private

def info_request
params[:info_request]
end
end
4 changes: 3 additions & 1 deletion doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Highlighted Features

Add additional InfoRequest embargo scopes (Graeme Porteous)
* Prevent request classification notifications from being set if request is
older than 6 months (Graeme Porteous)
* Add additional InfoRequest embargo scopes (Graeme Porteous)

# 0.45.3.1

Expand Down
12 changes: 11 additions & 1 deletion spec/mailers/mailer_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@

describe 'RequestMailer#old_unclassified_updated' do
let(:name) { 'request_mailer#old_unclassified_updated' }
it { expect(ability).to be_able_to(:receive, name) }
let(:ability) { MailerAbility.new(user, info_request: info_request) }

context 'when info request when sent less than 6 months ago' do
let(:info_request) { double(:InfoRequest, created_at: 6.months.ago + 1) }
it { expect(ability).to be_able_to(:receive, name) }
end

context 'when info request when sent more than 6 months ago' do
let(:info_request) { double(:InfoRequest, created_at: 6.months.ago) }
it { expect(ability).not_to be_able_to(:receive, name) }
end
end

describe 'RequestMailer#not_clarified_alert' do
Expand Down
3 changes: 2 additions & 1 deletion spec/mailers/previews/request_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def info_request
url_title: 'a_request',
user: User.first,
public_body: PublicBody.first,
described_state: 'successful'
described_state: 'successful',
created_at: Time.now
)
end

Expand Down
20 changes: 20 additions & 0 deletions spec/mailers/request_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ def sent_alert_params(request, type)
expect(mail.subject).to eq('Someone has updated the status of your request')
end

it 'delivers the email' do
mail.deliver_now
expect(ActionMailer::Base.deliveries).to_not be_empty
end

context "when the user does not use default locale" do
before do
info_request.user.locale = 'es'
Expand All @@ -554,6 +559,21 @@ def sent_alert_params(request, type)
end
end

context 'when the info request was created over 6 months ago' do
let(:info_request) do
FactoryBot.create(
:info_request,
user: user, title: "Test request", public_body: public_body,
url_title: "test_request", created_at: 6.months.ago
)
end

it 'does not deliver the email' do
mail.deliver_now
expect(ActionMailer::Base.deliveries).to be_empty
end
end

it 'should tell them what status was picked' do
expect(mail.body).to match(/"refused."/)
end
Expand Down

0 comments on commit be93bab

Please sign in to comment.