aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_public_body_controller.rb7
-rw-r--r--app/controllers/general_controller.rb35
-rw-r--r--app/controllers/public_body_controller.rb33
-rw-r--r--app/controllers/request_controller.rb13
-rw-r--r--app/controllers/user_controller.rb15
5 files changed, 70 insertions, 33 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 98d4c1044..f88b25572 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -77,6 +77,7 @@ class AdminPublicBodyController < AdminController
@locale = self.locale_from_params()
PublicBody.with_locale(@locale) do
@public_body = PublicBody.find(params[:id])
+ render
end
end
@@ -84,6 +85,7 @@ class AdminPublicBodyController < AdminController
@locale = self.locale_from_params()
PublicBody.with_locale(@locale) do
@public_body = PublicBody.new
+ render
end
end
@@ -106,6 +108,7 @@ class AdminPublicBodyController < AdminController
PublicBody.with_locale(@locale) do
@public_body = PublicBody.find(params[:id])
@public_body.last_edit_comment = ""
+ render
end
end
@@ -136,9 +139,9 @@ class AdminPublicBodyController < AdminController
public_body.tag_string = ""
public_body.destroy
+ flash[:notice] = "PublicBody was successfully destroyed."
+ redirect_to admin_url('body/list')
end
- flash[:notice] = "PublicBody was successfully destroyed."
- redirect_to admin_url('body/list')
end
def import_csv
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index bdbcfcdd4..21f3edbb1 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -20,19 +20,35 @@ class GeneralController < ApplicationController
# New, improved front page!
def frontpage
- # This is too slow
+
+ behavior_cache do
+
+ # get some example searches and public bodies to display
+ # either from config, or based on a (slow!) query if not set
+ body_short_names = MySociety::Config.get('FRONTPAGE_PUBLICBODY_EXAMPLES', '').split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
@locale = self.locale_from_params()
locale_condition = 'public_body_translations.locale = ?'
conditions = [locale_condition, @locale]
PublicBody.with_locale(@locale) do
- @popular_bodies = PublicBody.find(:all,
- :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c",
- :order => "c desc",
- :limit => 32,
- :conditions => conditions,
- :joins => :translations
- )
- end
+ if body_short_names.empty?
+ # This is too slow
+ @popular_bodies = PublicBody.find(:all,
+ :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c",
+ :order => "c desc",
+ :limit => 32,
+ :conditions => conditions,
+ :joins => :translations
+ )
+ else
+ @popular_bodies = PublicBody.find(:all,
+ :conditions => conditions + ["url_name in (" + body_short_names + ")"],
+ :joins => :translations)
+ end
+ end
+ @search_examples = MySociety::Config.get('FRONTPAGE_SEARCH_EXAMPLES', '').split(/\s*;\s*/)
+ if @search_examples.empty?
+ @search_examples = @popular_bodies.map { |body| body.name }
+ end
# Get some successful requests #
begin
query = 'variety:response (status:successful OR status:partially_successful)'
@@ -44,6 +60,7 @@ class GeneralController < ApplicationController
rescue
@successful_request_events = []
end
+ end
end
# Display WhatDoTheyKnow category from mySociety blog
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index e31b52f9d..c74959b17 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -20,11 +20,16 @@ class PublicBodyController < ApplicationController
PublicBody.with_locale(@locale) do
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise "None found" if @public_body.nil? # XXX proper 404
- return redirect_to :back if @public_body.url_name.nil?
- # If found by historic name, redirect to new name
- redirect_to show_public_body_url(:url_name => @public_body.url_name) if
- @public_body.url_name != params[:url_name]
-
+ if @public_body.url_name.nil?
+ redirect_to :back
+ return
+ end
+ # If found by historic name, or alternate locale name, redirect to new name
+ if @public_body.url_name != params[:url_name]
+ redirect_to show_public_body_url(:url_name => @public_body.url_name)
+ return
+ end
+
set_last_body(@public_body)
top_url = main_url("/")
@@ -51,9 +56,10 @@ class PublicBodyController < ApplicationController
@feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
respond_to do |format|
- format.html { @has_json = true }
+ format.html { @has_json = true; render :template => "public_body/show"}
format.json { render :json => @public_body.json_for_api }
end
+
end
end
@@ -99,13 +105,6 @@ class PublicBodyController < ApplicationController
and has_tag_string_tags.model = \'PublicBody\'
and has_tag_string_tags.name = ?) > 0', @locale, @tag]
end
- PublicBody.with_locale(@locale) do
- @public_bodies = PublicBody.paginate(
- :order => "public_body_translations.name", :page => params[:page], :per_page => 1000, # fit all councils on one page
- :conditions => conditions,
- :joins => :translations
- )
- end
if @tag.size == 1
@description = _("beginning with") + " '" + @tag + "'"
else
@@ -114,6 +113,14 @@ class PublicBodyController < ApplicationController
@description = @tag
end
end
+ PublicBody.with_locale(@locale) do
+ @public_bodies = PublicBody.paginate(
+ :order => "public_body_translations.name", :page => params[:page], :per_page => 1000, # fit all councils on one page
+ :conditions => conditions,
+ :joins => :translations
+ )
+ render :template => "public_body/list"
+ end
end
# Used so URLs like /local/islington work, for use e.g. writing to a local paper.
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 8987768e6..b17717002 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -6,6 +6,8 @@
#
# $Id: request_controller.rb,v 1.192 2009-10-19 19:26:40 francis Exp $
+require 'alaveteli_file_types'
+
class RequestController < ApplicationController
before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ]
protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details
@@ -52,7 +54,7 @@ class RequestController < ApplicationController
@last_info_request_event_id = @info_request.last_event_id_needing_description
@new_responses_count = @info_request.events_needing_description.select {|i| i.event_type == 'response'}.size
-
+1
# Sidebar stuff
# ... requests that have similar imporant terms
behavior_cache :tag => ['similar', @info_request.id] do
@@ -74,10 +76,10 @@ class RequestController < ApplicationController
@last_response = @info_request.get_last_response
respond_to do |format|
- format.html { @has_json = true }
+ format.html { @has_json = true; render :template => 'request/show'}
format.json { render :json => @info_request.json_for_api(true) }
end
- end
+ end
end
# Extra info about a request, such as event history
@@ -592,8 +594,7 @@ class RequestController < ApplicationController
if foi_fragment_cache_exists?(key_path)
cached = foi_fragment_cache_read(key_path)
- IncomingMessage # load global filename_to_mimetype XXX should move filename_to_mimetype to proper namespace
- response.content_type = filename_to_mimetype(params[:file_name].join("/")) or 'application/octet-stream'
+ response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream'
render_for_text(cached)
return
end
@@ -615,7 +616,7 @@ class RequestController < ApplicationController
@incoming_message.binary_mask_stuff!(@attachment.body, @attachment.content_type)
# we don't use @attachment.content_type here, as we want same mime type when cached in cache_attachments above
- response.content_type = filename_to_mimetype(params[:file_name].join("/")) or 'application/octet-stream'
+ response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream'
render :text => @attachment.body
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 823366957..2e3f6c9e0 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -257,7 +257,10 @@ class UserController < ApplicationController
return
end
- @signchangeemail = ChangeEmailValidator.new(params[:signchangeemail])
+ # validate taking into account the user_circumstance
+ validator_params = params[:signchangeemail].clone
+ validator_params[:user_circumstance] = session[:user_circumstance]
+ @signchangeemail = ChangeEmailValidator.new(validator_params)
@signchangeemail.logged_in_user = @user
if !@signchangeemail.valid?
@@ -279,8 +282,11 @@ class UserController < ApplicationController
# if not already, send a confirmation link to the new email address which logs
# them into the old email's user account, but with special user_circumstance
if (not session[:user_circumstance]) or (session[:user_circumstance] != "change_email")
- post_redirect = PostRedirect.new(:uri => signchangeemail_url(), :post_params => params,
- :circumstance => "change_email" # special login that lets you change your email
+ # don't store the password in the db
+ params[:signchangeemail].delete(:password)
+ post_redirect = PostRedirect.new(:uri => signchangeemail_url(),
+ :post_params => params,
+ :circumstance => "change_email" # special login that lets you change your email
)
post_redirect.user = @user
post_redirect.save!
@@ -297,6 +303,9 @@ class UserController < ApplicationController
# circumstance is 'change_email', so can actually change the email
@user.email = @signchangeemail.new_email
@user.save!
+
+ # Now clear the circumstance
+ session[:user_circumstance] = nil
flash[:notice] = _("You have now changed your email address used on {{site_name}}",:site_name=>site_name)
redirect_to user_url(@user)
end