aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--app/controllers/general_controller.rb2
-rw-r--r--app/controllers/request_controller.rb9
-rw-r--r--app/models/foi_attachment.rb16
-rw-r--r--app/models/info_request_event.rb22
-rw-r--r--app/views/admin_public_body/new.rhtml6
-rw-r--r--app/views/request/_request_listing_via_event.rhtml2
-rw-r--r--app/views/user/show.rhtml2
8 files changed, 48 insertions, 17 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7aa522389..2633aca4d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -371,7 +371,7 @@ class ApplicationController < ActionController::Base
# XXX this is a result of the OR hack below -- should fix by
# allowing a parameter to perform_search to control the
# default operator!
- query = query.strip.gsub(/(\s-\s|&)/, "")
+ query = query.strip.gsub(/(\s-\s|&|\(|\))/, "")
query = query.split(/ +(?![-+]+)/)
if query.last.nil? || query.last.strip.length < 3
xapian_requests = nil
@@ -435,7 +435,7 @@ class ApplicationController < ActionController::Base
params[:latest_status] = [params[:latest_status]]
end
if params[:latest_status].include?("recent") || params[:latest_status].include?("all")
- query += " variety:sent"
+ query += " (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)"
end
if params[:latest_status].include? "successful"
statuses << ['latest_status:successful', 'latest_status:partially_successful']
@@ -444,7 +444,7 @@ class ApplicationController < ActionController::Base
statuses << ['latest_status:rejected', 'latest_status:not_held']
end
if params[:latest_status].include? "awaiting"
- statuses << ['latest_status:waiting_response', 'latest_status:waiting_clarification', 'waiting_classification:true']
+ statuses << ['latest_status:waiting_response', 'latest_status:waiting_clarification', 'waiting_classification:true', 'latest_status:internal_review','latest_status:gone_postal', 'latest_status:error_message', 'latest_status:requires_admin']
end
if params[:latest_status].include? "internal_review"
statuses << ['status:internal_review']
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 194a1cec0..6cdfb9d5f 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -99,7 +99,7 @@ class GeneralController < ApplicationController
@variety_postfix = path.pop
end
@variety_postfix = "bodies" if @variety_postfix.nil? && !params[:bodies].nil?
- @variety_postfix = "requests" if @variety_postfix.nil?
+ @variety_postfix = "all" if @variety_postfix.nil?
if @variety_postfix != "users"
@common_query = get_tags_from_params
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index fbf862af3..8714f03cf 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -151,11 +151,14 @@ class RequestController < ApplicationController
def list
medium_cache
@view = params[:view]
+ @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect
+ if @view == "recent"
+ return redirect_to request_list_all_path(:action => "list", :view => "all", :page => @page), :status => :moved_permanently
+ end
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')
@list_results = xapian_object.results.map { |r| r[:model] }
@@ -601,10 +604,10 @@ class RequestController < ApplicationController
before_filter :authenticate_attachment, :only => [ :get_attachment, :get_attachment_as_html ]
def authenticate_attachment
- # Test for hidden
- if request.path =~ /\/$/
+ if request.path =~ /\/$/ || !(params[:part] =~ /^\d+$/)
raise PermissionDenied.new("Directory listing not allowed")
else
+ # Test for hidden
incoming_message = IncomingMessage.find(params[:incoming_message_id])
if !incoming_message.info_request.user_can_view?(authenticated_user)
@info_request = incoming_message.info_request # used by view
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index d12df688a..20c40abea 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -34,6 +34,9 @@ class FoiAttachment < ActiveRecord::Base
before_validation :ensure_filename!, :only => [:filename]
before_destroy :delete_cached_file!
+ BODY_MAX_TRIES = 3
+ BODY_MAX_DELAY = 5
+
def directory
base_dir = File.join(File.dirname(__FILE__), "../../cache", "attachments_#{ENV['RAILS_ENV']}")
return File.join(base_dir, self.hexdigest[0..2])
@@ -45,6 +48,7 @@ class FoiAttachment < ActiveRecord::Base
def delete_cached_file!
begin
+ @cached_body = nil
File.delete(self.filepath)
rescue
end
@@ -57,7 +61,6 @@ class FoiAttachment < ActiveRecord::Base
end
File.open(self.filepath, "wb") { |file|
file.write d
- file.fsync
}
update_display_size!
@cached_body = d
@@ -65,12 +68,23 @@ class FoiAttachment < ActiveRecord::Base
def body
if @cached_body.nil?
+ tries = 0
+ delay = 1
begin
@cached_body = File.open(self.filepath, "rb" ).read
rescue Errno::ENOENT
# we've lost our cached attachments for some reason. Reparse them.
+ if tries > BODY_MAX_TRIES
+ raise
+ else
+ sleep delay
+ end
+ tries += 1
+ delay *= 2
+ delay = BODY_MAX_DELAY if delay > BODY_MAX_DELAY
force = true
self.incoming_message.parse_raw_email!(force)
+ retry
end
end
return @cached_body
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 8b7b9ebe4..e99a0ae2f 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -109,7 +109,7 @@ class InfoRequestEvent < ActiveRecord::Base
[ :tags, 'U', "tag" ]
],
:if => :indexed_by_search?,
- :eager_load => [ :incoming_message, :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ]
+ :eager_load => [ :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ]
def requested_by
self.info_request.user.url_name
@@ -176,7 +176,21 @@ class InfoRequestEvent < ActiveRecord::Base
# format it here as no datetime support in Xapian's value ranges
return self.created_at.strftime("%Y%m%d%H%M%S")
end
- # clipped = true - means return shorter text. It is used for snippets for
+
+ def incoming_message_selective_columns(fields)
+ message = IncomingMessage.find(:all,
+ :select => fields + ", incoming_messages.info_request_id",
+ :joins => "INNER JOIN info_request_events ON incoming_messages.id = incoming_message_id ",
+ :conditions => "info_request_events.id = #{self.id}"
+ )
+ message = message[0]
+ if !message.nil?
+ message.info_request = InfoRequest.find(message.info_request_id)
+ end
+ return message
+ end
+
+ # clipped = true - means return shorter text. It is used for snippets fore
# performance reasons. Xapian will take the full text.
def search_text_main(clipped = false)
text = ''
@@ -186,7 +200,7 @@ class InfoRequestEvent < ActiveRecord::Base
text = text + self.outgoing_message.get_text_for_indexing + "\n\n"
elsif self.event_type == 'response'
if clipped
- text = text + self.incoming_message.get_text_for_indexing_clipped + "\n\n"
+ text = text + self.incoming_message_selective_columns("cached_attachment_text_clipped").cached_attachment_text_clipped + "\n\n"
else
text = text + self.incoming_message.get_text_for_indexing_full + "\n\n"
end
@@ -296,7 +310,7 @@ class InfoRequestEvent < ActiveRecord::Base
end
- def is_incoming_message?() not self.incoming_message.nil? end
+ def is_incoming_message?() not self.incoming_message_selective_columns("incoming_messages.id").nil? end
def is_outgoing_message?() not self.outgoing_message.nil? end
def is_comment?() not self.comment.nil? end
diff --git a/app/views/admin_public_body/new.rhtml b/app/views/admin_public_body/new.rhtml
index b859fdf6a..047d5a5bb 100644
--- a/app/views/admin_public_body/new.rhtml
+++ b/app/views/admin_public_body/new.rhtml
@@ -11,9 +11,9 @@
<%= render :partial => 'tag_help' %>
<div id="public_body_form">
- <% form_for :public_body, @public_body, :url => {:action => "create"} do |f| %>
- <%= render :partial => 'form', :locals => {:f => f} %>
- <p><%= f.submit "Create" %></p>
+ <% form_tag './create/' + @public_body.id.to_s do %>
+ <%= render :partial => 'form' %>
+ <p><%= submit_tag "Create" %></p>
<% end %>
<p>
diff --git a/app/views/request/_request_listing_via_event.rhtml b/app/views/request/_request_listing_via_event.rhtml
index e247163a3..7a211ed88 100644
--- a/app/views/request/_request_listing_via_event.rhtml
+++ b/app/views/request/_request_listing_via_event.rhtml
@@ -6,7 +6,7 @@ end %>
<div class="request_left">
<span class="head">
<% if event.is_incoming_message? %>
- <%= link_to highlight_words(info_request.title, @highlight_words), incoming_message_url(event.incoming_message) %>
+ <%= link_to highlight_words(info_request.title, @highlight_words), incoming_message_url(event.incoming_message_selective_columns("incoming_messages.id")) %>
<% elsif event.is_outgoing_message? and event.event_type == 'followup_sent' %>
<%= link_to highlight_words(info_request.title, @highlight_words), outgoing_message_url(event.outgoing_message) %>
<% elsif event.is_comment? %>
diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml
index 2d2394f5c..4fa29f00d 100644
--- a/app/views/user/show.rhtml
+++ b/app/views/user/show.rhtml
@@ -147,7 +147,7 @@
<% end %>
<% else %>
<h2 class="foi_results" id="foi_requests">
- <%= @is_you ? n_('Your %d Freedom of Information request', 'Your %d Freedom of Information requests', @xapian_requests.results.size) % @xapian_requests.results.size : n_('This person\'s %d Freedom of Information request', 'This person\'s %d Freedom of Information requests', @xapian_requests.matches_estimated.to_s) % @xapian_requests.matches_estimated %>
+ <%= @is_you ? n_('Your %d Freedom of Information request', 'Your %d Freedom of Information requests', @xapian_requests.matches_estimated.to_s) % @xapian_requests.matches_estimated.to_s : n_('This person\'s %d Freedom of Information request', 'This person\'s %d Freedom of Information requests', @xapian_requests.matches_estimated.to_s) % @xapian_requests.matches_estimated %>
<!-- matches_estimated <%=@xapian_requests.matches_estimated%> -->
<%= @match_phrase %>
<%= @page_desc %>