diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | app/models/info_request.rb | 52 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 5 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 4 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
7 files changed, 46 insertions, 31 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index fcd73508e..9c8d2fca9 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: incoming_messages # @@ -18,7 +18,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.37 2008-01-29 01:26:21 francis Exp $ +# $Id: incoming_message.rb,v 1.38 2008-02-06 09:41:44 francis Exp $ # TODO diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 8743a8572..68ace338a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,17 +1,16 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: info_requests # -# id :integer not null, primary key -# title :text not null -# user_id :integer not null -# public_body_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# described_state :string(255) not null -# awaiting_description :boolean default(false), not null -# described_last_incoming_message_id :integer +# id :integer not null, primary key +# title :text not null +# user_id :integer not null +# public_body_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# described_state :string(255) not null +# awaiting_description :boolean default(false), not null # # models/info_request.rb: @@ -20,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.33 2008-02-01 15:27:49 francis Exp $ +# $Id: info_request.rb,v 1.34 2008-02-06 09:41:44 francis Exp $ require 'digest/sha1' @@ -49,7 +48,9 @@ class InfoRequest < ActiveRecord::Base ] def after_initialize - self.described_state = 'waiting_response' + if self.described_state.nil? + self.described_state = 'waiting_response' + end end public @@ -225,15 +226,28 @@ public return excerpt end - # Returns all the messages which the user hasn't described yet - def incoming_messages_needing_description - if self.described_last_incoming_message_id.nil? - incoming_messages = self.incoming_messages.find(:all) + # Returns index of last event which is described or nil if none described. + def index_of_last_described_event + events = self.info_request_events.find(:all, :order => "created_at") + events.each_index do |i| + revi = events.size - 1 - i + m = events[revi] + if not m.described_state.nil? + return revi + end + end + return nil + end + + # Returns all the events which the user hasn't described yet - an empty array if all described. + def events_needing_description + events = self.info_request_events.find(:all, :order => "created_at") + i = self.index_of_last_described_event + if i.nil? + return events else - incoming_messages = self.incoming_messages.find(:all, :conditions => "id > " + self.described_last_incoming_message_id.to_s) + return events[i + 1, events.size] end - incoming_messages.sort! { |a,b| a.sent_at <=> b.sent_at } - return incoming_messages end protected diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index f291daca5..800acdf45 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: info_request_events # @@ -8,6 +8,7 @@ # event_type :text not null # params_yaml :text not null # created_at :datetime not null +# described_state :string(255) # # models/info_request_event.rb: @@ -15,7 +16,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request_event.rb,v 1.9 2008-02-01 15:27:49 francis Exp $ +# $Id: info_request_event.rb,v 1.10 2008-02-06 09:41:44 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 391308bd4..544ca87bc 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: outgoing_messages # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: outgoing_message.rb,v 1.24 2008-01-29 01:26:21 francis Exp $ +# $Id: outgoing_message.rb,v 1.25 2008-02-06 09:41:44 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 864f2880f..f98591c44 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: post_redirects # @@ -25,7 +25,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: post_redirect.rb,v 1.14 2008-01-29 01:26:21 francis Exp $ +# $Id: post_redirect.rb,v 1.15 2008-02-06 09:41:44 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 5e90ca9ec..2b367a84d 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: public_bodies # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.15 2008-01-29 01:26:21 francis Exp $ +# $Id: public_body.rb,v 1.16 2008-02-06 09:41:44 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name diff --git a/app/models/user.rb b/app/models/user.rb index 13a57ec92..7b23a1155 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 27 +# Schema version: 29 # # Table name: users # @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.23 2008-01-29 01:26:21 francis Exp $ +# $Id: user.rb,v 1.24 2008-02-06 09:41:44 francis Exp $ require 'digest/sha1' |