diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 97 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 158 |
2 files changed, 141 insertions, 114 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 1b79642d2..3e0613a1f 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -13,19 +13,22 @@ class AdminPublicBodyController < AdminController end def _lookup_query_internal - @query = params[:query] - if @query == "" - @query = nil - end - @page = params[:page] - if @page == "" - @page = nil + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + @query = params[:query] + if @query == "" + @query = nil + end + @page = params[:page] + if @page == "" + @page = nil + end + @public_bodies = PublicBody.paginate :order => "name", :page => @page, :per_page => 100, + :conditions => @query.nil? ? nil : ["lower(name) like lower('%'||?||'%') or + lower(short_name) like lower('%'||?||'%') or + lower(request_email) like lower('%'||?||'%')", @query, @query, @query] + @public_bodies_by_tag = PublicBody.find_by_tag(@query) end - @public_bodies = PublicBody.paginate :order => "name", :page => @page, :per_page => 100, - :conditions => @query.nil? ? nil : ["lower(name) like lower('%'||?||'%') or - lower(short_name) like lower('%'||?||'%') or - lower(request_email) like lower('%'||?||'%')", @query, @query, @query] - @public_bodies_by_tag = PublicBody.find_by_tag(@query) end def list @@ -69,51 +72,69 @@ class AdminPublicBodyController < AdminController end def show - @public_body = PublicBody.find(params[:id]) + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + @public_body = PublicBody.find(params[:id]) + end end def new - @public_body = PublicBody.new + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + @public_body = PublicBody.new + end end def create - params[:public_body][:last_edit_editor] = admin_http_auth_user() - @public_body = PublicBody.new(params[:public_body]) - if @public_body.save - flash[:notice] = 'PublicBody was successfully created.' - redirect_to admin_url('body/show/' + @public_body.id.to_s) - else - render :action => 'new' + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + params[:public_body][:last_edit_editor] = admin_http_auth_user() + @public_body = PublicBody.new(params[:public_body]) + if @public_body.save + flash[:notice] = 'PublicBody was successfully created.' + redirect_to admin_url('body/show/' + @public_body.id.to_s) + else + render :action => 'new' + end end end def edit - @public_body = PublicBody.find(params[:id]) - @public_body.last_edit_comment = "" + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + @public_body = PublicBody.find(params[:id]) + @public_body.last_edit_comment = "" + end end def update - params[:public_body][:last_edit_editor] = admin_http_auth_user() - @public_body = PublicBody.find(params[:id]) - if @public_body.update_attributes(params[:public_body]) - flash[:notice] = 'PublicBody was successfully updated.' - redirect_to admin_url('body/show/' + @public_body.id.to_s) - else - render :action => 'edit' + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + params[:public_body][:last_edit_editor] = admin_http_auth_user() + @public_body = PublicBody.find(params[:id]) + if @public_body.update_attributes(params[:public_body]) + flash[:notice] = 'PublicBody was successfully updated.' + redirect_to admin_url('body/show/' + @public_body.id.to_s) + else + render :action => 'edit' + end end end def destroy - public_body = PublicBody.find(params[:id]) + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + public_body = PublicBody.find(params[:id]) + + if public_body.info_requests.size > 0 + flash[:notice] = "There are requests associated with the authority, so can't destroy it" + redirect_to admin_url('body/show/' + public_body.id.to_s) + return + end - if public_body.info_requests.size > 0 - flash[:notice] = "There are requests associated with the authority, so can't destroy it" - redirect_to admin_url('body/show/' + public_body.id.to_s) - return + public_body.tag_string = "" + public_body.destroy end - - public_body.tag_string = "" - public_body.destroy flash[:notice] = "PublicBody was successfully destroyed." redirect_to admin_url('body/list') end diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 36fbc2b11..02abc12a8 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -11,69 +11,73 @@ class RequestController < ApplicationController protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details def show - # Look up by old style numeric identifiers - if params[:url_title].match(/^[0-9]+$/) - @info_request = InfoRequest.find(params[:url_title].to_i) - redirect_to request_url(@info_request) - return - end + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do - # Look up by new style text names - @info_request = InfoRequest.find_by_url_title(params[:url_title]) - if @info_request.nil? - raise "Request not found" - end - set_last_request(@info_request) + # Look up by old style numeric identifiers + if params[:url_title].match(/^[0-9]+$/) + @info_request = InfoRequest.find(params[:url_title].to_i) + redirect_to request_url(@info_request) + return + end - # Test for whole request being hidden - if !@info_request.user_can_view?(authenticated_user) - render :template => 'request/hidden', :status => 410 # gone - return - end - - # Other parameters - @info_request_events = @info_request.info_request_events - @status = @info_request.calculate_status - @collapse_quotes = params[:unfold] ? false : true - @update_status = params[:update_status] ? true : false - @is_owning_user = @info_request.is_owning_user?(authenticated_user) - @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil? - - if @update_status - return if !@is_owning_user && !authenticated_as_user?(@info_request.user, - :web => "To update the status of this FOI request", - :email => "Then you can update the status of your request to " + @info_request.public_body.name + ".", - :email_subject => "Update the status of your request to " + @info_request.public_body.name - ) - end - - @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 - - # Sidebar stuff - # ... requests that have similar imporant terms - behavior_cache :tag => ['similar', @info_request.id] do - begin - limit = 10 - @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, - :limit => limit, :collapse_by_prefix => 'request_collapse') - @xapian_similar_more = (@xapian_similar.matches_estimated > limit) - rescue - @xapian_similar = nil + # Look up by new style text names + @info_request = InfoRequest.find_by_url_title(params[:url_title]) + if @info_request.nil? + raise "Request not found" end - end - - # Track corresponding to this page - @track_thing = TrackThing.create_track_for_request(@info_request) - @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] + set_last_request(@info_request) - # For send followup link at bottom - @last_response = @info_request.get_last_response + # Test for whole request being hidden + if !@info_request.user_can_view?(authenticated_user) + render :template => 'request/hidden', :status => 410 # gone + return + end + + # Other parameters + @info_request_events = @info_request.info_request_events + @status = @info_request.calculate_status + @collapse_quotes = params[:unfold] ? false : true + @update_status = params[:update_status] ? true : false + @is_owning_user = @info_request.is_owning_user?(authenticated_user) + @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil? + + if @update_status + return if !@is_owning_user && !authenticated_as_user?(@info_request.user, + :web => "To update the status of this FOI request", + :email => "Then you can update the status of your request to " + @info_request.public_body.name + ".", + :email_subject => "Update the status of your request to " + @info_request.public_body.name + ) + end + + @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 + + # Sidebar stuff + # ... requests that have similar imporant terms + behavior_cache :tag => ['similar', @info_request.id] do + begin + limit = 10 + @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, + :limit => limit, :collapse_by_prefix => 'request_collapse') + @xapian_similar_more = (@xapian_similar.matches_estimated > limit) + rescue + @xapian_similar = nil + end + end + + # Track corresponding to this page + @track_thing = TrackThing.create_track_for_request(@info_request) + @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.json { render :json => @info_request.json_for_api(true) } - end + # For send followup link at bottom + @last_response = @info_request.get_last_response + + respond_to do |format| + format.html { @has_json = true } + format.json { render :json => @info_request.json_for_api(true) } + end + end end # Extra info about a request, such as event history @@ -666,28 +670,30 @@ class RequestController < ApplicationController # FOI officers can upload a response def upload_response - @info_request = InfoRequest.find_by_url_title(params[:url_title]) - - @reason_params = { - :web => "To upload a response, you must be logged in using an email address from " + CGI.escapeHTML(@info_request.public_body.name), - :email => "Then you can upload an FOI response. ", - :email_subject => "Confirm your account on WhatDoTheyKnow.com" - } - if !authenticated?(@reason_params) - return - end + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + @info_request = InfoRequest.find_by_url_title(params[:url_title]) + + @reason_params = { + :web => "To upload a response, you must be logged in using an email address from " + CGI.escapeHTML(@info_request.public_body.name), + :email => "Then you can upload an FOI response. ", + :email_subject => "Confirm your account on WhatDoTheyKnow.com" + } + if !authenticated?(@reason_params) + return + end - if !@info_request.public_body.is_foi_officer?(@user) - domain_required = @info_request.public_body.foi_officer_domain_required - if domain_required.nil? - render :template => 'user/wrong_user_unknown_email' + if !@info_request.public_body.is_foi_officer?(@user) + domain_required = @info_request.public_body.foi_officer_domain_required + if domain_required.nil? + render :template => 'user/wrong_user_unknown_email' + return + end + @reason_params[:user_name] = "an email @" + domain_required + render :template => 'user/wrong_user' return end - @reason_params[:user_name] = "an email @" + domain_required - render :template => 'user/wrong_user' - return end - if params[:submitted_upload_response] file_name = nil file_content = nil |