fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-08-22 06:57 am

[dw-free] Comment parameter to journal entry views

[commit: http://hg.dwscoalition.org/dw-free/rev/84f9c1bc8329]

http://bugs.dwscoalition.org/show_bug.cgi?id=1571

Fix visibility requirements: we want to filter to things everyone can see,
not just things that you can see.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Comment.pm
  • cgi-bin/LJ/Talk.pm
--------------------------------------------------------------------------------
diff -r c225ed7aee7d -r 84f9c1bc8329 cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm	Fri Aug 19 12:27:35 2011 +0800
+++ b/cgi-bin/LJ/Comment.pm	Mon Aug 22 14:57:06 2011 +0800
@@ -897,6 +897,22 @@
     return $_[0]->state eq 'F' ? 1 : 0;
 }
 
+sub viewable_by_others {
+    my ( $self ) = @_;
+
+    # Is the comment attached to a visible entry?
+    my $remote = LJ::get_remote();
+    return 0 unless $self->entry && $self->entry->visible_to( $remote );
+
+    # If the entry is visible, the comment should be generally viewable unless
+    # the comment is deleted, screened, or posted by a suspended user.
+    return 0 if $self->is_deleted;
+    return 0 if $self->is_screened;
+    return 0 if $self->poster && $self->poster->is_suspended;
+
+    return 1;
+}
+
 sub visible_to {
     my ($self, $u) = @_;
 
diff -r c225ed7aee7d -r 84f9c1bc8329 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Fri Aug 19 12:27:35 2011 +0800
+++ b/cgi-bin/LJ/Talk.pm	Mon Aug 22 14:57:06 2011 +0800
@@ -980,7 +980,7 @@
                 my %filtermap = (
                     screened => sub { return $pobj->is_screened },
                     frozen => sub { return $pobj->is_frozen },
-                    visible => sub { return $pobj->visible_to( $remote ) },
+                    visible => sub { return $pobj->viewable_by_others },
                 );
                 if ( $should_show && $opts->{filter} && exists $filtermap{ $opts->{filter} } ) {
                     $should_show = $filtermap{ $opts->{filter} }->();
--------------------------------------------------------------------------------