aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/responsive/_user_layout.scss4
-rw-r--r--app/controllers/admin_request_controller.rb25
-rw-r--r--app/controllers/admin_spam_addresses_controller.rb4
-rw-r--r--app/controllers/request_controller.rb33
-rw-r--r--app/controllers/user_controller.rb15
-rw-r--r--app/models/info_request_batch.rb8
-rw-r--r--app/models/outgoing_message.rb70
-rw-r--r--app/views/admin_request/_incoming_message_actions.html.erb2
-rw-r--r--app/views/admin_spam_addresses/index.html.erb4
-rw-r--r--app/views/user/show.html.erb3
10 files changed, 122 insertions, 46 deletions
diff --git a/app/assets/stylesheets/responsive/_user_layout.scss b/app/assets/stylesheets/responsive/_user_layout.scss
index a568a5fa3..84ddbf562 100644
--- a/app/assets/stylesheets/responsive/_user_layout.scss
+++ b/app/assets/stylesheets/responsive/_user_layout.scss
@@ -4,4 +4,8 @@
#search_form {
margin-top: 2rem;
}
+
+ #request_latest_status {
+ width: 300px;
+ }
}
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 21120e4ad..8f023bf12 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -37,7 +37,30 @@ class AdminRequestController < AdminController
def resend
@outgoing_message = OutgoingMessage.find(params[:outgoing_message_id])
- @outgoing_message.resend_message
+ @outgoing_message.prepare_message_for_resend
+
+ mail_message = case @outgoing_message.message_type
+ when 'initial_request'
+ OutgoingMailer.initial_request(
+ @outgoing_message.info_request,
+ @outgoing_message
+ ).deliver
+ when 'followup'
+ OutgoingMailer.followup(
+ @outgoing_message.info_request,
+ @outgoing_message,
+ @outgoing_message.incoming_message_followup
+ ).deliver
+ else
+ raise "Message id #{id} has type '#{message_type}' which cannot be resent"
+ end
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id,
+ 'resent'
+ )
+
flash[:notice] = "Outgoing message resent"
redirect_to admin_request_show_url(@outgoing_message.info_request)
end
diff --git a/app/controllers/admin_spam_addresses_controller.rb b/app/controllers/admin_spam_addresses_controller.rb
index f5c7e93da..fff7e2a4a 100644
--- a/app/controllers/admin_spam_addresses_controller.rb
+++ b/app/controllers/admin_spam_addresses_controller.rb
@@ -10,7 +10,7 @@ class AdminSpamAddressesController < AdminController
if @spam_address.save
notice = "#{ @spam_address.email } has been added to the spam addresses list"
- redirect_to spam_addresses_path, :notice => notice
+ redirect_to admin_spam_addresses_path, :notice => notice
else
@spam_addresses = SpamAddress.all
render :index
@@ -21,7 +21,7 @@ class AdminSpamAddressesController < AdminController
@spam_address = SpamAddress.find(params[:id])
@spam_address.destroy
notice = "#{ @spam_address.email } has been removed from the spam addresses list"
- redirect_to spam_addresses_path, :notice => notice
+ redirect_to admin_spam_addresses_path, :notice => notice
end
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 3fa0ef0ce..9e2c291dc 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -365,8 +365,21 @@ class RequestController < ApplicationController
end
# This automatically saves dependent objects, such as @outgoing_message, in the same transaction
@info_request.save!
- # TODO: send_message needs the database id, so we send after saving, which isn't ideal if the request broke here.
- @outgoing_message.send_message
+
+ # TODO: Sending the message needs the database id, so we send after
+ # saving, which isn't ideal if the request broke here.
+ if @outgoing_message.sendable?
+ mail_message = OutgoingMailer.initial_request(
+ @outgoing_message.info_request,
+ @outgoing_message
+ ).deliver
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id
+ )
+ end
+
flash[:notice] = _("<p>Your {{law_used_full}} request has been <strong>sent on its way</strong>!</p>
<p><strong>We will email you</strong> when there is a response, or after {{late_number_of_days}} working days if the authority still hasn't
replied by then.</p>
@@ -668,13 +681,27 @@ class RequestController < ApplicationController
end
# Send a follow up message
- @outgoing_message.send_message
+ @outgoing_message.sendable?
+
+ mail_message = OutgoingMailer.followup(
+ @outgoing_message.info_request,
+ @outgoing_message,
+ @outgoing_message.incoming_message_followup
+ ).deliver
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id
+ )
+
@outgoing_message.save!
+
if @outgoing_message.what_doing == 'internal_review'
flash[:notice] = _("Your internal review request has been sent on its way.")
else
flash[:notice] = _("Your follow up message has been sent on its way.")
end
+
redirect_to request_url(@info_request)
end
else
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index f23343ddb..baeaab18a 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -49,13 +49,28 @@ class UserController < ApplicationController
# TODO: really should just use SQL query here rather than Xapian.
if @show_requests
begin
+
+ request_states = @display_user.info_requests.pluck(:described_state).uniq
+
+ option_item = Struct.new(:value, :text)
+ @request_states = request_states.map do |state|
+ option_item.new(state, InfoRequest.get_status_description(state))
+ end
+
requests_query = 'requested_by:' + @display_user.url_name
comments_query = 'commented_by:' + @display_user.url_name
if !params[:user_query].nil?
requests_query += " " + params[:user_query]
comments_query += " " + params[:user_query]
@match_phrase = _("{{search_results}} matching '{{query}}'", :search_results => "", :query => params[:user_query])
+
+ unless params[:request_latest_status].blank?
+ requests_query << ' latest_status:' << params[:request_latest_status]
+ comments_query << ' latest_status:' << params[:request_latest_status]
+ @match_phrase << _(" filtered by status: '{{status}}'", :status => params[:request_latest_status])
+ end
end
+
@xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse')
@xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil)
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb
index d7c5eb9af..8a5ebeaba 100644
--- a/app/models/info_request_batch.rb
+++ b/app/models/info_request_batch.rb
@@ -46,7 +46,13 @@ class InfoRequestBatch < ActiveRecord::Base
self.sent_at = Time.now
self.save!
end
- created.each{ |info_request| info_request.outgoing_messages.first.send_message }
+ created.each do |info_request|
+ outgoing_message = info_request.outgoing_messages.first
+
+ outgoing_message.sendable?
+ mail_message = OutgoingMailer.initial_request(outgoing_message.info_request, outgoing_message).deliver
+ outgoing_message.record_email_delivery(mail_message.to_addrs.join(', '), mail_message.message_id)
+ end
return unrequestable
end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 9424113fc..fa83c7381 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -171,57 +171,42 @@ class OutgoingMessage < ActiveRecord::Base
MySociety::Validate.contains_postcode?(body)
end
- # Deliver outgoing message
- # Note: You can test this from script/console with, say:
- # InfoRequest.find(1).outgoing_messages[0].send_message
- def send_message(log_event_type = 'sent')
+ def record_email_delivery(to_addrs, message_id, log_event_type = 'sent')
+ self.last_sent_at = Time.now
+ self.status = 'sent'
+ save!
+
+ log_event_type = "followup_#{ log_event_type }" if message_type == 'followup'
+
+ info_request.log_event(log_event_type, { :email => to_addrs,
+ :outgoing_message_id => id,
+ :smtp_message_id => message_id })
+ set_info_request_described_state
+ end
+
+ def sendable?
if status == 'ready'
if message_type == 'initial_request'
- self.last_sent_at = Time.now
- self.status = 'sent'
- self.save!
-
- mail_message = OutgoingMailer.initial_request(info_request, self).deliver
- self.info_request.log_event(log_event_type, {
- :email => mail_message.to_addrs.join(", "),
- :outgoing_message_id => self.id,
- :smtp_message_id => mail_message.message_id
- })
- self.info_request.set_described_state('waiting_response')
+ return true
elsif message_type == 'followup'
- self.last_sent_at = Time.now
- self.status = 'sent'
- self.save!
-
- mail_message = OutgoingMailer.followup(info_request, self, incoming_message_followup).deliver
- self.info_request.log_event('followup_' + log_event_type, {
- :email => mail_message.to_addrs.join(", "),
- :outgoing_message_id => self.id,
- :smtp_message_id => mail_message.message_id
- })
- if info_request.described_state == 'waiting_clarification'
- self.info_request.set_described_state('waiting_response')
- end
- if what_doing == 'internal_review'
- self.info_request.set_described_state('internal_review')
- end
+ return true
else
- raise "Message id #{id} has type '#{message_type}' which send_message can't handle"
+ raise "Message id #{id} has type '#{message_type}' which cannot be sent"
end
elsif status == 'sent'
raise "Message id #{id} has already been sent"
else
- raise "Message id #{id} not in state for send_message"
+ raise "Message id #{id} not in state for sending"
end
end
# An admin function
- def resend_message
+ def prepare_message_for_resend
if ['initial_request', 'followup'].include?(message_type) and status == 'sent'
self.status = 'ready'
- send_message('resent')
else
- raise "Message id #{id} has type '#{message_type}' status '#{status}' which resend_message can't handle"
+ raise "Message id #{id} has type '#{message_type}' status " \
+ "'#{status}' which prepare_message_for_resend can't handle"
end
end
@@ -303,6 +288,19 @@ class OutgoingMessage < ActiveRecord::Base
private
+ def set_info_request_described_state
+ if message_type == 'initial_request'
+ info_request.set_described_state('waiting_response')
+ elsif message_type == 'followup'
+ if info_request.described_state == 'waiting_clarification'
+ info_request.set_described_state('waiting_response')
+ end
+ if what_doing == 'internal_review'
+ info_request.set_described_state('internal_review')
+ end
+ end
+ end
+
def set_default_letter
self.body = get_default_message if body.nil?
end
diff --git a/app/views/admin_request/_incoming_message_actions.html.erb b/app/views/admin_request/_incoming_message_actions.html.erb
index dd50eb047..22effcce5 100644
--- a/app/views/admin_request/_incoming_message_actions.html.erb
+++ b/app/views/admin_request/_incoming_message_actions.html.erb
@@ -25,7 +25,7 @@
<div class="control-group">
<label class="control-label">Mark <code>To:</code> address as spam</label>
<div class="controls">
- <%= link_to 'Spam Addresses', spam_addresses_path %>
+ <%= link_to 'Spam Addresses', admin_spam_addresses_path %>
</div>
</div>
diff --git a/app/views/admin_spam_addresses/index.html.erb b/app/views/admin_spam_addresses/index.html.erb
index 9846bc017..7a11f70e1 100644
--- a/app/views/admin_spam_addresses/index.html.erb
+++ b/app/views/admin_spam_addresses/index.html.erb
@@ -16,7 +16,7 @@
<div class="row">
<div class="span12">
- <%= form_for(@spam_address, :html => { :class => 'form-inline' }) do |f| -%>
+ <%= form_for(@spam_address, :url => admin_spam_addresses_path, :html => { :class => 'form-inline' }) do |f| -%>
<%= error_messages_for @spam_address %>
<%= f.text_field :email, :class => 'input-xxlarge', :placeholder => 'Enter email' %>
<%= f.submit 'Add Spam Address', :class => 'btn btn-warning' %>
@@ -39,7 +39,7 @@
<% @spam_addresses.each do |spam| %>
<tr>
<td><%= spam.email %></td>
- <td><%= link_to 'Remove', spam,
+ <td><%= link_to 'Remove', admin_spam_address_path(spam),
:method => :delete,
:confirm => 'This is permanent! Are you sure?',
:class => 'btn btn-mini btn-danger' %></td>
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index 7ae577565..b23f74326 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -121,6 +121,9 @@
<%= form_tag(show_user_url, :method => "get", :id=>"search_form") do %>
<div>
<%= text_field_tag(:user_query, params[:user_query], {:title => "type your search term here" }) %>
+ <%= select_tag :request_latest_status,
+ options_from_collection_for_select(@request_states, 'value', 'text', params[:request_latest_status]),
+ :prompt => _('Filter by Request Status (optional)') %>
<% if @is_you %>
<%= submit_tag(_("Search your contributions")) %>
<% else %>