aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb18
-rw-r--r--app/controllers/user_controller.rb12
-rw-r--r--app/models/public_body.rb18
-rw-r--r--app/models/user.rb11
4 files changed, 31 insertions, 28 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index dcaaa432c..17eba911f 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -50,23 +50,7 @@ class PublicBodyController < ApplicationController
respond_to do |format|
format.html { @has_json = true }
- format.json {
- render :json => {
- :id => @public_body.id,
- :url_name => @public_body.url_name,
- :name => @public_body.name,
- :short_name => @public_body.short_name,
- # :request_email # we hide this behind a captcha, to stop people doing bulk requests easily
- :created_at => @public_body.created_at,
- :updated_at => @public_body.updated_at,
- # don't add the history as some edit comments contain sensitive information
- # :version, :last_edit_editor, :last_edit_comment
- :home_page => @public_body.calculated_home_page,
- :notes => @public_body.notes,
- :publication_scheme => @public_body.publication_scheme,
- :tags => @public_body.tag_array,
- }
- }
+ format.json { render :json => @public_body.json_for_api }
end
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 1fa3a1778..87152b7ca 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -55,17 +55,7 @@ class UserController < ApplicationController
respond_to do |format|
format.html { @has_json = true }
- format.json {
- render :json => {
- :id => @display_user.id,
- :url_name => @display_user.url_name,
- :name => @display_user.name,
- :ban_text => @display_user.ban_text,
- :about_me => @display_user.about_me,
- # :profile_photo => @display_user.profile_photo # ought to have this, but too hard to get URL out for now
- # created_at / updated_at we only show the year on the main page for privacy reasons, so don't put here
- }
- }
+ format.json { render :json => @display_user.json_for_api }
end
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 2c13d1bf3..de3ac3552 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -412,6 +412,24 @@ class PublicBody < ActiveRecord::Base
self.notes.gsub(/<\/?[^>]*>/, "")
end
+ def json_for_api
+ return {
+ :id => self.id,
+ :url_name => self.url_name,
+ :name => self.name,
+ :short_name => self.short_name,
+ # :request_email # we hide this behind a captcha, to stop people doing bulk requests easily
+ :created_at => self.created_at,
+ :updated_at => self.updated_at,
+ # don't add the history as some edit comments contain sensitive information
+ # :version, :last_edit_editor, :last_edit_comment
+ :home_page => self.calculated_home_page,
+ :notes => self.notes,
+ :publication_scheme => self.publication_scheme,
+ :tags => self.tag_array,
+ }
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 847959ce7..7f85a2c4f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -326,6 +326,17 @@ class User < ActiveRecord::Base
return text
end
+ def json_for_api
+ return {
+ :id => self.id,
+ :url_name => self.url_name,
+ :name => self.name,
+ :ban_text => self.ban_text,
+ :about_me => self.about_me,
+ # :profile_photo => self.profile_photo # ought to have this, but too hard to get URL out for now
+ # created_at / updated_at we only show the year on the main page for privacy reasons, so don't put here
+ }
+ end
private