mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-03-29 05:15 am

[dw-free] Fix calls to WTF methods on some pages

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

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

Update can_watch/can_trust with newly agreed upon logic. Also update
management pages to use these methods.

Patch by [personal profile] janinedog.

Files modified:
  • cgi-bin/DW/User/Edges/CommMembership.pm
  • cgi-bin/DW/User/Edges/WatchTrust.pm
  • htdocs/manage/circle/add.bml
  • htdocs/manage/circle/edit.bml
--------------------------------------------------------------------------------
diff -r bccae67619a0 -r b990942e2381 cgi-bin/DW/User/Edges/CommMembership.pm
--- a/cgi-bin/DW/User/Edges/CommMembership.pm	Sun Mar 29 05:04:47 2009 +0000
+++ b/cgi-bin/DW/User/Edges/CommMembership.pm	Sun Mar 29 05:15:46 2009 +0000
@@ -144,7 +144,7 @@ sub can_join {
     # if the user is a maintainer, skip every other check
     return 1 if $tu && $u->can_manage( $tu );
 
-    # a user must be a personal account
+    # the user must be a personal account
     return 0 unless $u->is_personal;
 
     # the user must be visible
diff -r bccae67619a0 -r b990942e2381 cgi-bin/DW/User/Edges/WatchTrust.pm
--- a/cgi-bin/DW/User/Edges/WatchTrust.pm	Sun Mar 29 05:04:47 2009 +0000
+++ b/cgi-bin/DW/User/Edges/WatchTrust.pm	Sun Mar 29 05:15:46 2009 +0000
@@ -951,13 +951,27 @@ sub can_trust {
     $u = LJ::want_user( $u ) or confess 'invalid user object';
     $tu = LJ::want_user( $tu );
 
-    # only individuals are allowed to trust eachother
-    return 0 if ! $u->is_individual || ( $tu && ! $tu->is_individual );
+    # the user must be an individual
+    return 0 unless $u->is_individual;
 
-    # both must be visible
-    return 0 if ! $u->is_visible || ( $tu && ! $tu->is_visible );
+    # the user must be visible
+    return 0 unless $u->is_visible;
 
-    # that was simple...
+    if ( $tu ) {
+        # the user cannot be the same as the target
+        return 0 if $u->equals( $tu );
+
+        # the target must be an individual
+        return 0 unless $tu->is_individual;
+
+        # the target must not be purged/suspended/locked
+        return 0 if $tu->is_expunged || $tu->is_suspended || $tu->is_locked;
+
+        # the target must not be banned by the user
+        return 0 if $u->has_banned( $tu );
+    }
+
+    # okay, good to go!
     return 1;
 }
 *LJ::User::can_trust = \&can_trust;
@@ -971,16 +985,18 @@ sub can_watch {
     $u = LJ::want_user( $u ) or confess 'invalid user object';
     $tu = LJ::want_user( $tu );
 
-    # only individuals are allowed to watch
+    # the user must be an individual
     return 0 unless $u->is_individual;
 
-    # both must be visible
-    return 0 if ! $u->is_visible || ( $tu && ! $tu->is_visible );
+    # the user must be visible
+    return 0 unless $u->is_visible;
 
-    # and you're not allowed to watch identity accounts (they can't post)
-    return 0 if $tu && $tu->is_identity;
+    if ( $tu ) {
+        # the target must not be purged/suspended/locked
+        return 0 if $tu->is_expunged || $tu->is_suspended || $tu->is_locked;
+    }
 
-    # that was kinda simple...
+    # okay, good to go!
     return 1;
 }
 *LJ::User::can_watch = \&can_watch;
diff -r bccae67619a0 -r b990942e2381 htdocs/manage/circle/add.bml
--- a/htdocs/manage/circle/add.bml	Sun Mar 29 05:04:47 2009 +0000
+++ b/htdocs/manage/circle/add.bml	Sun Mar 29 05:15:46 2009 +0000
@@ -174,7 +174,7 @@
    # users that aren't visible can only be removed, not modified
    if ($u->is_visible) {
 
-    if ( !$u->equals( $remote ) && $remote->is_personal && ( $u->is_personal || $u->is_identity ) ) {
+    if ( $remote->can_trust( $u ) ) {
         $body .= LJ::html_check({
             name => "add_trust",
             id => "add_trust",
@@ -183,19 +183,21 @@
         }) . "<br />";
     }
 
-    $body .= LJ::html_check({
-        name => "add_watch",
-        id => "add_watch",
-        selected => $watched || $action eq 'subscribe' ? 1 : 0,
-        label => $ML{'.add.watch'},
-    });
+    if ( $remote->can_watch( $u ) ) {
+        $body .= LJ::html_check({
+            name => "add_watch",
+            id => "add_watch",
+            selected => $watched || $action eq 'subscribe' ? 1 : 0,
+            label => $ML{'.add.watch'},
+        });
+    }
 
     ## let them pick friend groups
     # FIXME: Add support for reading groups once those exist
     my $err;
     my $trust_groups = $remote->trust_groups;
 
-    if ( !$u->equals( $remote ) && ( $u->is_personal || $u->is_identity ) && keys %$trust_groups ) {
+    if ( $remote->can_trust( $u ) && keys %$trust_groups ) {
         $body .= "<?p &nbsp;<br />";
         $body .= "$ML{'.groups.text1'} " . LJ::help_icon('customgroups', '&nbsp;') . "p?>\n";
         $body .= "<blockquote>\n";
diff -r bccae67619a0 -r b990942e2381 htdocs/manage/circle/edit.bml
--- a/htdocs/manage/circle/edit.bml	Sun Mar 29 05:04:47 2009 +0000
+++ b/htdocs/manage/circle/edit.bml	Sun Mar 29 05:15:46 2009 +0000
@@ -59,7 +59,7 @@ body<=
             $ret .= "<p>$ML{'.circle.intro.people'}</p>";
             $ret .= "<div align='center'><table class='editfriends'>";
             $ret .= "<tr class='header'><th>$ML{'.circle.username'}</th><th>$ML{'.circle.name'}</th><th>$ML{'.circle.trusted_by'}</th><th>$ML{'.circle.watched_by'}</th>";
-            $ret .= "<th>$ML{'.circle.trust'}</th>" if $u->is_personal;
+            $ret .= "<th>$ML{'.circle.trust'}</th>";
             $ret .= "<th>$ML{'.circle.watch'}</th></tr>";
             foreach my $uid ( sort { $us->{$a}->display_name cmp $us->{$b}->display_name } keys %$us ) {
                 my $other_u = $us->{$uid};
@@ -76,10 +76,7 @@ body<=
                     $u_bg = $watch_list->{$uid}->{bgcolor};
                 }
 
-                if ( $u->equals( $other_u ) || $other_u->is_identity ) {
-                    $t_bg = "transparent";
-                    $t_text = $ML{'.circle.na'};
-                } else {
+                if ( $other_u->can_trust( $u ) ) {
                     if ( $is_trusted_by_userid{$uid} ) {
                         $t_bg = "#00ff00";
                         $t_text = "Y";
@@ -87,13 +84,22 @@ body<=
                         $t_bg = "#ff0000";
                         $t_text = "N";
                     }
+                } else {
+                    $t_bg = "transparent";
+                    $t_text = $ML{'.circle.na'};
                 }
-                if ( $is_watched_by_userid{$uid} ) {
-                    $w_bg = "#00ff00";
-                    $w_text = "Y";
+
+                if ( $other_u->can_watch( $u ) ) {
+                    if ( $is_watched_by_userid{$uid} ) {
+                        $w_bg = "#00ff00";
+                        $w_text = "Y";
+                    } else {
+                        $w_bg = "#ff0000";
+                        $w_text = "N";
+                    }
                 } else {
-                    $w_bg = "#ff0000";
-                    $w_text = "N";
+                    $w_bg = "transparent";
+                    $w_text = $ML{'.circle.na'};
                 }
 
                 $ret .= "<tr>";
@@ -101,22 +107,27 @@ body<=
                 $ret .= "<td style='color: $u_fg; background-color: $u_bg;'>" . $other_u->name_html . "</td>";
                 $ret .= "<td style='background-color: $t_bg;'>$t_text</td>";
                 $ret .= "<td style='background-color: $w_bg;'>$w_text</td>";
-                if ( $u->is_personal ) {
-                    if ( $u->equals( $other_u ) ) {
-                        $ret .= "<td>$ML{'.circle.na'}</td>";
-                    } else {
-                        $ret .= "<td>" . LJ::html_check({
-                            name => "editfriend_edit_${uid}_trust",
-                            value => 1,
-                            selected => $is_trusted_userid{$uid} ? 1 : 0,
-                        }) . "</td>";
-                    }
+
+                if ( $u->can_trust( $other_u ) || $is_trusted_userid{$uid} ) {
+                    $ret .= "<td>" . LJ::html_check({
+                        name => "editfriend_edit_${uid}_trust",
+                        value => 1,
+                        selected => $is_trusted_userid{$uid} ? 1 : 0,
+                    }) . "</td>";
+                } else {
+                    $ret .= "<td>$ML{'.circle.na'}</td>";
                 }
-                $ret .= "<td>" . LJ::html_check({
-                    name => "editfriend_edit_${uid}_watch",
-                    value => 1,
-                    selected => $watch_list->{$uid} ? 1 : 0,
-                }) . "</td>";
+
+                if ( $u->can_watch( $other_u ) || $watch_list->{$uid} ) {
+                    $ret .= "<td>" . LJ::html_check({
+                        name => "editfriend_edit_${uid}_watch",
+                        value => 1,
+                        selected => $watch_list->{$uid} ? 1 : 0,
+                    }) . "</td>";
+                } else {
+                    $ret .= "<td>$ML{'.circle.na'}</td>";
+                }
+
                 $ret .= "</tr>";
                 $ret .= LJ::html_hidden( "editfriend_edit_${uid}_user" => 1 );
             }
@@ -141,11 +152,17 @@ body<=
                 $ret .= "<tr>";
                 $ret .= "<td>" . $other_u->ljuser_display . "</td>";
                 $ret .= "<td style='color: $u_fg; background-color: $u_bg;'>" . $other_u->name_html . "</td>";
-                $ret .= "<td>" . LJ::html_check({
-                    name => "editfriend_edit_${uid}_watch",
-                    value => 1,
-                    selected => $watch_list->{$uid} ? 1 : 0,
-                }) . "</td>";
+
+                if ( $u->can_watch( $other_u ) ) {
+                    $ret .= "<td>" . LJ::html_check({
+                        name => "editfriend_edit_${uid}_watch",
+                        value => 1,
+                        selected => $watch_list->{$uid} ? 1 : 0,
+                    }) . "</td>";
+                } else {
+                    $ret .= "<td>$ML{'.circle.na'}</td>";
+                }
+
                 $ret .= "</tr>";
                 $ret .= LJ::html_hidden( "editfriend_edit_${uid}_user" => 1 );
             }
@@ -159,37 +176,41 @@ body<=
         $ret .= "<br />";
         $ret .= "<div align='center'><table id='addfriends'>\n";
         $ret .= "<tr><th>$ML{'.circle.username'}</th>";
-        $ret .= "<th>$ML{'.circle.trust'}</th>" if $u->is_personal;
+        $ret .= "<th>$ML{'.circle.trust'}</th>";
         $ret .= "<th>$ML{'.circle.watch'}</th><th>$ML{'.foreground'}</th><th>$ML{'.background'}</th>\n";
 
-        # load the colors
         my @color = ();
-        LJ::load_codes({ "color" => \@color });
+        if ( $u->can_watch ) {
+            # load the colors
+            LJ::load_codes({ "color" => \@color });
 
-        $ret .= "<td rowspan='11' valign='middle'>";
+            $ret .= "<td rowspan='11' valign='middle'>";
 
-        ### color swatch
-        $ret .= "<table border='0' cellspacing='0' cellpadding='0' align='center' width='100'>\n";
-        $ret .= "<tr><td colspan='5'><p align='center'><small>$ML{'.hover'}</small></p></td></tr>\n";
-        my $col = 0;
-        foreach (@color) {
-            $col = $col % 5;
-            $ret .= "<tr>\n" if $col == 0;
+            ### color swatch
+            $ret .= "<table border='0' cellspacing='0' cellpadding='0' align='center' width='100'>\n";
+            $ret .= "<tr><td colspan='5'><p align='center'><small>$ML{'.hover'}</small></p></td></tr>\n";
+            my $col = 0;
+            foreach (@color) {
+                $col = $col % 5;
+                $ret .= "<tr>\n" if $col == 0;
 
-            my $ecolor = LJ::ehtml($_->{'item'});
-            $ret .= "<td style='background-color: $_->{code};'><img src='/img/dot.gif' width='14' height='14' title='$ecolor' alt='$ecolor' /></td>\n";
+                my $ecolor = LJ::ehtml($_->{'item'});
+                $ret .= "<td style='background-color: $_->{code};'><img src='/img/dot.gif' width='14' height='14' title='$ecolor' alt='$ecolor' /></td>\n";
 
-            $col++;
-            $ret .= "</tr>\n" if $col == 5;
+                $col++;
+                $ret .= "</tr>\n" if $col == 5;
+            }
+
+            $ret .= "</tr>\n" if ($col % 5); # close out row if we don't have a full row
+            $ret .= "</table>";
+
+            $ret .= "<p align='center'><input type='button' value='" . LJ::ehtml($ML{'.btn.toggle'}) . "' ";
+            $ret .= "onClick='togglePreview(); return true;'></p>\n";
+
+            $ret .= "</td>";
         }
 
-        $ret .= "</tr>\n" if ($col % 5); # close out row if we don't have a full row
-        $ret .= "</table>";
-
-        $ret .= "<p align='center'><input type='button' value='" . LJ::ehtml($ML{'.btn.toggle'}) . "' ";
-        $ret .= "onClick='togglePreview(); return true;'></p>\n";
-
-        $ret .= "</td></tr>";
+        $ret .= "</tr>";
 
         foreach my $i (1..10) {
             $ret .= "<tr><td>";
@@ -198,31 +219,42 @@ body<=
                                     'onchange' => "updatePreview(); return true;",
                                     'onfocus' => "setFriend($i);" });
             $ret .= "</td>";
-            if ( $u->is_personal ) {
+
+            if ( $u->can_trust ) {
                 $ret .= "<td style='text-align: center;'>";
                 $ret .= LJ::html_check({ name => "editfriend_add_${i}_trust",
                                          value => 1,
                                          onfocus => "setFriend($i);" });
                 $ret .= "</td>";
+            } else {
+                $ret .= "<td>$ML{'.circle.na'}</td>";
             }
-            $ret .= "<td style='text-align: center;'>";
-            $ret .= LJ::html_check({ name => "editfriend_add_${i}_watch",
-                                     value => 1,
-                                     onfocus => "setFriend($i);" });
-            $ret .= "</td><td>";
-            $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_fg",
-                                      'selected' => '#000000',
-                                      'onchange' => "updatePreview(); return true;",
-                                      'onfocus' => "setFriend($i);" },
-                                      map { lc($_->{'code'}), $_->{'item'} } @color );
-            $ret .= "</td><td>";
-            $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_bg",
-                                      'selected' => '#ffffff',
-                                      'onchange' => "updatePreview(); return true;",
-                                      'onfocus' => "setFriend($i);" },
-                                      map { lc($_->{'code'}), $_->{'item'} } @color );
 
-            $ret .= "</td></tr>\n";
+            if ( $u->can_watch ) {
+                $ret .= "<td style='text-align: center;'>";
+                $ret .= LJ::html_check({ name => "editfriend_add_${i}_watch",
+                                         value => 1,
+                                         onfocus => "setFriend($i);" });
+                $ret .= "</td><td>";
+                $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_fg",
+                                          'selected' => '#000000',
+                                          'onchange' => "updatePreview(); return true;",
+                                          'onfocus' => "setFriend($i);" },
+                                          map { lc($_->{'code'}), $_->{'item'} } @color );
+                $ret .= "</td><td>";
+                $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_bg",
+                                          'selected' => '#ffffff',
+                                          'onchange' => "updatePreview(); return true;",
+                                          'onfocus' => "setFriend($i);" },
+                                          map { lc($_->{'code'}), $_->{'item'} } @color );
+                $ret .= "</td>";
+            } else {
+                $ret .= "<td>$ML{'.circle.na'}</td>";
+                $ret .= "<td>$ML{'.circle.na'}</td>";
+                $ret .= "<td>$ML{'.circle.na'}</td>";
+            }
+
+            $ret .= "</tr>\n";
         }
         $ret .= "</table></div><br />";
 
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org