diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-05-08 16:07:19 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-06-06 11:09:09 +0100 |
commit | 468e9d5dfbbf2896b97553b8bf145acd0e8b95ca (patch) | |
tree | 763f69ba7c617bbb74bd2a9b933ae2a3589164bc /app/models | |
parent | b2219112ad185d4e6b07ad439da9eabd4907e32d (diff) |
Extract public body CSV export to its own class
- SRP: Do one thing. PublicBodyCSV converts a
collection of bodies in to a CSV formatted
String
- Adds some parenthesis around parameters in
PublicBodyController#list_all_csv
- Let the controller handle what records to pull
out for the CSV export
Arguably this doesn't really need to be anything
to do with PublicBody, but it allows us to set
nice defaults.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_body.rb | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 03ec270ee..d0e5bbb9e 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -569,45 +569,6 @@ class PublicBody < ActiveRecord::Base return [errors, notes] end - # Returns all public bodies (except for the internal admin authority) as csv - def self.export_csv(output_filename) - CSV.open(output_filename, "w") do |csv| - csv << [ - 'Name', - 'Short name', - # deliberately not including 'Request email' - 'URL name', - 'Tags', - 'Home page', - 'Publication scheme', - 'Disclosure log', - 'Notes', - 'Created at', - 'Updated at', - 'Version', - ] - PublicBody.visible.find_each(:include => [:translations, :tags]) do |public_body| - # Skip bodies we use only for site admin - next if public_body.has_tag?('site_administration') - csv << [ - public_body.name, - public_body.short_name, - # DO NOT include request_email (we don't want to make it - # easy to spam all authorities with requests) - public_body.url_name, - public_body.tag_string, - public_body.calculated_home_page, - public_body.publication_scheme, - public_body.disclosure_log, - public_body.notes, - public_body.created_at, - public_body.updated_at, - public_body.version, - ] - end - end - end - # Does this user have the power of FOI officer for this body? def is_foi_officer?(user) user_domain = user.email_domain |