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

[dw-free] provide user methods for check_rel usage

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

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

Refactor code that checks for posting access.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/User.pm
  • cgi-bin/weblib.pl
  • htdocs/poll/create.bml
--------------------------------------------------------------------------------
diff -r ecb4f977c4a1 -r 030adc21b5aa cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Mon Jun 28 18:07:33 2010 +0800
+++ b/cgi-bin/LJ/User.pm	Mon Jun 28 18:19:02 2010 +0800
@@ -3726,7 +3726,7 @@ sub can_manage_other {
 
 # can $u post to $targetu?
 sub can_post_to {
-    my ( $u, $targetu, %opts ) = @_;
+    my ( $u, $targetu ) = @_;
     croak "Invalid users passed to LJ::User->can_post_to."
         unless LJ::isu( $u ) && LJ::isu( $targetu );
 
@@ -3740,7 +3740,7 @@ sub can_post_to {
     return 1 if LJ::check_rel( $targetu, $u, 'P' );
 
     # let's check if this community is allowing post access to non-members
-    if ( $targetu->prop( 'nonmember_posting' ) ) {
+    if ( $targetu->has_open_posting ) {
         my ( $ml, $pl ) = LJ::get_comm_settings( $targetu );
         return 1 if $pl eq 'members';
     }
diff -r ecb4f977c4a1 -r 030adc21b5aa cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Mon Jun 28 18:07:33 2010 +0800
+++ b/cgi-bin/weblib.pl	Mon Jun 28 18:19:02 2010 +0800
@@ -2815,13 +2815,13 @@ sub control_strip
         } elsif ($journal->is_community) {
             my $watching = $remote->watches( $journal );
             my $memberof = $remote->member_of( $journal );
-            my $haspostingaccess = LJ::check_rel($journal, $remote, 'P');
+            my $haspostingaccess = $remote->can_post_to( $journal );
             my $isclosedcommunity = $journal->is_closed_membership;
+
             if ( $remote->can_manage_other( $journal ) ) {
                 $ret .= "$statustext{maintainer}<br />";
-                if ( $haspostingaccess || $journal->has_open_posting ) {
-                    $ret .= "$links{post_to_community}&nbsp;&nbsp; " unless $remote->is_identity;
-                }
+                $ret .= "$links{post_to_community}&nbsp;&nbsp; "
+                    if $haspostingaccess;
 
                 if ( $journal->prop( 'moderated' ) ) {
                     $ret .= "$links{queue} [" . LJ::get_mod_queue_count( $journal ) . "]&nbsp;&nbsp;";
@@ -2830,34 +2830,34 @@ sub control_strip
                 }
 
                 $ret .= "$links{edit_community_invites}&nbsp;&nbsp;$links{edit_community_members}";
+
             } elsif ($watching && $memberof) {
                 $ret .= "$statustext{memberwatcher}<br />";
-                if ($haspostingaccess) {
-                    $ret .= "$links{post_to_community}&nbsp;&nbsp; ";
-                }
+                $ret .= "$links{post_to_community}&nbsp;&nbsp; "
+                    if $haspostingaccess;
                 $ret .= $links{leave_community};
                 $ret .= "&nbsp;&nbsp;" . $links{track_community};
+
             } elsif ($watching) {
                 $ret .= "$statustext{watcher}<br />";
-                if ($haspostingaccess) {
-                    $ret .= "$links{post_to_community}&nbsp;&nbsp; ";
-                }
+                $ret .= "$links{post_to_community}&nbsp;&nbsp; "
+                    if $haspostingaccess;
                 $ret .= $isclosedcommunity ? "This is a closed community&nbsp;&nbsp; " :
                      "$links{join_community}&nbsp;&nbsp; ";
                 $ret .= $links{unwatch_community};
                 $ret .= "&nbsp;&nbsp;" . $links{track_community};
+
             } elsif ($memberof) {
                 $ret .= "$statustext{member}<br />";
-                if ($haspostingaccess) {
-                    $ret .= "$links{post_to_community}&nbsp;&nbsp; ";
-                }
+                $ret .= "$links{post_to_community}&nbsp;&nbsp; "
+                    if $haspostingaccess;
                 $ret .= "$links{watch_community}&nbsp;&nbsp; $links{'leave_community'}";
                 $ret .= "&nbsp;&nbsp;" . $links{track_community};
+
             } else {
                 $ret .= "$statustext{community}<br />";
-                if ( $haspostingaccess || $journal->has_open_posting ) {
-                    $ret .= "$links{post_to_community}&nbsp;&nbsp; ";
-                }
+                $ret .= "$links{post_to_community}&nbsp;&nbsp; "
+                    if $haspostingaccess;
                 $ret .= $isclosedcommunity ? "This is a closed community&nbsp;&nbsp; " :
                     "$links{join_community}&nbsp;&nbsp; ";
                 $ret .= $links{watch_community};
diff -r ecb4f977c4a1 -r 030adc21b5aa htdocs/poll/create.bml
--- a/htdocs/poll/create.bml	Mon Jun 28 18:07:33 2010 +0800
+++ b/htdocs/poll/create.bml	Mon Jun 28 18:19:02 2010 +0800
@@ -89,9 +89,7 @@ _c?>
     # If remote can't make polls, make sure they maintain the authas journal
     if ($remote_can_make_polls) {
         my $authas_u = LJ::load_user($authas);
-        if ($authas_u and ( $authas_u->equals( $remote ) or LJ::check_rel($authas_u, $remote, 'P'))) {
-            $u = $authas_u;
-        }
+        $u = $authas_u if $authas_u and $remote->can_post_to( $authas_u );
     } else {
         $u = LJ::get_authas_user($authas);
     }
--------------------------------------------------------------------------------