aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb21
-rw-r--r--app/controllers/public_body_controller.rb8
-rw-r--r--app/controllers/request_controller.rb8
-rw-r--r--app/controllers/user_controller.rb6
-rwxr-xr-xapp/helpers/link_to_helper.rb12
-rw-r--r--app/models/foi_attachment.rb1
-rw-r--r--app/views/admin_public_body/_form.rhtml7
-rw-r--r--app/views/admin_public_body/edit.rhtml6
-rw-r--r--app/views/general/exception_caught.rhtml4
9 files changed, 45 insertions, 28 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b0351f7d1..8fd2da54a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -361,6 +361,27 @@ class ApplicationController < ActionController::Base
def get_search_page_from_params
return (params[:page] || "1").to_i
end
+ def perform_search_typeahead(query, model)
+ # strip out unintended search operators - see
+ # https://github.com/sebbacon/alaveteli/issues/328
+ # 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.gsub(/(\s-\s|&)/, "")
+ query = query.split(/ +(?!-)/)
+ if query.last.nil? || query.last.strip.length < 3
+ xapian_requests = nil
+ else
+ query = query.join(' OR ') # XXX: HACK for OR instead of default AND!
+ if model == PublicBody
+ collapse = nil
+ elsif model == InfoRequestEvent
+ collapse = 'request_collapse'
+ end
+ xapian_requests = perform_search([model], query, 'relevant', collapse, 5)
+ end
+ return xapian_requests
+ end
# Store last visited pages, for contact form; but only for logged in users, as otherwise this breaks caching
def set_last_request(info_request)
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 94d1351db..659433c9e 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -186,13 +186,7 @@ class PublicBodyController < ApplicationController
# 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[:query]
- query = query.split(' ')
- if query.last.nil? || query.last.strip.length < 3
- @xapian_requests = nil
- else
- query = query.join(' OR ') # XXX: HACK for OR instead of default AND!
- @xapian_requests = perform_search([PublicBody], query, 'relevant', nil, 5)
- end
+ @xapian_requests = perform_search_typeahead(query, PublicBody)
render :partial => "public_body/search_ahead"
end
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index f3bbd6708..6e33fe043 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -755,13 +755,7 @@ class RequestController < ApplicationController
# 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(' ')
- if query.last.nil? || query.last.strip.length < 3
- @xapian_requests = nil
- else
- query = query.join(' OR ') # XXX: HACK for OR instead of default AND!
- @xapian_requests = perform_search([InfoRequestEvent], query, 'relevant', 'request_collapse', 5)
- end
+ @xapian_requests = perform_search_typeahead(query, InfoRequestEvent)
render :partial => "request/search_ahead.rhtml"
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index fc29a847c..45b71a3a9 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -116,8 +116,10 @@ class UserController < ApplicationController
render :action => 'sign'
return
else
- @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false)
- if @user_signin.errors.size > 0
+ if !@post_redirect.nil?
+ @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false)
+ end
+ if @post_redirect.nil? || @user_signin.errors.size > 0
# Failed to authenticate
render :action => 'sign'
return
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 5866c31f0..7903dee2a 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -189,10 +189,14 @@ module LinkToHelper
url_prefix = "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000')
url = url_prefix + relative_path
if !append.nil?
- env = Rack::MockRequest.env_for(url)
- req = Rack::Request.new(env)
- req.path_info += append
- url = req.url
+ begin
+ env = Rack::MockRequest.env_for(url)
+ req = Rack::Request.new(env)
+ req.path_info += append
+ url = req.url
+ rescue URI::InvalidURIError
+ # don't append to it
+ end
end
return url
end
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index a14e0b553..dc55ff5f6 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -59,6 +59,7 @@ class FoiAttachment < ActiveRecord::Base
file.write d
}
update_display_size!
+ @cached_body = d
end
def body
diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml
index 1cdc9b3fe..d854b53f5 100644
--- a/app/views/admin_public_body/_form.rhtml
+++ b/app/views/admin_public_body/_form.rhtml
@@ -50,12 +50,13 @@
<h3>Common Fields</h3>
<p><label for="public_body_tag_string">Tags <small>(space separated; see list of tags on the right; also <strong>not_apply</strong> if FOI and EIR no longer apply to authority, <strong>eir_only</strong> if EIR but not FOI applies to authority, <strong>defunct</strong> if the authority no longer exists; charity:NUMBER if a registered charity)</small></label><br/>
-<%= f.text_field :tag_string, :size => 60 %></p>
+
+<%= text_field :public_body, :tag_string, :size => 60, :id => 'public_body_tag_string' %></p>
<p><label for="public_body_home_page">Home page <small>(of whole authority, not just their FOI page; set to <strong>blank</strong> (empty string) to guess it from the email)</small></label><br/>
-<%= f.text_field :home_page, :size => 60 %></p>
+<%= text_field :public_body, :home_page, :size => 60, :id => 'public_body_home_page' %></p>
<p><label for="public_body_last_edit_comment"><strong>Comment</strong> for this edit</label> <small>(put URL or other source of new info)</small><br/>
-<%= f.text_area :last_edit_comment, :rows => 3, :cols => 60 %></p>
+<%= text_area :public_body, :last_edit_comment, :rows => 3, :cols => 60, :id => 'public_body_last_edit_comment' %></p>
<!--[eoform:public_body]-->
diff --git a/app/views/admin_public_body/edit.rhtml b/app/views/admin_public_body/edit.rhtml
index b91f15a2e..b19477a6b 100644
--- a/app/views/admin_public_body/edit.rhtml
+++ b/app/views/admin_public_body/edit.rhtml
@@ -9,9 +9,9 @@
<%= render :partial => 'tag_help' %>
<div id="public_body_form">
- <% form_for @public_body, :url => {:action => 'update'} do |f| %>
- <%= render :partial => 'form', :locals => {:f => f} %>
- <p><%= f.submit 'Save', :accesskey => 's' %></p>
+ <% form_tag '../update/' + @public_body.id.to_s do %>
+ <%= render :partial => 'form' %>
+ <p><%= submit_tag 'Save', :accesskey => 's' %></p>
<% end %>
<p>
diff --git a/app/views/general/exception_caught.rhtml b/app/views/general/exception_caught.rhtml
index b266b53a1..5f0dfe13d 100644
--- a/app/views/general/exception_caught.rhtml
+++ b/app/views/general/exception_caught.rhtml
@@ -19,6 +19,6 @@
<% end %>
<h2><%= _('Technical details') %></h2>
- <p><strong><%=@exception_class ? @exception_class : _("Unknown")%></strong></p>
- <p><strong><%=@exception_message %></strong></p>
+ <p><strong><%= h(@exception_class ? @exception_class : _("Unknown")) %></strong></p>
+ <p><strong><%= h(@exception_message) %></strong></p>
</div>