From 9925d8f83864dc740d9b284a9e472d422dba12fb Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 26 Jul 2011 22:07:30 +0200 Subject: Adapting New Request flow to new wireframes: added type ahead search when creating new requests --- app/controllers/request_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 472f18f6e..b6111b087 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -736,5 +736,17 @@ class RequestController < ApplicationController return end end + + # Type ahead search + def search_typeahead + # Since acts_as_xapian doesn't support the Partial match flag, we work around it + # by making the last work a wildcard, which is quite the same + query = params[:q] + '*' + + query = query.split(' ').join(' OR ') # XXX: HACK for OR instead of default AND! + @xapian_requests = perform_search([InfoRequestEvent], query, 'relevant', 'request_collapse', 5) + + render :partial => "request/search_ahead.rhtml" + end end -- cgit v1.2.3 From 755ac9e6e8cc194d771ee59d7fe815fe72454a85 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 2 Aug 2011 03:50:04 +0200 Subject: implementing new request wireframes: new page to select authority to write to --- app/controllers/request_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index f36fae463..d39b78f36 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -22,6 +22,10 @@ class RequestController < ApplicationController rescue MissingSourceFile, NameError end + def select_authority + medium_cache + end + def show medium_cache @locale = self.locale_from_params() @@ -66,7 +70,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 -- cgit v1.2.3 From a63e598b9e0ddfa7ac695b1be41aaace6c0eb628 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Thu, 11 Aug 2011 03:50:10 +0200 Subject: Move log-in point to before Preview and fix modal sign-in and sign-up redirects --- app/controllers/request_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index d39b78f36..88fb9be6c 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -276,6 +276,15 @@ class RequestController < ApplicationController return end + if !authenticated?( + :web => _("To send your FOI request"), + :email => _("Then your FOI request to {{public_body_name}} will be sent.",:public_body_name=>@info_request.public_body.name), + :email_subject => _("Confirm your FOI request to ") + @info_request.public_body.name + ) + # do nothing - as "authenticated?" has done the redirect to signin page for us + return + end + # Show preview page, if it is a preview if params[:preview].to_i == 1 message = "" @@ -298,15 +307,6 @@ class RequestController < ApplicationController return end - if !authenticated?( - :web => _("To send your FOI request"), - :email => _("Then your FOI request to {{public_body_name}} will be sent.",:public_body_name=>@info_request.public_body.name), - :email_subject => _("Confirm your FOI request to ") + @info_request.public_body.name - ) - # do nothing - as "authenticated?" has done the redirect to signin page for us - return - end - @info_request.user = authenticated_user # This automatically saves dependent objects, such as @outgoing_message, in the same transaction @info_request.save! -- cgit v1.2.3 From 7c7d7187b682f926e39231bcc748b0694d594445 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 17 Aug 2011 10:52:15 +0100 Subject: Add test for generation of HTML versions of attachments. As a side-effect, make some of the HTML more valid. Prerequisite for addressing issue #108. --- app/controllers/request_controller.rb | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 42d54a403..466c6d6ce 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -604,23 +604,29 @@ class RequestController < ApplicationController # special caching code so mime types are handled right around_filter :cache_attachments, :only => [ :get_attachment, :get_attachment_as_html ] def cache_attachments - key = params.merge(:only_path => true) - key_path = foi_fragment_cache_path(key) + if !params[:skip_cache].nil? + yield + else + key = params.merge(:only_path => true) + key_path = foi_fragment_cache_path(key) - if foi_fragment_cache_exists?(key_path) - cached = foi_fragment_cache_read(key_path) - response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream' - render_for_text(cached) - return - end + if foi_fragment_cache_exists?(key_path) + cached = foi_fragment_cache_read(key_path) + response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream' + render_for_text(cached) + return + end - yield + yield - # write it to the fileystem ourselves, so is just a plain file. (The - # various fragment cache functions using Ruby Marshall to write the file - # which adds a header, so isnt compatible with images that have been - # extracted elsewhere from PDFs) - foi_fragment_cache_write(key_path, response.body) + if params[:skip_cache].nil? + # write it to the fileystem ourselves, so is just a plain file. (The + # various fragment cache functions using Ruby Marshall to write the file + # which adds a header, so isnt compatible with images that have been + # extracted elsewhere from PDFs) + foi_fragment_cache_write(key_path, response.body) + end + end end def get_attachment @@ -649,7 +655,7 @@ class RequestController < ApplicationController view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet" html.sub!(//i, "" + view_html_stylesheet) - html.sub!(/]*>/i, '
') + html.sub!(/]*>/i, '
') html.sub!(/<\/body[^>]*>/i, '
') view_html_prefix = render_to_string :partial => "request/view_html_prefix" @@ -657,7 +663,6 @@ class RequestController < ApplicationController html.sub!("", CGI.escape(@attachment_url)) @incoming_message.html_mask_stuff!(html) - response.content_type = 'text/html' render :text => html end -- cgit v1.2.3 From c154b6a4ff5ab7b5a7d667e68b3b426875676853 Mon Sep 17 00:00:00 2001 From: Faton Selishta Date: Mon, 22 Aug 2011 10:33:17 +0200 Subject: changed hard coded information about how overdue --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 466c6d6ce..426996f2e 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -425,7 +425,7 @@ class RequestController < ApplicationController elsif @info_request.calculate_status == 'gone_postal' redirect_to respond_to_last_url(@info_request) + "?gone_postal=1" elsif @info_request.calculate_status == 'internal_review' - flash[:notice] = _("

Thank you! Hopefully your wait isn't too long.

You should get a response within 20 days, or be told if it will take longer (details).

", :review_url => unhappy_url(@info_request) + "#internal_review") + flash[:notice] = _("

Thank you! Hopefully your wait isn't too long.

You should get a response within {{late_number_of_days}} days, or be told if it will take longer (details).

",:late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20)), :review_url => unhappy_url(@info_request) + "#internal_review") redirect_to request_url(@info_request) elsif @info_request.calculate_status == 'error_message' flash[:notice] = _("

Thank you! We'll look into what happened and try and fix it up.

If the error was a delivery failure, and you can find an up to date FOI email address for the authority, please tell us using the form below.

") -- cgit v1.2.3 From c2aa5f55f14528c4e8fca0aff887d43d9e098a40 Mon Sep 17 00:00:00 2001 From: Faton Selishta Date: Mon, 22 Aug 2011 11:02:44 +0200 Subject: Rebuild .pot file after I18n changes and fix syntax at request_controller --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 426996f2e..c1a13273a 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -425,7 +425,7 @@ class RequestController < ApplicationController elsif @info_request.calculate_status == 'gone_postal' redirect_to respond_to_last_url(@info_request) + "?gone_postal=1" elsif @info_request.calculate_status == 'internal_review' - flash[:notice] = _("

Thank you! Hopefully your wait isn't too long.

You should get a response within {{late_number_of_days}} days, or be told if it will take longer (details).

",:late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20)), :review_url => unhappy_url(@info_request) + "#internal_review") + flash[:notice] = _("

Thank you! Hopefully your wait isn't too long.

You should get a response within {{late_number_of_days}} days, or be told if it will take longer (details).

",:late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20), :review_url => unhappy_url(@info_request) + "#internal_review") redirect_to request_url(@info_request) elsif @info_request.calculate_status == 'error_message' flash[:notice] = _("

Thank you! We'll look into what happened and try and fix it up.

If the error was a delivery failure, and you can find an up to date FOI email address for the authority, please tell us using the form below.

") -- cgit v1.2.3 From d9948091967123ca7e9d986d6ebaf4b6226b27f3 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 23 Aug 2011 02:28:03 +0200 Subject: Add sign-in at beginning of New Request process (configurable) --- app/controllers/request_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index dadbb0cbd..ffdcbe62c 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -23,6 +23,17 @@ class RequestController < ApplicationController end def select_authority + # Check whether we force the user to sign in right at the start, or we allow her + # to start filling the request anonymously + if force_registration_on_new_request && !authenticated?( + :web => _("To send your FOI request"), + :email => _("Then you'll be allowed to send FOI requests."), + :email_subject => _("Confirm your email address") + ) + # do nothing - as "authenticated?" has done the redirect to signin page for us + return + end + medium_cache end -- cgit v1.2.3 From 6f46c15f6290e286ffa7b12ace40e4983c6641a3 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 23 Aug 2011 02:32:40 +0200 Subject: Move compulsory sign-in step after Preview page, where it was originally --- app/controllers/request_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index ffdcbe62c..6e562d97d 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -287,15 +287,6 @@ class RequestController < ApplicationController return end - if !authenticated?( - :web => _("To send your FOI request"), - :email => _("Then your FOI request to {{public_body_name}} will be sent.",:public_body_name=>@info_request.public_body.name), - :email_subject => _("Confirm your FOI request to ") + @info_request.public_body.name - ) - # do nothing - as "authenticated?" has done the redirect to signin page for us - return - end - # Show preview page, if it is a preview if params[:preview].to_i == 1 message = "" @@ -318,6 +309,15 @@ class RequestController < ApplicationController return end + if !authenticated?( + :web => _("To send your FOI request"), + :email => _("Then your FOI request to {{public_body_name}} will be sent.",:public_body_name=>@info_request.public_body.name), + :email_subject => _("Confirm your FOI request to ") + @info_request.public_body.name + ) + # do nothing - as "authenticated?" has done the redirect to signin page for us + return + end + @info_request.user = authenticated_user # This automatically saves dependent objects, such as @outgoing_message, in the same transaction @info_request.save! -- cgit v1.2.3 From 284808d259b3ba8ba1e6c106d949fffeb110a5a7 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 24 Aug 2011 11:50:10 +0100 Subject: First stab at filtering on the "View requests" page --- app/controllers/request_controller.rb | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index c1a13273a..731348fbf 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -129,25 +129,12 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - - if @view.nil? - redirect_to request_list_url(:view => 'successful') - return - end - - if @view == 'recent' - @title = _("Recently sent Freedom of Information requests") - query = "variety:sent"; - sortby = "newest" - @track_thing = TrackThing.create_track_for_all_new_requests - elsif @view == 'successful' - @title = _("Recently successful responses") - query = 'variety:response (status:successful OR status:partially_successful)' - sortby = "described" - @track_thing = TrackThing.create_track_for_all_successful_requests - else - raise "unknown request list view " + @view.to_s + if !@view.nil? + params[:request_status] = @view end + params[:request_status] = "recent" if params[:query].nil? && params[:request_status].nil? + query, sortby = alter_query_from_params(params[:query]) + @title = "Some title" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect behavior_cache :tag => [@view, @page] do @@ -158,7 +145,8 @@ class RequestController < ApplicationController @title = @title + " (page " + @page.to_s + ")" if (@page > 1) - @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] + # XXX need to reinstate the following; @track_thing had previously been set to "TrackThing.create_track_for_all_new_requests" and "TrackThing.create_track_for_all_successful_requests" + # @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] # Don't let robots go more than 20 pages in if @page > 20 -- cgit v1.2.3 From 45fc8c3e18dc5e43e98fc1fae5b519f1440086ea Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 24 Aug 2011 16:48:55 +0100 Subject: more work in progress on search forms --- app/controllers/request_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 731348fbf..bb91cc854 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -129,12 +129,9 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - if !@view.nil? - params[:request_status] = @view - end params[:request_status] = "recent" if params[:query].nil? && params[:request_status].nil? - query, sortby = alter_query_from_params(params[:query]) - @title = "Some title" + query, sortby = alter_query_from_params + @title = "View and search requests" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect behavior_cache :tag => [@view, @page] do -- cgit v1.2.3 From 5f0c0d59ded4301efa085c4103b84a42a9fa61f6 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 26 Aug 2011 09:48:01 +0100 Subject: Further work in progress on better search functionality --- app/controllers/request_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index bb91cc854..3c283baae 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -129,10 +129,10 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - params[:request_status] = "recent" if params[:query].nil? && params[:request_status].nil? - query, sortby = alter_query_from_params + params[:latest_status] = @view + query = make_query_from_params @title = "View and search requests" - + sortby = "newest" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect behavior_cache :tag => [@view, @page] do xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') -- cgit v1.2.3 From b41edc7ae069e6071f7ff7223c1e60cca5e75e8c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 29 Aug 2011 13:13:59 +0100 Subject: Add tests & fixes for new search/filtering functionality --- app/controllers/request_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 3c283baae..79b8e4816 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -134,6 +134,7 @@ class RequestController < ApplicationController @title = "View and search requests" sortby = "newest" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect + behavior_cache :tag => [@view, @page] do xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') @list_results = xapian_object.results.map { |r| r[:model] } -- cgit v1.2.3 From a26fbf9b9653114869f0929103f94ceb1c405232 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 29 Aug 2011 15:37:48 +0100 Subject: re-enable tracking on "view requests" page (and make note that we now need to make the descriptions we present users more friendly) --- app/controllers/request_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 79b8e4816..1db038c92 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -134,7 +134,6 @@ class RequestController < ApplicationController @title = "View and search requests" sortby = "newest" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect - behavior_cache :tag => [@view, @page] do xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') @list_results = xapian_object.results.map { |r| r[:model] } @@ -142,9 +141,8 @@ class RequestController < ApplicationController end @title = @title + " (page " + @page.to_s + ")" if (@page > 1) - - # XXX need to reinstate the following; @track_thing had previously been set to "TrackThing.create_track_for_all_new_requests" and "TrackThing.create_track_for_all_successful_requests" - # @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] + @track_thing = TrackThing.create_track_for_search_query(query) + @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] # Don't let robots go more than 20 pages in if @page > 20 -- cgit v1.2.3 From 0420098e50996a033552335e94e35ade781357af Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 13:32:13 +0100 Subject: Additional changes omitted from commit 9d8388c03d0faeaca29d233a340c58bd65f28a97 (distinguish 404s and 500s), fixes #161. --- app/controllers/request_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 79b8e4816..a76418e4e 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -37,7 +37,7 @@ class RequestController < ApplicationController # 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" + raise ActiveRecord::RecordNotFound.new("Request not found") end set_last_request(@info_request) @@ -189,7 +189,7 @@ class RequestController < ApplicationController params[:info_request][:public_body_id] = params[:url_name] else public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) - raise "None found" if public_body.nil? # XXX proper 404 + raise ActiveRecord::RecordNotFound.new("None found") if public_body.nil? # XXX proper 404 params[:info_request][:public_body_id] = public_body.id end elsif params[:public_body_id] @@ -672,10 +672,10 @@ class RequestController < ApplicationController raise "internal error, pre-auth filter should have caught this" if !@info_request.user_can_view?(authenticated_user) @attachment = IncomingMessage.get_attachment_by_url_part_number(@incoming_message.get_attachments_for_display, @part_number) - raise "attachment not found part number " + @part_number.to_s + " incoming_message " + @incoming_message.id.to_s if @attachment.nil? + raise ActiveRecord::RecordNotFound.new("attachment not found part number " + @part_number.to_s + " incoming_message " + @incoming_message.id.to_s) if @attachment.nil? # check filename in URL matches that in database (use a censor rule if you want to change a filename) - raise "please use same filename as original file has, display: '" + @attachment.display_filename + "' old_display: '" + @attachment.old_display_filename + "' original: '" + @original_filename + "'" if @attachment.display_filename != @original_filename && @attachment.old_display_filename != @original_filename + raise ActiveRecord::RecordNotFound.new("please use same filename as original file has, display: '" + @attachment.display_filename + "' old_display: '" + @attachment.old_display_filename + "' original: '" + @original_filename + "'") if @attachment.display_filename != @original_filename && @attachment.old_display_filename != @original_filename @attachment_url = get_attachment_url(:id => @incoming_message.info_request_id, :incoming_message_id => @incoming_message.id, :part => @part_number, -- cgit v1.2.3 From f443b36ed4819bbc6766e7089d035f5d071fe2a1 Mon Sep 17 00:00:00 2001 From: Faton Selishta Date: Mon, 5 Sep 2011 10:56:36 +0200 Subject: I18n'ize some strings --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index e3f431cc7..12b5247b5 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -146,7 +146,7 @@ class RequestController < ApplicationController @view = params[:view] params[:latest_status] = @view query = make_query_from_params - @title = "View and search requests" + @title = _("View and search requests") sortby = "newest" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect behavior_cache :tag => [@view, @page] do -- cgit v1.2.3 From 50a1f019535f61f7ed7e09931d0d114e5e4fd538 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 13 Sep 2011 11:45:45 +0100 Subject: Provide ability to download zip file containing complete request. Closes #11 --- app/controllers/request_controller.rb | 67 +++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 12b5247b5..b615cc834 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -7,6 +7,8 @@ # $Id: request_controller.rb,v 1.192 2009-10-19 19:26:40 francis Exp $ require 'alaveteli_file_types' +require 'zip/zip' +require 'open-uri' class RequestController < ApplicationController before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ] @@ -67,7 +69,6 @@ class RequestController < ApplicationController @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 @@ -101,7 +102,7 @@ class RequestController < ApplicationController # For send followup link at bottom @last_response = @info_request.get_last_response - + @is_owning_user = @info_request.is_owning_user?(authenticated_user) respond_to do |format| format.html { @has_json = true; render :template => 'request/show'} format.json { render :json => @info_request.json_for_api(true) } @@ -754,5 +755,67 @@ class RequestController < ApplicationController render :partial => "request/search_ahead.rhtml" end + + def download_entire_request + @locale = self.locale_from_params() + PublicBody.with_locale(@locale) do + info_request = InfoRequest.find_by_url_title(params[:url_title]) + if info_request.nil? + raise ActiveRecord::RecordNotFound.new("Request not found") + end + if authenticated?( + :web => _("To download the zip file"), + :email => _("Then you can download a zip file of {{info_request_title}}.",:info_request_title=>info_request.title), + :email_subject => _("Log in to download a zip file of {{info_request_title}}",:info_request_title=>info_request.title) + ) + updated = Digest::SHA1.hexdigest(info_request.get_last_event.created_at.to_s + info_request.updated_at.to_s) + @url_path = "/download/#{updated[0..1]}/#{updated}/#{params[:url_title]}.zip" + file_path = File.join(File.dirname(__FILE__), '../../cache/zips', @url_path) + if !File.exists?(file_path) + FileUtils.mkdir_p(File.dirname(file_path)) + Zip::ZipFile.open(file_path, Zip::ZipFile::CREATE) { |zipfile| + convert_command = MySociety::Config.get("HTML_TO_PDF_COMMAND") + done = false + if File.exists?(convert_command) + domain = MySociety::Config.get("DOMAIN") + url = "http://#{domain}#{request_url(info_request)}?print_stylesheet=1" + tempfile = Tempfile.new('foihtml2pdf') + output = AlaveteliExternalCommand.run(convert_command, url, tempfile.path) + if !output.nil? + zipfile.get_output_stream("correspondence.pdf") { |f| + f.puts(File.open(tempfile.path).read) + } + done = true + else + logger.error("Could not convert info request #{info_request.id} to PDF") + end + tempfile.close + else + logger.warn("No HTML -> PDF converter found at #{convert_command}") + end + if !done + @info_request = info_request + @info_request_events = info_request.info_request_events + template = File.read(File.join(File.dirname(__FILE__), "..", "views", "request", "simple_correspondence.rhtml")) + output = ERB.new(template).result(binding) + zipfile.get_output_stream("correspondence.txt") { |f| + f.puts(output) + } + end + for message in info_request.incoming_messages + attachments = message.get_attachments_for_display + for attachment in attachments + zipfile.get_output_stream(attachment.display_filename) { |f| + f.puts(attachment.body) + } + end + end + } + File.chmod(0644, file_path) + end + redirect_to @url_path + end + end + end end -- cgit v1.2.3 From a5f9e3d8d91ccded80af07f6336bca44b1c9a171 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 16 Sep 2011 10:59:03 +0100 Subject: Make the result of a form submit on the first step of "make new request" behave the same as the find-as-you-type implementation. Fixes #181. --- app/controllers/request_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index b615cc834..a9394fe39 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -35,7 +35,12 @@ class RequestController < ApplicationController # do nothing - as "authenticated?" has done the redirect to signin page for us return end - + + if !params[:query].nil? + query = params[:query] + '*' + query = query.split(' ').join(' OR ') # XXX: HACK for OR instead of default AND! + @xapian_requests = perform_search([PublicBody], query, 'relevant', 'request_collapse', 5) + end medium_cache end -- cgit v1.2.3 From bccd673534c8162f7b61e66491cafd62fc915019 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 16 Sep 2011 12:34:12 +0100 Subject: Improved error logging when zipfile PDF creation fails --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index a9394fe39..06d8f15f4 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -792,7 +792,7 @@ class RequestController < ApplicationController } done = true else - logger.error("Could not convert info request #{info_request.id} to PDF") + logger.error("Could not convert info request #{info_request.id} to PDF with command '#{convert_command} #{url} #{tempfile.path}'") end tempfile.close else -- cgit v1.2.3 From b48df57d9243336d4b96e29c5587137eff3a3c67 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Fri, 23 Sep 2011 02:50:41 +0200 Subject: Remove invalid collate argument for public body searches The existing bug wasn't catched by the tests, because it only fails when running in dev: otherwise all the classes are loaded before the search is done, and acts_as_xapian can find the provided 'request_collapse' argument, even if the PublicBody class doesn't define it, since all the init options end up together in acts_as_xapian. --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 06d8f15f4..e719a8898 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -39,7 +39,7 @@ class RequestController < ApplicationController if !params[:query].nil? query = params[:query] + '*' query = query.split(' ').join(' OR ') # XXX: HACK for OR instead of default AND! - @xapian_requests = perform_search([PublicBody], query, 'relevant', 'request_collapse', 5) + @xapian_requests = perform_search([PublicBody], query, 'relevant', nil, 5) end medium_cache end -- cgit v1.2.3 From c71551992bf3bf6204f298777bc04cc355ef4613 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Mon, 26 Sep 2011 21:36:11 +0200 Subject: Removed hardcoded number of days. Fixes #199 --- app/controllers/request_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index e719a8898..4b7884065 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -314,10 +314,11 @@ class RequestController < ApplicationController # XXX send_message needs the database id, so we send after saving, which isn't ideal if the request broke here. @outgoing_message.send_message flash[:notice] = _("

Your {{law_used_full}} request has been sent on its way!

-

We will email you when there is a response, or after 20 working days if the authority still hasn't +

We will email you when there is a response, or after {{late_number_of_days}} working days if the authority still hasn't replied by then.

If you write about this request (for example in a forum or a blog) please link to this page, and add an - annotation below telling people about your writing.

",:law_used_full=>@info_request.law_used_full) + annotation below telling people about your writing.

",:law_used_full=>@info_request.law_used_full, + :late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20)) redirect_to show_new_request_path(:url_title => @info_request.url_title) end -- cgit v1.2.3 From 8ed974e499c842a8e46d15fd5e492828550b0423 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 21 Nov 2011 12:13:18 +0000 Subject: Fix occasional test failures due to two events happening in the same second being treated as one for the purposes of caching. Fixes #290. --- app/controllers/request_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 4b7884065..1801648ca 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -774,7 +774,7 @@ class RequestController < ApplicationController :email => _("Then you can download a zip file of {{info_request_title}}.",:info_request_title=>info_request.title), :email_subject => _("Log in to download a zip file of {{info_request_title}}",:info_request_title=>info_request.title) ) - updated = Digest::SHA1.hexdigest(info_request.get_last_event.created_at.to_s + info_request.updated_at.to_s) + updated = Digest::SHA1.hexdigest(info_request.get_last_event.created_at.to_i.to_s + info_request.updated_at.to_i.to_s) @url_path = "/download/#{updated[0..1]}/#{updated}/#{params[:url_title]}.zip" file_path = File.join(File.dirname(__FILE__), '../../cache/zips', @url_path) if !File.exists?(file_path) -- cgit v1.2.3