aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/public_body_controller.rb23
-rw-r--r--app/helpers/public_body_helper.rb21
-rw-r--r--app/mailers/contact_mailer.rb2
-rw-r--r--app/mailers/outgoing_mailer.rb2
-rw-r--r--app/models/incoming_message.rb16
-rw-r--r--app/models/info_request_event.rb6
-rw-r--r--app/models/public_body.rb30
-rw-r--r--app/views/public_body/show.html.erb83
-rw-r--r--app/views/request/_request_listing_via_event.html.erb4
-rw-r--r--app/views/request/_request_search_form.html.erb44
-rw-r--r--app/views/track/_tracking_links.html.erb34
11 files changed, 133 insertions, 132 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 1b01dc837..376b2024a 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -16,22 +16,28 @@ class PublicBodyController < ApplicationController
long_cache
@page = get_search_page_from_params
requests_per_page = 25
+
# Later pages are very expensive to load
if @page > MAX_RESULTS / requests_per_page
raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / requests_per_page}.")
end
+
if MySociety::Format.simplify_url_part(params[:url_name], 'body') != params[:url_name]
redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently
return
end
+
@locale = locale_from_params
+
I18n.with_locale(@locale) do
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
+
if @public_body.url_name.nil?
redirect_to :back
return
end
+
# If found by historic name, or alternate locale name, redirect to new name
if @public_body.url_name != params[:url_name]
redirect_to :url_name => @public_body.url_name
@@ -42,22 +48,25 @@ class PublicBodyController < ApplicationController
@number_of_visible_requests = @public_body.info_requests.visible.count
- top_url = frontpage_url
@searched_to_send_request = false
referrer = request.env['HTTP_REFERER']
- if !referrer.nil? && referrer.match(%r{^#{top_url}search/.*/bodies$})
+
+ if !referrer.nil? && referrer.match(%r{^#{frontpage_url}search/.*/bodies$})
@searched_to_send_request = true
end
+
@view = params[:view]
+
query = InfoRequestEvent.make_query_from_params(params.merge(:latest_status => @view))
query += " requested_from:#{@public_body.url_name}"
+
# Use search query for this so can collapse and paginate easily
# TODO: really should just use SQL query here rather than Xapian.
sortby = "described"
begin
@xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse', requests_per_page)
if (@page > 1)
- @page_desc = " (page " + @page.to_s + ")"
+ @page_desc = " (page #{ @page })"
else
@page_desc = ""
end
@@ -68,10 +77,16 @@ class PublicBodyController < ApplicationController
flash.keep(:search_params)
@track_thing = TrackThing.create_track_for_public_body(@public_body)
+
if @user
@existing_track = TrackThing.find_existing(@user, @track_thing)
end
- @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
+
+ @follower_count = TrackThing.where(:public_body_id => @public_body.id).count
+
+ @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; render :template => "public_body/show"}
diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb
index e094d98b4..b8e59a341 100644
--- a/app/helpers/public_body_helper.rb
+++ b/app/helpers/public_body_helper.rb
@@ -37,22 +37,19 @@ module PublicBodyHelper
#
# public_body - Instance of a PublicBody
#
- # Returns a string
+ # Returns a String
def type_of_authority(public_body)
- first = true
- types = public_body.tags.each.map do |tag|
- if PublicBodyCategory.get.by_tag.include?(tag.name)
- desc = PublicBodyCategory.get.singular_by_tag[tag.name]
- if first
- desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
- first = false
- end
- link_to(desc, list_public_bodies_path(tag.name))
+ categories = PublicBodyCategory.
+ where(:category_tag => public_body.tag_string.split)
+
+ types = categories.each_with_index.map do |category, index|
+ desc = category.description
+ if index.zero?
+ desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
end
+ link_to(desc, list_public_bodies_path(category.category_tag))
end
- types.compact!
-
if types.any?
types.to_sentence(:last_word_connector => ' and ').html_safe
else
diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb
index 7c48bfd4b..58e036d3b 100644
--- a/app/mailers/contact_mailer.rb
+++ b/app/mailers/contact_mailer.rb
@@ -10,7 +10,7 @@ class ContactMailer < ApplicationMailer
def to_admin_message(name, email, subject, message, logged_in_user, last_request, last_body)
@message, @logged_in_user, @last_request, @last_body = message, logged_in_user, last_request, last_body
- mail(:from => "#{name} <#{email}>",
+ mail(:from => MailHandler.address_from_name_and_email(name, email),
:to => contact_from_name_and_email,
:subject => subject)
end
diff --git a/app/mailers/outgoing_mailer.rb b/app/mailers/outgoing_mailer.rb
index 78041d04b..cc6190954 100644
--- a/app/mailers/outgoing_mailer.rb
+++ b/app/mailers/outgoing_mailer.rb
@@ -70,7 +70,7 @@ class OutgoingMailer < ApplicationMailer
# Subject to use for followup
def self.subject_for_followup(info_request, outgoing_message, options = {})
if outgoing_message.what_doing == 'internal_review'
- return "Internal review of " + info_request.email_subject_request(:html => options[:html])
+ return _("Internal review of {{email_subject}}", :email_subject => info_request.email_subject_request(:html => options[:html]))
else
return info_request.email_subject_followup(:incoming_message => outgoing_message.incoming_message_followup,
:html => options[:html])
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index dff516f0e..7e1567bd1 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -506,14 +506,9 @@ class IncomingMessage < ActiveRecord::Base
# Find any uudecoded things buried in it, yeuchly
uus = text.scan(/^begin.+^`\n^end\n/m)
attachments = []
- for uu in uus
+ uus.each do |uu|
# Decode the string
- content = nil
- tempfile = Tempfile.new('foiuu')
- tempfile.print uu
- tempfile.flush
- content = AlaveteliExternalCommand.run("uudecode", "-o", "/dev/stdout", tempfile.path)
- tempfile.close
+ content = uu.sub(/\Abegin \d+ [^\n]*\n/, '').unpack('u').first
# Make attachment type from it, working out filename and mime type
filename = uu.match(/^begin\s+[0-9]+\s+(.*)$/)[1]
calc_mime = AlaveteliFileTypes.filename_and_content_to_mimetype(filename, content)
@@ -524,15 +519,14 @@ class IncomingMessage < ActiveRecord::Base
content_type = 'application/octet-stream'
end
hexdigest = Digest::MD5.hexdigest(content)
- attachment = self.foi_attachments.find_or_create_by_hexdigest(hexdigest)
+ attachment = foi_attachments.find_or_create_by_hexdigest(hexdigest)
attachment.update_attributes(:filename => filename,
:content_type => content_type,
- :body => content,
- :display_size => "0K")
+ :body => content)
attachment.save!
attachments << attachment
end
- return attachments
+ attachments
end
def get_attachments_for_display
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 29c1ce965..263de20a0 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -327,15 +327,15 @@ class InfoRequestEvent < ActiveRecord::Base
def is_incoming_message?
- !self.incoming_message_selective_columns("incoming_messages.id").nil?
+ incoming_message_id? or (incoming_message if new_record?)
end
def is_outgoing_message?
- !self.outgoing_message.nil?
+ outgoing_message_id? or (outgoing_message if new_record?)
end
def is_comment?
- !self.comment.nil?
+ comment_id? or (comment if new_record?)
end
# Display version of status
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index fec1cefb6..5053523a3 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -160,25 +160,27 @@ class PublicBody < ActiveRecord::Base
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
- found = PublicBody.find(:all,
- :conditions => ["public_body_translations.url_name=?", name],
- :joins => :translations,
- :readonly => false)
- # If many bodies are found (usually because the url_name is the same across
- # locales) return any of them
- return found.first if found.size >= 1
-
- # If none found, then search the history of short names
- old = PublicBody::Version.find_all_by_url_name(name)
- # Find unique public bodies in it
- old = old.map { |x| x.public_body_id }
- old = old.uniq
+ # If many bodies are found (usually because the url_name is the same
+ # across locales) return any of them.
+ found = joins(:translations).
+ where("public_body_translations.url_name = ?", name).
+ readonly(false).
+ first
+
+ return found if found
+
+ # If none found, then search the history of short names and find unique
+ # public bodies in it
+ old = PublicBody::Version.
+ where(:url_name => name).
+ pluck('DISTINCT public_body_id')
+
# Maybe return the first one, so we show something relevant,
# rather than throwing an error?
raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
return unless old.size == 1
# does acts_as_versioned provide a method that returns the current version?
- return PublicBody.find(old.first)
+ PublicBody.find(old.first)
end
# Set the first letter, which is used for faster queries
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index 9dd3dc7cb..546db681e 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -11,35 +11,37 @@
<% end %>
<div class="authority__header">
- <h1><%=h(@public_body.name)%></h1>
+ <h1><%= h(@public_body.name) %></h1>
<p class="authority__header__subtitle">
- <%= type_of_authority(@public_body) %><% if not @public_body.short_name.empty? %>,
- <%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name))%><% end %>
- <% if !@user.nil? && @user.admin_page_links? %>
- (<%= link_to _("admin"), admin_body_path(@public_body) %>)
+ <%= type_of_authority(@public_body) %><% unless @public_body.short_name.empty? %>,
+ <%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name)) %>
+ <% end %>
+
+ <% if @user && @user.admin_page_links? %>
+ (<%= link_to _("admin"), admin_body_path(@public_body) %>)
<% end %>
</p>
<% if @public_body.has_notes? || @public_body.eir_only? || @public_body.special_not_requestable_reason? %>
- <div id="stepwise_make_request">
- <% if @public_body.has_notes? %>
- <p class="authority__header__notes">
- <%= @public_body.notes_as_html.html_safe %>
- </p>
- <% end %>
+ <div id="stepwise_make_request">
+ <% if @public_body.has_notes? %>
+ <p class="authority__header__notes">
+ <%= @public_body.notes_as_html.html_safe %>
+ </p>
+ <% end %>
- <% if @public_body.is_requestable? %>
- <% if @public_body.eir_only? %>
+ <% if @public_body.is_requestable? %>
+ <% if @public_body.eir_only? %>
+ <p class="authority__header__notes">
+ <%= _('You can only request information about the environment from this authority.')%>
+ </p>
+ <% end %>
+ <% elsif @public_body.special_not_requestable_reason? %>
<p class="authority__header__notes">
- <%= _('You can only request information about the environment from this authority.')%>
+ <%= public_body_not_requestable_reasons(@public_body).first %>
</p>
<% end %>
- <% elsif @public_body.special_not_requestable_reason? %>
- <p class="authority__header__notes">
- <%= public_body_not_requestable_reasons(@public_body).first %>
- </p>
- <% end %>
- </div>
+ </div>
<% end %>
<% if @number_of_visible_requests > 0 %>
@@ -55,25 +57,25 @@
<div class="action-bar__make-request">
<% if @public_body.is_requestable? || @public_body.not_requestable_reason == 'bad_contact' %>
<%= link_to _("Make a request to this authority"), new_request_to_body_path(:url_name => @public_body.url_name), :class => "link_button_green" %>
- <% end %>
+ <% end %>
</div>
+
<div class="action-bar__follow">
- <% follower_count = TrackThing.count(:all, :conditions => ["public_body_id = ?", @public_body.id]) %>
- <div class="action-bar__follow-button">
- <% if @existing_track %>
- <%= (link_to _("Unsubscribe"), {:controller => 'track', :action => 'update', :track_id => @existing_track.id, :track_medium => "delete", :r => request.fullpath}, :class => "link_button_green") %>
- <% else %>
- <div class="feed_link">
- <%= link_to _("Follow"), do_track_path(@track_thing), :class => "link_button_green" %>
- </div>
- <% end %>
- </div>
+ <div class="action-bar__follow-button">
+ <% if @existing_track %>
+ <%= link_to _("Unsubscribe"), {:controller => 'track', :action => 'update', :track_id => @existing_track.id, :track_medium => "delete", :r => request.fullpath}, :class => "link_button_green" %>
+ <% else %>
+ <div class="feed_link">
+ <%= link_to _("Follow"), do_track_path(@track_thing), :class => "link_button_green" %>
+ </div>
+ <% end %>
+ </div>
<div class="action-bar__follower-count">
<%= n_("{{count}} follower",
"{{count}} followers",
- follower_count,
- :count => content_tag(:span, follower_count, :id => "follow_count")) %>
+ @follower_count,
+ :count => content_tag(:span, @follower_count, :id => "follow_count")) %>
</div>
</div>
</div>
@@ -81,7 +83,7 @@
<div class="authority__body">
<div class="authority__body__foi-results">
- <% if @number_of_visible_requests == 0 %>
+ <% if @number_of_visible_requests.zero? %>
<% if @public_body.is_requestable? or @public_body.not_requestable_reason != 'defunct' %>
<% if @public_body.eir_only? %>
<h2><%= _('Environmental Information Regulations requests made using this site') %></h2>
@@ -104,9 +106,8 @@
<% end %>
<% end %>
- <% if !@xapian_requests.nil? %>
-
- <% for result in @xapian_requests.results %>
+ <% if @xapian_requests %>
+ <% @xapian_requests.results.each do |result| %>
<%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
@@ -135,8 +136,14 @@
<% if @number_of_visible_requests > 4 %>
<%= render :partial => 'request/request_search_form' %>
<% end %>
+
<%= render :partial => 'more_info', :locals => { :public_body => @public_body } %>
- <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'sidebar' } %>
+
+ <%= render :partial => 'track/tracking_links',
+ :locals => { :track_thing => @track_thing,
+ :existing_track => @existing_track,
+ :own_request => false,
+ :location => 'sidebar' } %>
</div>
</div>
diff --git a/app/views/request/_request_listing_via_event.html.erb b/app/views/request/_request_listing_via_event.html.erb
index 20bc5b2c8..7ad568829 100644
--- a/app/views/request/_request_listing_via_event.html.erb
+++ b/app/views/request/_request_listing_via_event.html.erb
@@ -6,8 +6,8 @@ end %>
<div class="request_left">
<span class="head">
<% if event.is_incoming_message? %>
- <%= link_to highlight_words(event.info_request.title, @highlight_words), incoming_message_path(event.incoming_message_selective_columns("incoming_messages.id")) %>
- <% elsif event.is_outgoing_message? and event.event_type == 'followup_sent' %>
+ <%= link_to highlight_words(event.info_request.title, @highlight_words), incoming_message_path(event.incoming_message) %>
+ <% elsif event.is_outgoing_message? && event.event_type == 'followup_sent' %>
<%= link_to highlight_words(event.info_request.title, @highlight_words), outgoing_message_path(event.outgoing_message) %>
<% elsif event.is_comment? %>
<%= link_to highlight_words(event.info_request.title, @highlight_words), comment_path(event.comment) %>
diff --git a/app/views/request/_request_search_form.html.erb b/app/views/request/_request_search_form.html.erb
index 3f2f66950..795070337 100644
--- a/app/views/request/_request_search_form.html.erb
+++ b/app/views/request/_request_search_form.html.erb
@@ -2,34 +2,22 @@
<div id="list-filter">
<%= form_tag(request.path, :method => "get", :id=>"filter_requests_form") do %>
- <div class="list-filter-item">
- <%= label_tag(:query, _("Keywords"), :class=>"form_label title") %>
- <%= text_field_tag(:query, params[:query]) %>
- </div>
-<% if false # don't think we want this, but leaving as an example %>
- <div class="list-filter-item">
- <%= _("Search for words in:") %> <br/>
- <% [["sent", _("messages from users")],
- ["response", _("messages from authorities")],
- ["comment", _("comments")]].each_with_index do |item, index|
- variety, title = item %>
-
- <%= check_box_tag "request_variety[]", variety, params[:request_variety].nil? ? true : params[:request_variety].include?(variety), :id => "request_variety_#{index}" %>
- <%= label_tag("request_variety_#{index}", title) %> <br/>
- <% end %>
- </div>
-<% end %>
- <div class="list-filter-item">
- <%= label_tag(:query, _("Made between"), :class=>"form_label title") %>
- <%= text_field_tag(:request_date_after, params[:request_date_after], {:class => "use-datepicker", :size => 10}) %>&nbsp;&nbsp;
- <%= label_tag(:query, _("and"), :class=>"form_label") %>
- <%= text_field_tag(:request_date_before, params[:request_date_before], {:class => "use-datepicker", :size => 10}) %>
- </div>
+ <div class="list-filter-item">
+ <%= label_tag(:query, _("Keywords"), :class=>"form_label title") %>
+ <%= text_field_tag(:query, params[:query]) %>
+ </div>
+
+ <div class="list-filter-item">
+ <%= label_tag(:query, _("Made between"), :class=>"form_label title") %>
+ <%= text_field_tag(:request_date_after, params[:request_date_after], {:class => "use-datepicker", :size => 10}) %>&nbsp;&nbsp;
+ <%= label_tag(:query, _("and"), :class=>"form_label") %>
+ <%= text_field_tag(:request_date_before, params[:request_date_before], {:class => "use-datepicker", :size => 10}) %>
+ </div>
- <%= after_form_fields if defined?(after_form_fields) -%>
+ <%= after_form_fields if defined?(after_form_fields) -%>
- <div class="list-filter-item">
- <%= submit_tag(_("Search")) %>
- </div>
-<% end %>
+ <div class="list-filter-item">
+ <%= submit_tag(_("Search")) %>
+ </div>
+ <% end %>
</div>
diff --git a/app/views/track/_tracking_links.html.erb b/app/views/track/_tracking_links.html.erb
index c027e9732..d94d3be13 100644
--- a/app/views/track/_tracking_links.html.erb
+++ b/app/views/track/_tracking_links.html.erb
@@ -1,25 +1,23 @@
<%
- if @user
- existing_track = TrackThing.find_existing(@user, track_thing)
- end
+ existing_track = local_assigns.fetch(:existing_track) do
+ TrackThing.find_existing(@user, track_thing) if @user
+ end
%>
<% if own_request %>
- <p><%= _('This is your own request, so you will be automatically emailed when new responses arrive.')%></p>
+ <p><%= _('This is your own request, so you will be automatically emailed when new responses arrive.')%></p>
<% elsif existing_track %>
- <p><%= track_thing.params[:verb_on_page_already] %></p>
- <div class="feed_link feed_link_<%=location%>">
- <%= link_to _("Unsubscribe"), {:controller => 'track', :action => 'update', :track_id => existing_track.id, :track_medium => "delete", :r => request.fullpath}, :class => "link_button_green" %>
- </div>
+ <p><%= track_thing.params[:verb_on_page_already] %></p>
+
+ <div class="feed_link feed_link_<%= location %>">
+ <%= link_to _("Unsubscribe"), { :controller => 'track', :action => 'update', :track_id => existing_track.id, :track_medium => "delete", :r => request.fullpath }, :class => "link_button_green" %>
+ </div>
<% elsif track_thing %>
- <div class="feed_link feed_link_<%=location%>">
- <% if defined?(follower_count) && follower_count > 0 %>
- <%= link_to _("I like this request"), do_track_path(track_thing), :class => "link_button_green" %>
- <% else %>
- <%= link_to _("Follow"), do_track_path(track_thing), :class => "link_button_green" %>
- <% end %>
- </div>
+ <div class="feed_link feed_link_<%= location %>">
+ <% if defined?(follower_count) && follower_count > 0 %>
+ <%= link_to _("I like this request"), do_track_path(track_thing), :class => "link_button_green" %>
+ <% else %>
+ <%= link_to _("Follow"), do_track_path(track_thing), :class => "link_button_green" %>
+ <% end %>
+ </div>
<% end %>
-
-
-