aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb35
-rw-r--r--app/models/public_body.rb37
2 files changed, 38 insertions, 34 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 12d03765b..8a4a65820 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -146,40 +146,7 @@ class PublicBodyController < ApplicationController
end
def list_all_csv
- public_bodies = PublicBody.find(:all, :order => 'url_name',
- :include => [:translations, :tags])
- report = FasterCSV.generate() do |csv|
- csv << [
- 'Name',
- 'Short name',
- # deliberately not including 'Request email'
- 'URL name',
- 'Tags',
- 'Home page',
- 'Publication scheme',
- 'Disclosure log',
- 'Created at',
- 'Updated at',
- 'Version',
- ]
- public_bodies.each do |public_body|
- 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.created_at,
- public_body.updated_at,
- public_body.version,
- ]
- end
- end
- send_data(report, :type=> 'text/csv; charset=utf-8; header=present',
+ send_data(PublicBody.export_csv, :type=> 'text/csv; charset=utf-8; header=present',
:filename => 'all-authorities.csv',
:disposition =>'attachment', :encoding => 'utf8')
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 3bcf0e75d..933dc8fb1 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -500,6 +500,43 @@ class PublicBody < ActiveRecord::Base
return [errors, notes]
end
+ # Returns all public bodies (except for the internal admin authority) as csv
+ def self.export_csv
+ public_bodies = PublicBody.visible.find(:all, :order => 'url_name',
+ :include => [:translations, :tags])
+ FasterCSV.generate() do |csv|
+ csv << [
+ 'Name',
+ 'Short name',
+ # deliberately not including 'Request email'
+ 'URL name',
+ 'Tags',
+ 'Home page',
+ 'Publication scheme',
+ 'Notes',
+ 'Created at',
+ 'Updated at',
+ 'Version',
+ ]
+ public_bodies.each do |public_body|
+ 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.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