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

[dw-free] Warning in the logs for the interests search controller

[commit: http://hg.dwscoalition.org/dw-free/rev/0a1d6b8603a0]

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

Fix error when someone tries to add a new interest while not logged in. Fix
warnings when user has never updated, and when interest in ?mode=int is new.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/DW/Controller/Search/Interests.pm
--------------------------------------------------------------------------------
diff -r 58bccbfc98ff -r 0a1d6b8603a0 cgi-bin/DW/Controller/Search/Interests.pm
--- a/cgi-bin/DW/Controller/Search/Interests.pm	Tue Jan 25 17:53:41 2011 +0800
+++ b/cgi-bin/DW/Controller/Search/Interests.pm	Tue Jan 25 18:10:41 2011 +0800
@@ -48,7 +48,8 @@ sub interest_handler {
 
     # check whether authentication is needed or authas is allowed
     # default is to allow anonymous users, except for certain modes
-    my ( $anon, $authas ) = ( $mode eq "add" ? 0 : 1, 0 );
+    my $anon = ( $mode eq "add" || $mode eq "addnew" ) ? 0 : 1;
+    my $authas = 0;
     ( $anon, $authas ) = ( 0, 1 )
         if $mode eq ( $did_post ? "enmasse_do" : "enmasse" );
 
@@ -295,7 +296,9 @@ sub interest_handler {
         if ( LJ::is_enabled( 'interests-community' ) ) {
             my $us = $int_query->( "comminterests" );
             my $updated = LJ::get_timeupdate_multi( keys %$us );
-            my @cl = sort { $updated->{$b->id} <=> $updated->{$a->id} || $a->user cmp $b->user }
+            my $def_upd = sub { $updated->{$_[0]->userid} || 0 };
+            # let undefined values be zero for sorting purposes
+            my @cl = sort { $def_upd->($b) <=> $def_upd->($a) || $a->user cmp $b->user }
                      grep { $_ && $should_show->( $_ ) } values %$us;
             $rv->{int_comms} = { count => scalar @cl, data => [] };
             foreach ( @cl ) {
@@ -331,7 +334,7 @@ sub interest_handler {
 
         # check to see if the remote user already has the interest
         $rv->{not_interested} = ! $remote->interests->{$interest}
-            if $remote;
+            if $remote && defined $interest;
 
         return DW::Template->render_template( 'interests/int.tt', $rv );
     }
--------------------------------------------------------------------------------