Skip to content

Commit

Permalink
Merge branch '3477-auto-tag-missing-email-bodies' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Sep 1, 2022
2 parents db16ae0 + 8c36499 commit 148934d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/models/public_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ def self.admin_title
validate :request_email_if_requestable

before_save :set_api_key!, :unless => :api_key
after_update :reindex_requested_from

after_save :update_missing_email_tag

after_update :reindex_requested_from

# Every public body except for the internal admin one is visible
scope :visible, -> { where("public_bodies.id <> #{ PublicBody.internal_admin_body.id }") }
Expand Down Expand Up @@ -975,4 +977,16 @@ def self.get_public_body_list_translated_condition(table, has_first_letter=false
end
result
end

def update_missing_email_tag
if missing_email?
add_tag_if_not_already_present('missing_email')
else
remove_tag('missing_email')
end
end

def missing_email?
!has_request_email?
end
end
1 change: 1 addition & 0 deletions app/views/admin_public_body/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<li><code>defunct</code> if the authority no longer exists</li>
<li><code>charity:NUMBER</code> if a registered charity</li>
<li><code>important_notes</code> if the notes have major implications on making a request to this authority</li>
<li><code>missing_email</code> is automatically applied (and removed) so that users can help source missing request addresses via a <%= link_to 'public search', list_public_bodies_by_tag_path('missing_email') %>.</li>
</ul>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Highlighted Features

* Automatically apply `missing_email` tag to bodies who are missing a request
email so that they can be found in a public list (Gareth Rees)
* Improve linking from outgoing & incoming message admin pages (Gareth Rees)
* Allow admins to destroy user post redirects (Gareth Rees)
* Use correct mime type for cached CSV attachments
Expand All @@ -11,6 +13,12 @@

## Upgrade Notes

* _Optional:_ Bodies missing a request email will automatically get tagged
`missing_email` as they are updated. If you want to automatically tag them all
in one go, run the following from the app root directory:

bin/rails runner "PublicBody.without_request_email.each(&:save)"

### Changed Templates

# 0.41.1.0
Expand Down
2 changes: 2 additions & 0 deletions lib/has_tag_string/has_tag_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def has_tag?(tag_as_string) # rubocop:disable Naming::PredicateName
false
end

alias tagged? has_tag?

class TagNotFound < StandardError
end

Expand Down
28 changes: 28 additions & 0 deletions spec/models/public_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@

end

describe '#save' do
subject { public_body.save }

context 'when a request email is added' do
let!(:public_body) do
FactoryBot.create(:blank_email_public_body, tag_string: 'missing_email')
end

before { public_body.request_email = 'added@example.com' }

it 'removes the missing email tag' do
subject
expect(public_body).not_to be_tagged('missing_email')
end
end

context 'when a request email is removed' do
let!(:public_body) { FactoryBot.create(:public_body) }

before { public_body.request_email = '' }

it 'adds the missing email tag' do
subject
expect(public_body).to be_tagged('missing_email')
end
end
end

describe '#name' do

it 'is invalid when nil' do
Expand Down

0 comments on commit 148934d

Please sign in to comment.