aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/info_request_event.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/info_request_event.rb')
-rw-r--r--app/models/info_request_event.rb75
1 files changed, 34 insertions, 41 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 09eba31ab..5eed5ba83 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -1,28 +1,29 @@
# == Schema Information
-# Schema version: 114
#
# Table name: info_request_events
#
-# id :integer not null, primary key
-# info_request_id :integer not null
-# event_type :text not null
-# params_yaml :text not null
-# created_at :datetime not null
+# id :integer not null, primary key
+# info_request_id :integer not null
+# event_type :text not null
+# params_yaml :text not null
+# created_at :datetime not null
# described_state :string(255)
# calculated_state :string(255)
# last_described_at :datetime
# incoming_message_id :integer
# outgoing_message_id :integer
# comment_id :integer
-# prominence :string(255) default("normal"), not null
#
# models/info_request_event.rb:
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
-# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class InfoRequestEvent < ActiveRecord::Base
+
+ extend XapianQueries
+
belongs_to :info_request
validates_presence_of :info_request
@@ -48,10 +49,10 @@ class InfoRequestEvent < ActiveRecord::Base
'destroy_incoming', # deleted an incoming message (in admin interface)
'destroy_outgoing', # deleted an outgoing message (in admin interface)
'redeliver_incoming', # redelivered an incoming message elsewhere (in admin interface)
+ 'edit_incoming', # incoming message edited (in admin interface)
'move_request', # changed user or public body (in admin interface)
'hide', # hid a request (in admin interface)
'manual', # you did something in the db by hand
-
'response',
'comment',
'status_update'
@@ -63,34 +64,12 @@ class InfoRequestEvent < ActiveRecord::Base
# user described state (also update in info_request)
validate :must_be_valid_state
- # whether event is publicly visible
- validates_inclusion_of :prominence, :in => [
- 'normal',
- 'hidden',
- 'requester_only'
- ]
-
def must_be_valid_state
if !described_state.nil? and !InfoRequest.enumerate_states.include?(described_state)
errors.add(described_state, "is not a valid state")
end
end
- def user_can_view?(user)
- if !self.info_request.user_can_view?(user)
- raise "internal error, called user_can_view? on event when there is not permission to view entire request"
- end
-
- if self.prominence == 'hidden'
- return User.view_hidden_requests?(user)
- end
- if self.prominence == 'requester_only'
- return self.info_request.is_owning_user?(user)
- end
- return true
- end
-
-
# Full text search indexing
acts_as_xapian :texts => [ :search_text_main, :title ],
:values => [
@@ -259,6 +238,12 @@ class InfoRequestEvent < ActiveRecord::Base
if !self.info_request.indexed_by_search?
return false
end
+ if self.event_type == 'response' && !self.incoming_message.indexed_by_search?
+ return false
+ end
+ if ['sent', 'followup_sent'].include?(self.event_type) && !self.outgoing_message.indexed_by_search?
+ return false
+ end
if self.event_type == 'comment' && !self.comment.visible
return false
end
@@ -267,6 +252,7 @@ class InfoRequestEvent < ActiveRecord::Base
return false
end
end
+
def variety
self.event_type
end
@@ -356,6 +342,9 @@ class InfoRequestEvent < ActiveRecord::Base
end
raise _("unknown status ") + status
end
+ # TRANSLATORS: "Follow up" in this context means a further
+ # message sent by the requester to the authority after
+ # the initial request
return _("Follow up")
end
@@ -363,16 +352,19 @@ class InfoRequestEvent < ActiveRecord::Base
end
def is_sent_sort?
- if [ 'sent', 'resent'].include?(self.event_type)
- return true
- end
- return false
+ ['sent', 'resent'].include?(event_type)
end
+
def is_followup_sort?
- if [ 'followup_sent', 'followup_resent'].include?(self.event_type)
- return true
- end
- return false
+ ['followup_sent', 'followup_resent'].include?(event_type)
+ end
+
+ def outgoing?
+ ['sent', 'followup_sent'].include?(event_type)
+ end
+
+ def response?
+ event_type == 'response'
end
def same_email_as_previous_send?
@@ -401,7 +393,7 @@ class InfoRequestEvent < ActiveRecord::Base
:comment_id => self.comment_id,
# XXX would be nice to add links here, but alas the
- # code to make them is in views only. See views/request/details.rhtml
+ # code to make them is in views only. See views/request/details.html.erb
# perhaps can call with @template somehow
}
@@ -416,7 +408,7 @@ class InfoRequestEvent < ActiveRecord::Base
if deep
ret[:info_request] = self.info_request.json_for_api(false)
ret[:public_body] = self.info_request.public_body.json_for_api
- ret[:user] = self.info_request.user.json_for_api
+ ret[:user] = self.info_request.user_json_for_api
end
return ret
@@ -427,4 +419,5 @@ class InfoRequestEvent < ActiveRecord::Base
yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
end
end
+
end