end
if closed_since < 0
- notes.where("status != 'hidden'")
+ notes.where.not(:status => "hidden")
elsif closed_since > 0
- notes.where("(status = 'open' OR (status = 'closed' AND closed_at > '#{Time.now - closed_since.days}'))")
+ notes.where(:status => "open")
+ .or(notes.where(:status => "closed")
+ .where(notes.arel_table[:closed_at].gt(Time.now - closed_since.days)))
else
- notes.where("status = 'open'")
+ notes.where(:status => "open")
end
end
class Note < ActiveRecord::Base
include GeoRecord
- has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
+ has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validate :validate_position
- scope :visible, -> { where("status != 'hidden'") }
- scope :invisible, -> { where("status = 'hidden'") }
+ scope :visible, -> { where.not(:status => "hidden") }
+ scope :invisible, -> { where(:status => "hidden") }
after_initialize :set_defaults
assert_select "div.note-comments ul li", :count => 2
end
+ def test_read_note_hidden_user_comment
+ hidden_user = create(:user, :status => "deleted")
+ note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
+ create(:note_comment, :note => note, :author => hidden_user)
+ end
+
+ browse_check "note", note_with_hidden_user_comment.id, "browse/note"
+ assert_select "div.note-comments ul li", :count => 1
+
+ session[:user] = create(:moderator_user).id
+
+ browse_check "note", note_with_hidden_user_comment.id, "browse/note"
+ assert_select "div.note-comments ul li", :count => 1
+ end
+
##
# Methods to check redaction.
#