Refactor out the check for can_moderate; also, community administrators 
are automatically moderators.

        Patch by kareila. 

diffs (66 lines):

diff -r b8e59833de2e -r 7dac7303e79d cgi-bin/DW/User/ContentFilters/Filter.pm
--- a/cgi-bin/DW/User/ContentFilters/Filter.pm  Tue Jun 29 18:27:35 2010 +0800
+++ b/cgi-bin/DW/User/ContentFilters/Filter.pm  Tue Jun 29 22:31:49 2010 +0800
@@ -240,7 +240,7 @@ sub show_entry {
     # step 1) community poster type
     if ( $journalu->is_community && $opts->{postertype} && $opts->{postertype} 
ne 'any' ) {
         my $is_admin = $posteru->can_manage_other( $journalu );
-        my $is_moderator = $is_admin || LJ::check_rel( $journalu, $posteru, 
'M' );
+        my $is_moderator = $posteru->can_moderate( $journalu );
 
         return $fail->( 'not_maintainer' )
             if $opts->{postertype} eq 'maintainer' && ! $is_admin;
diff -r b8e59833de2e -r 7dac7303e79d cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Tue Jun 29 18:27:35 2010 +0800
+++ b/cgi-bin/LJ/S2.pm  Tue Jun 29 22:31:49 2010 +0800
@@ -2667,7 +2667,7 @@ sub viewer_is_moderator {
 
     my $ju = $LJ::S2::CURR_PAGE->{_u};
     return 0 unless $ju->is_community;
-    return LJ::check_rel( $ju, $remote, 'M' );
+    return $remote->can_moderate( $ju );
 }
 
 sub viewer_can_manage_tags
diff -r b8e59833de2e -r 7dac7303e79d cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Tue Jun 29 18:27:35 2010 +0800
+++ b/cgi-bin/LJ/User.pm        Tue Jun 29 22:31:49 2010 +0800
@@ -3724,6 +3724,17 @@ sub can_manage_other {
 }
 
 
+sub can_moderate {
+    # true if the first user can moderate the target user.
+    my ( $u, $target ) = @_;
+    # backward compatibility: allow $target to be a userid
+    $target = LJ::want_user( $target ) or return undef;
+
+    return 1 if $u->can_manage_other( $target );
+    return LJ::check_rel( $target, $u, 'M' );
+}
+
+
 # can $u post to $targetu?
 sub can_post_to {
     my ( $u, $targetu ) = @_;
diff -r b8e59833de2e -r 7dac7303e79d htdocs/community/moderate.bml
--- a/htdocs/community/moderate.bml     Tue Jun 29 18:27:35 2010 +0800
+++ b/htdocs/community/moderate.bml     Tue Jun 29 22:31:49 2010 +0800
@@ -59,7 +59,7 @@ body<=
         }
         my $dbcm = LJ::get_cluster_master($c);
 
-        unless (LJ::check_rel($c, $remote, 'M')) {
+        unless ( $remote->can_moderate( $c ) ) {
             $ret .= "<?h1 $ML{'Error'} h1?><?p " .
                 BML::ml('.error.noaccess', {'comm'=>"<?ljcomm $c->{'user'} 
ljcomm?>"}) . " p?>";
             return $ret;
@@ -216,7 +216,7 @@ body<=
 
     my $dbcr = LJ::get_cluster_def_reader($c);
 
-    unless ( LJ::check_rel( $c, $remote, 'M' ) ) {
+    unless ( $remote->can_moderate( $c ) ) {
         $ret .= "<?h1 $ML{'Error'} h1?>";
         if ( $c->has_moderated_posting ) {
             $ret .= "<?p " . BML::ml( '.error.noaccess', { comm => 
$c->ljuser_display } ) . " p?>";
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to