aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_controller.rb2
-rw-r--r--app/controllers/admin_public_body_controller.rb2
-rw-r--r--app/controllers/admin_request_controller.rb8
-rw-r--r--app/controllers/api_controller.rb2
-rw-r--r--app/controllers/application_controller.rb11
-rw-r--r--app/controllers/request_controller.rb2
-rw-r--r--app/models/info_request.rb44
-rw-r--r--app/views/admin_general/timeline.html.erb2
8 files changed, 51 insertions, 22 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 0bccd3358..f5191504e 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -17,7 +17,7 @@ class AdminController < ApplicationController
end
# Always give full stack trace for admin interface
- def local_request?
+ def show_rails_exceptions?
true
end
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 078af12f4..ec2a08dbc 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -146,12 +146,12 @@ class AdminPublicBodyController < AdminController
if params[:csv_file]
csv_contents = params[:csv_file].read
@original_csv_file = params[:csv_file].original_filename
+ csv_contents = normalize_string_to_utf8(csv_contents)
# or from previous dry-run temporary file
elsif params[:temporary_csv_file] && params[:original_csv_file]
csv_contents = retrieve_csv_data(params[:temporary_csv_file])
@original_csv_file = params[:original_csv_file]
end
-
if !csv_contents.nil?
# Try with dry run first
errors, notes = PublicBody.import_csv(csv_contents,
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 66989ea93..40ccfb98c 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -62,9 +62,6 @@ class AdminRequestController < AdminController
@info_request.title = params[:info_request][:title]
@info_request.prominence = params[:info_request][:prominence]
- if @info_request.described_state != params[:info_request][:described_state]
- @info_request.set_described_state(params[:info_request][:described_state])
- end
@info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" ? true : false
@info_request.allow_new_responses_from = params[:info_request][:allow_new_responses_from]
@info_request.handle_rejected_responses = params[:info_request][:handle_rejected_responses]
@@ -77,13 +74,16 @@ class AdminRequestController < AdminController
{ :editor => admin_current_user(),
:old_title => old_title, :title => @info_request.title,
:old_prominence => old_prominence, :prominence => @info_request.prominence,
- :old_described_state => old_described_state, :described_state => @info_request.described_state,
+ :old_described_state => old_described_state, :described_state => params[:info_request][:described_state],
:old_awaiting_description => old_awaiting_description, :awaiting_description => @info_request.awaiting_description,
:old_allow_new_responses_from => old_allow_new_responses_from, :allow_new_responses_from => @info_request.allow_new_responses_from,
:old_handle_rejected_responses => old_handle_rejected_responses, :handle_rejected_responses => @info_request.handle_rejected_responses,
:old_tag_string => old_tag_string, :tag_string => @info_request.tag_string,
:old_comments_allowed => old_comments_allowed, :comments_allowed => @info_request.comments_allowed
})
+ if @info_request.described_state != params[:info_request][:described_state]
+ @info_request.set_described_state(params[:info_request][:described_state])
+ end
# expire cached files
expire_for_request(@info_request)
flash[:notice] = 'Request successfully updated.'
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 49b226e4b..e7bea67ef 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -63,6 +63,8 @@ class ApiController < ApplicationController
:smtp_message_id => nil
)
+ request.set_described_state('waiting_response')
+
# Return the URL and ID number.
render :json => {
'url' => make_url("request", request.url_title),
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 88b107861..2ce44011f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -119,12 +119,9 @@ class ApplicationController < ActionController::Base
end
def render_exception(exception)
-
- # In development, or the admin interface, or for a local request, let Rails handle the exception
- # with its stack trace templates. Local requests in testing are a special case so that we can
- # test this method - there we use consider_all_requests_local to control behaviour.
- if Rails.application.config.consider_all_requests_local || local_request? ||
- (request.local? && !Rails.env.test?)
+ # In development or the admin interface let Rails handle the exception
+ # with its stack trace templates
+ if Rails.application.config.consider_all_requests_local || show_rails_exceptions?
raise exception
end
@@ -150,7 +147,7 @@ class ApplicationController < ActionController::Base
end
end
- def local_request?
+ def show_rails_exceptions?
false
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 0c1d9880c..45d8b7de6 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -593,7 +593,7 @@ class RequestController < ApplicationController
@outgoing_message.set_signature_name(@user.name) if !@user.nil?
if (not @incoming_message.nil?) and @info_request != @incoming_message.info_request
- raise sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, @info_request.id)
+ raise ActiveRecord::RecordNotFound.new("Incoming message #{@incoming_message.id} does not belong to request #{@info_request.id}")
end
# Test for hidden requests
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 8f15a4ea4..9bce2ca88 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -563,12 +563,15 @@ public
end
# change status, including for last event for later historical purposes
+ # described_state should always indicate the current state of the request, as described
+ # by the request owner (or, in some other cases an admin or other user)
def set_described_state(new_state, set_by = nil, message = "")
old_described_state = described_state
ActiveRecord::Base.transaction do
self.awaiting_description = false
last_event = self.info_request_events.last
last_event.described_state = new_state
+
self.described_state = new_state
last_event.save!
self.save!
@@ -588,11 +591,14 @@ public
end
end
- # Work out what the situation of the request is. In addition to values of
- # self.described_state, can take these two values:
+ # Work out what state to display for the request on the site. In addition to values of
+ # self.described_state, can take these values:
# waiting_classification
# waiting_response_overdue
# waiting_response_very_overdue
+ # (this method adds an assessment of overdueness with respect to the current time to 'waiting_response'
+ # states, and will return 'waiting_classification' instead of the described_state if the
+ # awaiting_description flag is set on the request).
def calculate_status(cached_value_ok=false)
if cached_value_ok && @cached_calculated_status
return @cached_calculated_status
@@ -611,10 +617,22 @@ public
return 'waiting_response'
end
+
+ # 'described_state' can be populated on any info_request_event but is only
+ # ever used in the process populating calculated_state on the
+ # info_request_event (if it represents a response, outgoing message, edit
+ # or status update), or previous response or outgoing message events for
+ # the same request.
+
# Fill in any missing event states for first response before a description
# was made. i.e. We take the last described state in between two responses
# (inclusive of earlier), and set it as calculated value for the earlier
- # response.
+ # response. Also set the calculated state for any initial outgoing message,
+ # follow up, edit or status_update to the described state of that event.
+
+ # Note that the calculated state of the latest info_request_event will
+ # be used in latest_status based searches and should match the described_state
+ # of the info_request.
def calculate_event_states
curr_state = nil
for event in self.info_request_events.reverse
@@ -636,7 +654,7 @@ public
event.save!
end
curr_state = nil
- elsif !curr_state.nil? && (event.event_type == 'followup_sent' || event.event_type == 'sent' || event.event_type == "status_update")
+ elsif !curr_state.nil? && (event.event_type == 'followup_sent' || event.event_type == 'sent') && !event.described_state.nil? && (event.described_state == 'waiting_response' || event.described_state == 'internal_review')
# Followups can set the status to waiting response / internal
# review. Initial requests ('sent') set the status to waiting response.
@@ -648,10 +666,22 @@ public
event.save!
end
- # And we don't want to propogate it to the response itself,
+ # And we don't want to propagate it to the response itself,
# as that might already be set to waiting_clarification / a
# success status, which we want to know about.
curr_state = nil
+ elsif !curr_state.nil? && (['edit', 'status_update'].include? event.event_type)
+ # A status update or edit event should get the same calculated state as described state
+ # so that the described state is always indexed (and will be the latest_status
+ # for the request immediately after it has been described, regardless of what
+ # other request events precede it). This means that request should be correctly included
+ # in status searches for that status. These events allow the described state to propagate in
+ # case there is a preceding response that the described state should be applied to.
+ if event.calculated_state != event.described_state
+ event.calculated_state = event.described_state
+ event.last_described_at = Time.now()
+ event.save!
+ end
end
end
end
@@ -1107,10 +1137,10 @@ public
begin
if self.described_state.nil?
self.described_state = 'waiting_response'
- end
+ end
rescue ActiveModel::MissingAttributeError
# this should only happen on Model.exists?() call. It can be safely ignored.
- # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/
+ # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/
end
# FOI or EIR?
if !self.public_body.nil? && self.public_body.eir_only?
diff --git a/app/views/admin_general/timeline.html.erb b/app/views/admin_general/timeline.html.erb
index 8fd8875b6..439ae1e68 100644
--- a/app/views/admin_general/timeline.html.erb
+++ b/app/views/admin_general/timeline.html.erb
@@ -88,7 +88,7 @@
<% elsif event.event_type == 'comment' %>
had an annotation posted by <%=h event.comment.user.name %>.
<% elsif event.event_type == 'status_update' %>
- had its status updated by <%=h User.find(event.params[:user_id]).name %> from '<%= h event.params[:old_described_state] %>' to '<%= h event.params[:described_state] %>'.
+ had its status updated by <%= event.params[:user_id] ? User.find(event.params[:user_id]).name : event.params[:script] %> from '<%= h event.params[:old_described_state] %>' to '<%= h event.params[:described_state] %>'.
<% else %>
had '<%=event.event_type%>' done to it, parameters <%=h event.params_yaml%>.
<% end %>