diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/general_controller.rb | 36 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/services_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/user_controller.rb | 3 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 27 | ||||
-rw-r--r-- | app/models/raw_email.rb | 26 | ||||
-rw-r--r-- | app/views/general/search.rhtml | 10 | ||||
-rw-r--r-- | app/views/request/list.rhtml | 2 | ||||
-rw-r--r-- | app/views/user/show.rhtml | 82 |
9 files changed, 77 insertions, 129 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index c715b547d..8ac41b05a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -86,34 +86,19 @@ class GeneralController < ApplicationController # Just does a redirect from ?query= search to /query def search_redirect - if params[:advanced].nil? - @query, _ = make_query_from_params - else - @query, _ = params[:query] - end - @sortby = params[:sortby] - path = request.path.split("/") - if path.size > 0 && (['newest', 'described', 'relevant'].include?(path[-1])) - @sort_postfix = path.pop - end - if path.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(path[-1])) - @variety_postfix = path.pop - end - @variety_postfix = "bodies" if @variety_postfix.nil? && !params[:bodies].nil? - @variety_postfix = "all" if @variety_postfix.nil? - if @variety_postfix != "users" - @common_query = get_tags_from_params - end - [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| - session[x] = params[x] - end + @query = params.delete(:query) if @query.nil? || @query.empty? @query = nil @page = 1 @advanced = !params[:advanced].nil? render :action => "search" else - redirect_to search_url(@query, @variety_postfix, @sort_postfix, params[:advanced]) + query_parts = @query.split("/") + if !['bodies', 'requests', 'users', 'all'].include?(query_parts[-1]) + redirect_to search_url([@query, "all"], params) + else + redirect_to search_url(@query, params) + end end end @@ -121,13 +106,6 @@ class GeneralController < ApplicationController def search # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. - if !params[:commit].nil? - search_redirect - return - end - [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| - params[x] = session[x] if params[x].nil? - end combined = params[:combined] @sortby = nil @bodies = @requests = @users = true diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 11812b729..a70e8d16c 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -74,8 +74,9 @@ class RequestController < ApplicationController @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 + @update_status = params[:update_status] ? true : false @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil? + @is_owning_user = @info_request.is_owning_user?(authenticated_user) if @update_status return if !@is_owning_user && !authenticated_as_user?(@info_request.user, @@ -108,7 +109,6 @@ 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) } @@ -168,7 +168,8 @@ class RequestController < ApplicationController query = make_query_from_params @title = _("View and search requests") sortby = "newest" - behavior_cache :tag => [@query, @page, I18n.locale] do + @cache_tag = Digest::MD5.hexdigest(query + @page.to_s) + behavior_cache :tag => [@cache_tag] do xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') @list_results = xapian_object.results.map { |r| r[:model] } @matches_estimated = xapian_object.matches_estimated @@ -696,7 +697,8 @@ class RequestController < ApplicationController @incoming_message.parse_raw_email! @info_request = @incoming_message.info_request if @incoming_message.info_request_id != params[:id].to_i - raise ActiveRecord::RecordNotFound.new(sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, params[:id])) + message = "Incoming message %d does not belong to request %d" % [@incoming_message.info_request_id, params[:id]] + raise ActiveRecord::RecordNotFound.new(message) end @part_number = params[:part].to_i @filename = params[:file_name].join("/") diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 6fb20336e..225790d71 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -1,12 +1,4 @@ -# controllers/application.rb: -# Parent class of all controllers in FOI site. Filters added to this controller -# apply to all controllers in the application. Likewise, all the methods added -# will be available for all controllers. -# -# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: application.rb,v 1.59 2009-09-17 13:01:56 francis Exp $ +# controllers/services_controller.rb: require 'open-uri' diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 45b71a3a9..f49fc9165 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -489,7 +489,8 @@ class UserController < ApplicationController raise ActiveRecord::RecordNotFound.new("user not found, url_name=" + params[:url_name]) end if !@display_user.profile_photo - raise "user has no profile photo, url_name=" + params[:url_name] + raise ActiveRecord::RecordNotFound.new("user has no profile photo, url_name=" + params[:url_name]) + end response.content_type = "image/png" diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 7903dee2a..56c33e512 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -136,9 +136,19 @@ module LinkToHelper end # General pages. - def search_url(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) - query = query - ["", nil] if query.kind_of?(Array) - url = search_general_url(:combined => query) + def search_url(query, params = nil) + if query.kind_of?(Array) + query = query - ["", nil] + query = query.join("/") + end + routing_info = {:controller => 'general', + :action => 'search', + :combined => query, + :view => nil} + if !params.nil? + routing_info = params.merge(routing_info) + end + url = url_for(routing_info) # Here we can't escape the slashes, as RFC 2396 doesn't allow slashes # within a path component. Rails is assuming when generating URLs that # either there aren't slashes, or we are in a query part where you can @@ -150,19 +160,10 @@ module LinkToHelper # http://rails.lighthouseapp.com/projects/8994/tickets/144-patch-bug-in-rails-route-globbing url = url.gsub("%2F", "/") - if !variety_postfix.nil? && !variety_postfix.empty? - url = url + "/" + variety_postfix - end - if !sort_postfix.nil? && !sort_postfix.empty? - url = url + "/" + sort_postfix - end - if !advanced.nil? && (advanced) - url = url + "/advanced" - end return url end def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) - link_to h(query), search_url(query, variety_postfix, sort_postfix, advanced) + link_to h(query), search_url(query) end # Admin pages diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 6e073aa27..3e12a6feb 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -27,7 +27,7 @@ class RawEmail < ActiveRecord::Base def directory request_id = self.incoming_message.info_request.id.to_s if ENV["RAILS_ENV"] == "test" - return 'files/raw_email_test' + return File.join(RAILS_ROOT, 'files/raw_email_test') else return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION', 'files/raw_emails'), @@ -49,35 +49,13 @@ class RawEmail < ActiveRecord::Base end def data - if !File.exists?(self.filepath) - dbdata - else - File.open(self.filepath, "rb" ).read - end + File.open(self.filepath, "rb").read end def destroy_file_representation! File.delete(self.filepath) end - def dbdata=(d) - write_attribute(:data_binary, d) - end - - def dbdata - d = read_attribute(:data_binary) - if !d.nil? - return d - end - - d = read_attribute(:data_text) - if !d.nil? - return d - end - - raise "internal error, double nil value in RawEmail" - end - end diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml index fe6229293..90ace809e 100644 --- a/app/views/general/search.rhtml +++ b/app/views/general/search.rhtml @@ -56,11 +56,7 @@ ["all", _("everything")]]%> <% for variety, label in labels %> <% if @variety_postfix != variety %> - <% if variety != "users" %> - <%= link_to label, search_url([params[:query], @common_query], variety, @sort_postfix) %> - <% else %> - <%= link_to label, search_url(params[:query], variety, @sort_postfix) %> - <% end %> + <%= link_to label, search_url([params[:query], variety, @sort_postfix]) %> <% else %> <%= label %> <% end %> @@ -126,9 +122,9 @@ <% if !@query.nil? %> <p id="search_controls"> - <%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_url(@query, @variety_postfix, 'relevant') %> + <%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_url([params[:query], @variety_postfix, 'relevant'], params) %> | - <%=link_to_unless @sortby == 'newest', _("Newest results first"), search_url(@query, @variety_postfix, 'newest') %> + <%=link_to_unless @sortby == 'newest', _("Newest results first"), search_url([params[:query], @variety_postfix, 'newest'], params) %> <% if @sortby == 'described' %> | <%= _('Recently described results first') %> <% end %> diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml index 42cd41498..7cbd982f1 100644 --- a/app/views/request/list.rhtml +++ b/app/views/request/list.rhtml @@ -14,7 +14,7 @@ <div style="clear:both"></div> <div class="results_section"> - <% view_cache :ttl => 5.minutes.to_i, :tag => [@query, @page, I18n.locale] do %> + <% view_cache :ttl => 5.minutes.to_i, :tag => [@cache_tag] do %> <% if @list_results.empty? %> <p> <%= _('No requests of this sort yet.')%></p> <% else %> diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml index 4fa29f00d..a4466f5f4 100644 --- a/app/views/user/show.rhtml +++ b/app/views/user/show.rhtml @@ -190,56 +190,56 @@ <% end %> <% end %> - <% if @show_profile && @is_you %> - <% if @track_things.empty? %> - <h2 id="email_subscriptions"> <%= _('Your email subscriptions')%></h2> - <p><%= _('None made.')%></p> - <% else %> - <h2 id="email_subscriptions"> Your <%=pluralize(@track_things.size, _('email subscription')) %> </h2> - <% if @track_things_grouped.size == 1 %> +</div> +<% end %> +<% if @show_profile && @is_you %> + <% if @track_things.empty? %> + <h2 id="email_subscriptions"> <%= _('Your email subscriptions')%></h2> + <p><%= _('None made.')%></p> + <% else %> + <h2 id="email_subscriptions"> Your <%=pluralize(@track_things.size, _('email subscription')) %> </h2> + <% if @track_things_grouped.size == 1 %> + <% form_tag({:controller => 'track', :action => 'delete_all_type'}, :class => "feed_form") do %> + <h3> + <%=TrackThing.track_type_description(@track_things[0].track_type)%> + <%= hidden_field_tag 'track_type', @track_things[0].track_type %> + <%= hidden_field_tag 'user', @display_user.id %> + <%= hidden_field_tag 'r', request.request_uri %> + <% if @track_things.size > 1 %> + <%= submit_tag _('unsubscribe all') %> + <% end %> + </h3> + <% end %> + <% end %> + <% for track_type, track_things in @track_things_grouped %> + <% if @track_things_grouped.size > 1 %> <% form_tag({:controller => 'track', :action => 'delete_all_type'}, :class => "feed_form") do %> <h3> - <%=TrackThing.track_type_description(@track_things[0].track_type)%> - <%= hidden_field_tag 'track_type', @track_things[0].track_type %> + <%=TrackThing.track_type_description(track_type)%> + <%= hidden_field_tag 'track_type', track_type %> <%= hidden_field_tag 'user', @display_user.id %> <%= hidden_field_tag 'r', request.request_uri %> - <% if @track_things.size > 1 %> - <%= submit_tag _('unsubscribe all') %> - <% end %> + <% if track_things.size > 1 %> + <%= submit_tag _('unsubscribe all')%> + <% end %> </h3> <% end %> <% end %> - <% for track_type, track_things in @track_things_grouped %> - <% if @track_things_grouped.size > 1 %> - <% form_tag({:controller => 'track', :action => 'delete_all_type'}, :class => "feed_form") do %> - <h3> - <%=TrackThing.track_type_description(track_type)%> - <%= hidden_field_tag 'track_type', track_type %> - <%= hidden_field_tag 'user', @display_user.id %> - <%= hidden_field_tag 'r', request.request_uri %> - <% if track_things.size > 1 %> - <%= submit_tag _('unsubscribe all')%> - <% end %> - </h3> - <% end %> - <% end %> - <ul> - <% for track_thing in track_things %> - <li> - <% form_tag({:controller => 'track', :action => 'update', :track_id => track_thing.id}, :class => "feed_form") do %> - <div> - <%= track_thing.params[:list_description] %> - <%= hidden_field_tag 'track_medium', "delete", { :id => 'track_medium_' + track_thing.id.to_s } %> - <%= hidden_field_tag 'r', request.request_uri, { :id => 'r_' + track_thing.id.to_s } %> - <%= submit_tag _('unsubscribe') %> - </div> - <% end %> - </li> - <% end %> - </ul> + <ul> + <% for track_thing in track_things %> + <li> + <% form_tag({:controller => 'track', :action => 'update', :track_id => track_thing.id}, :class => "feed_form") do %> + <div> + <%= track_thing.params[:list_description] %> + <%= hidden_field_tag 'track_medium', "delete", { :id => 'track_medium_' + track_thing.id.to_s } %> + <%= hidden_field_tag 'r', request.request_uri, { :id => 'r_' + track_thing.id.to_s } %> + <%= submit_tag _('unsubscribe') %> + </div> + <% end %> + </li> <% end %> + </ul> <% end %> <% end %> -</div> <% end %> |