diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/comment.rb | 10 | ||||
-rw-r--r-- | app/models/info_request.rb | 6 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 14 | ||||
-rw-r--r-- | app/models/user.rb | 6 |
4 files changed, 31 insertions, 5 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb index 967108171..e4b995f32 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,7 +19,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: comment.rb,v 1.6 2008-09-22 22:16:37 francis Exp $ +# $Id: comment.rb,v 1.7 2008-10-02 23:11:40 francis Exp $ class Comment < ActiveRecord::Base belongs_to :user @@ -43,6 +43,14 @@ class Comment < ActiveRecord::Base read_attribute(:body) end + # So when made invisble it vanishes + after_save :event_xapian_update + def event_xapian_update + for event in self.info_request_events + event.xapian_mark_needs_index + end + end + # Check have edited comment def validate if self.body.empty? || self.body =~ /^\s+$/ diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 43d566199..e9f76f445 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -23,7 +23,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.143 2008-09-23 00:47:50 francis Exp $ +# $Id: info_request.rb,v 1.144 2008-10-02 23:11:40 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') @@ -76,6 +76,10 @@ class InfoRequest < ActiveRecord::Base end end + def visible_comments + self.comments.find(:all, :conditions => 'visible') + end + # Central function to do all searches # (Not really the right place to put it, but everything can get it here, and it # does *mainly* find info requests, via their events, so hey) diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 7b32954d3..0b6e126a9 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -21,7 +21,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.61 2008-09-23 21:00:14 francis Exp $ +# $Id: info_request_event.rb,v 1.62 2008-10-02 23:11:40 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -149,7 +149,10 @@ class InfoRequestEvent < ActiveRecord::Base end def indexed_by_search if ['sent', 'followup_sent', 'response', 'comment'].include?(self.event_type) - if info_request.prominence == 'backpage' + if self.info_request.prominence == 'backpage' + return false + end + if self.event_type == 'comment' && !self.comment.visible return false end return true @@ -161,6 +164,13 @@ class InfoRequestEvent < ActiveRecord::Base self.event_type end + def visible + if self.event_type == 'comment' + return self.comment.visible + end + return true + end + # We store YAML version of parameters in the database def params=(params) # XXX should really set these explicitly, and stop storing them in diff --git a/app/models/user.rb b/app/models/user.rb index ba7e6f72b..072cca50a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,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.72 2008-09-24 12:59:27 francis Exp $ +# $Id: user.rb,v 1.73 2008-10-02 23:11:40 francis Exp $ require 'digest/sha1' @@ -68,6 +68,10 @@ class User < ActiveRecord::Base end end + def visible_comments + self.comments.find(:all, :conditions => 'visible') + end + def validate errors.add(:email, "doesn't look like a valid address") unless MySociety::Validate.is_valid_email(self.email) if MySociety::Validate.is_valid_email(self.name) |