kareila: (Default)
kareila ([personal profile] kareila) wrote in [site community profile] changelog2009-07-31 04:47 am

[dw-free] Community Management widget for the front page

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

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

Enables new community management module and new get_pending_members_count
function.

Patch by [personal profile] afuna.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/DW/Panel.pm
  • cgi-bin/DW/Widget/CommunityManagement.pm
  • cgi-bin/communitylib.pl
  • doc/raw/memcache-keys.txt
  • htdocs/stc/widgets/communitymanagement.css
--------------------------------------------------------------------------------
diff -r 059355222c2f -r bd3f259831cb bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Thu Jul 30 18:37:07 2009 +0000
+++ b/bin/upgrading/en.dat	Thu Jul 30 23:46:56 2009 -0500
@@ -3915,6 +3915,18 @@ widget.commsofuser.viewfriendspage=View 
 
 widget.commsofuser.viewprofile=View [[user]]'s profile
 
+widget.communitymanagement.nopending=No communities require action.
+
+widget.communitymanagement.pending=Pending:
+
+widget.communitymanagement.pending.entry=[[num]] [[?num|entry|entries]]
+
+widget.communitymanagement.pending.header=The following communities require action:
+
+widget.communitymanagement.pending.member=[[num]] [[?num|member|members]]
+
+widget.communitymanagement.title=Community Management
+
 widget.createaccount.alt_layout.error.tos=You must agree to the Terms of Service.
 
 widget.createaccount.alt_layout.field.captcha=Enter the text below to help verify the authenticity of this account:
diff -r 059355222c2f -r bd3f259831cb cgi-bin/DW/Panel.pm
--- a/cgi-bin/DW/Panel.pm	Thu Jul 30 18:37:07 2009 +0000
+++ b/cgi-bin/DW/Panel.pm	Thu Jul 30 23:46:56 2009 -0500
@@ -64,7 +64,7 @@ sub init {
         "DW::Widget::AccountStatistics",
         "LJ::Widget::SiteMessages",
         "DW::Widget::UserTagCloud",
-        # "DW::Widget::CommunityManagement",
+        "DW::Widget::CommunityManagement",
         "LJ::Widget::CurrentTheme",
     ];
 
diff -r 059355222c2f -r bd3f259831cb cgi-bin/DW/Widget/CommunityManagement.pm
--- a/cgi-bin/DW/Widget/CommunityManagement.pm	Thu Jul 30 18:37:07 2009 +0000
+++ b/cgi-bin/DW/Widget/CommunityManagement.pm	Thu Jul 30 23:46:56 2009 -0500
@@ -21,17 +21,69 @@ use base qw/ LJ::Widget /;
 
 sub should_render { 1; }
 
-# requires attention are: 
-# * has pending join requests
-# * has pending entries in the queue
+sub need_res { qw( stc/widgets/communitymanagement.css ) }
+
 sub render_body {
     my ( $class, %opts ) = @_;
 
     my $remote = LJ::get_remote()
         or return;
 
-    # TODO: everything!
-    my $ret = "";
+    my $ret = "<h2>" . $class->ml( 'widget.communitymanagement.title' ) . "</h2>";
+
+    my %show;
+
+    # keep track of what communities remote maintains
+    my $cids = LJ::load_rel_target_cache( $remote, 'A' );
+    my %admin;
+    if ( $cids ) { 
+        $admin{$_} = $show{$_} = 1 foreach @$cids;
+    }
+
+    # keep track of what communities remote moderates
+    my $mids = LJ::load_rel_target_cache( $remote, 'M' );
+    my %mods; 
+    if ( $mids ) {  
+        $mods{$_} = $show{$_} = 1 foreach @$mids;
+    }
+
+    my $list;
+    if ( %show ) {
+        my $us = LJ::load_userids( keys %show );
+
+        foreach my $cu ( sort { $a->user cmp $b->user }  values %$us ) {
+            next unless $cu->is_visible;
+
+            my ( $membership, $postlevel ) = LJ::get_comm_settings( $cu );
+
+            my $pending_entries_count;
+            $pending_entries_count = LJ::get_mod_queue_count( $cu )
+                if $mods{$cu->userid};
+
+            my $pending_members_count;
+            $pending_members_count = LJ::get_pending_members_count( $cu )
+                if $membership eq "moderated" && $admin{$cu->userid};
+            if ( $pending_members_count || $pending_entries_count ) {
+                $list .= "<dt>" . $cu->ljuser_display;
+                $list .= "<dd>" . $class->ml( 'widget.communitymanagement.pending' );
+
+                $list .= " [<a href='$LJ::SITEROOT/community/moderate.bml?authas=" . $cu->username . "'>" . $class->ml( 'widget.communitymanagement.pending.entry', { num => $pending_entries_count } ) . "</a>]"
+                    if $pending_entries_count;
+
+                $list .= " [<a href='$LJ::SITEROOT/community/pending.bml?authas=" . $cu->username . "'>" . $class->ml( 'widget.communitymanagement.pending.member', { num =>  $pending_members_count } ) . "</a>]"
+                    if $pending_members_count;
+
+                $list .= "</dd>";
+            }
+        }
+    }
+
+    if ( $list ) {
+        $ret .= "<p>" . $class->ml( 'widget.communitymanagement.pending.header' ) . "</p>";
+        $ret .= "<dl>$list</dl>";
+    } else {
+        $ret .= "<p>" . $class->ml( 'widget.communitymanagement.nopending' ) . "</p>";
+    }
     return $ret;
 }
 
diff -r 059355222c2f -r bd3f259831cb cgi-bin/communitylib.pl
--- a/cgi-bin/communitylib.pl	Thu Jul 30 18:37:07 2009 +0000
+++ b/cgi-bin/communitylib.pl	Thu Jul 30 23:46:56 2009 -0500
@@ -420,6 +420,7 @@ sub get_pending_members {
     foreach (@$args) {
         push @list, $1+0 if $_ =~ /^targetid=(\d+)$/;
     }
+
     return \@list;
 }
 
@@ -456,6 +457,8 @@ sub approve_pending_member {
     }
     LJ::Event::CommunityJoinApprove->new($u, $cu)->fire if LJ::is_enabled('esn');
 
+    $cu->memc_delete( "pendingmemct" );
+
     return 1;
 }
 
@@ -486,6 +489,8 @@ sub reject_pending_member {
         $u->subscribe(%params, method => 'Email');
     }
     LJ::Event::CommunityJoinReject->new($u, $cu)->fire if LJ::is_enabled('esn');
+
+    $cu->memc_delete( "pendingmemct" );
 
     return 1;
 }
@@ -549,6 +554,8 @@ sub comm_join_request {
 
         LJ::Event::CommunityJoinRequest->new($au, $u, $comm)->fire;
     }
+
+    $comm->memc_delete( 'pendingmemct' );
 
     return $aa;
 }
@@ -655,5 +662,20 @@ sub get_mod_queue_count {
     return $mqcount;
 }
 
+sub get_pending_members_count {
+    my $cu = LJ::want_user( shift );
+    return 0 unless $cu->is_community;
+
+    my $pending_count = $cu->memc_get( 'pendingmemct' );
+    return $pending_count if defined $pending_count;
+
+    # seems to be doing some additional parsing, which would make this
+    # number potentially incorrect if you just do SELECT COUNT
+    # so grab the parsed list and count it
+    $pending_count = scalar @{ LJ::get_pending_members( $cu ) };
+    $cu->memc_set( 'pendingmemct' => $pending_count, 600 );
+
+    return $pending_count;
+}
 
 1;
diff -r 059355222c2f -r bd3f259831cb doc/raw/memcache-keys.txt
--- a/doc/raw/memcache-keys.txt	Thu Jul 30 18:37:07 2009 +0000
+++ b/doc/raw/memcache-keys.txt	Thu Jul 30 23:46:56 2009 -0500
@@ -133,6 +133,7 @@ jabclusterid:<id> == address of server
 <uid> timezone_guess:<uid> == guess of the user's timezone offset based on time of their most recent entry
 
 <uid> commsettings:<cid> == [membership, postlevel] - Membership and Posting Access for a community
+<uid> pendingmemct:<cid> == number of pending membership requests
 
 <uid> synd:<uid> == hash of basic syndication info
 
diff -r 059355222c2f -r bd3f259831cb htdocs/stc/widgets/communitymanagement.css
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/stc/widgets/communitymanagement.css	Thu Jul 30 23:46:56 2009 -0500
@@ -0,0 +1,3 @@
+.appwidget-communitymanagement dd {
+    margin-left: 2em;
+}
--------------------------------------------------------------------------------