fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-12-29 10:46 am

[dw-free] Support journal parameter to addcomment

[commit: http://hg.dwscoalition.org/dw-free/rev/1275d9db0266]

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

Add a "journal" parameter, which is a username string (may be a personal
journal or a community journal)

Patch from LiveJournal, packaged for Dreamwidth by [personal profile] fu.

Files modified:
  • cgi-bin/LJ/Protocol.pm
  • t/protocol.t
--------------------------------------------------------------------------------
diff -r ea5fc2c10527 -r 1275d9db0266 cgi-bin/LJ/Protocol.pm
--- a/cgi-bin/LJ/Protocol.pm	Thu Dec 29 07:00:44 2011 +0000
+++ b/cgi-bin/LJ/Protocol.pm	Thu Dec 29 18:45:32 2011 +0800
@@ -218,9 +218,18 @@
     return fail($err,314) unless $u->is_paid;
     return fail($err,214) if LJ::Comment->is_text_spam( \ $req->{body} );
 
+    my $journal;
+    if ( $req->{journal} ){
+        $journal = LJ::load_user( $req->{journal} ) or return fail( $err, 100 );
+        return fail( $err, 214 )
+            if LJ::Talk::Post::require_captcha_test( $u, $journal, $req->{body}, $req->{ditemid} );
+    } else {
+        $journal = $u;
+    }
+
     # create
     my $comment = LJ::Comment->create(
-                        journal      => $u,
+                        journal      => $journal,
                         ditemid      => $req->{ditemid},
                         parenttalkid => ($req->{parenttalkid} || ($req->{parent} >> 8)),
 
diff -r ea5fc2c10527 -r 1275d9db0266 t/protocol.t
--- a/t/protocol.t	Thu Dec 29 07:00:44 2011 +0000
+++ b/t/protocol.t	Thu Dec 29 18:45:32 2011 +0800
@@ -3,11 +3,12 @@
 use warnings;
 
 use Test::More;
-plan tests => 231;
+plan tests => 237;
 
 use lib "$ENV{LJHOME}/cgi-bin";
 require 'ljlib.pl';
 use LJ::Protocol;
+use DW::Pay;
 
 use LJ::Test qw( temp_user temp_comm );
 no warnings "once";
@@ -822,3 +823,73 @@
     }, "No new entries." );
 
 }
+
+note( "adding a comment to a journal" );
+{
+    my $u = temp_user();
+    $u->update_self({ status => "A" });
+    DW::Pay::add_paid_time( $u, "paid", 2 );
+
+    my $entry = $u->t_post_fake_entry;
+
+    ( $res, $err ) = $do_request->( "addcomment",
+        username => $u->user,
+
+        ditemid => $entry->ditemid,
+        subject => "subject",
+        body    => "comment body " . rand(),
+    );
+
+    my $comment = LJ::Comment->new( $entry->journal, dtalkid => $res->{dtalkid} );
+    ok( $comment->poster->equals( $u ), "Check comment poster when posting to your own journal" );
+    ok( $comment->journal->equals( $u ), "Check comment journal when posting to your own journal" );
+}
+
+note( "adding a comment to a community" );
+{
+    my $u = temp_user();
+    $u->update_self({ status => "A" });
+    DW::Pay::add_paid_time( $u, "paid", 2 );
+
+    my $cu = temp_comm();
+
+    my $entry = $u->t_post_fake_comm_entry( $cu );
+
+    ( $res, $err ) = $do_request->( "addcomment",
+        username => $u->user,
+        journal => $cu->user,
+
+        ditemid => $entry->ditemid,
+        subject => "subject",
+        body    => "comment body " . rand(),
+    );
+
+    my $comment = LJ::Comment->new( $entry->journal, dtalkid => $res->{dtalkid} );
+    ok( $comment->poster->equals( $u ), "Check comment poster when posting to a community" );
+    ok( $comment->journal->equals( $cu ), "Check comment journal when posting to a community" );
+}
+
+note( "adding a comment to another journal" );
+{
+    my $u1 = temp_user();
+    $u1->update_self({ status => "A" });
+    DW::Pay::add_paid_time( $u1, "paid", 2 );
+
+    my $u2 = temp_user();
+
+    my $entry = $u2->t_post_fake_entry;
+
+    ( $res, $err ) = $do_request->( "addcomment",
+        username => $u1->user,
+        journal => $u2->user,
+
+        ditemid => $entry->ditemid,
+        subject => "subject",
+        body    => "comment body " . rand(),
+    );
+
+    my $comment = LJ::Comment->new( $entry->journal, dtalkid => $res->{dtalkid} );
+    ok( $comment->poster->equals( $u1 ), "Check comment poster when posting to another journal" );
+    ok( $comment->journal->equals( $u2 ), "Check comment journal when posting to another journal" );
+}
+
--------------------------------------------------------------------------------