afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-07-11 11:41 am

[dw-free] Allow community maintainers to cancel community invites

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

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

Codemerge.

Patch from henrylyne@LiveJournal; prepared for Dreamwidth by denise.

Files modified:
  • cgi-bin/communitylib.pl
  • htdocs/community/sentinvites.bml
  • htdocs/community/sentinvites.bml.text
--------------------------------------------------------------------------------
diff -r e943df9d4340 -r f3ee87866768 cgi-bin/communitylib.pl
--- a/cgi-bin/communitylib.pl	Sat Jul 11 11:27:51 2009 +0000
+++ b/cgi-bin/communitylib.pl	Sat Jul 11 11:40:49 2009 +0000
@@ -240,6 +240,42 @@ sub get_pending_invites {
                                             undef, $u->{userid});
     return undef if $dbcr->err;
     return $pending;
+}
+
+# <LJFUNC>
+# name: LJ::revoke_invites
+# des: Revokes a list of outstanding invitations to a community.
+# args: cuserid, userids
+# des-cuserid: a userid or u object of the community.
+# des-ruserids: userids to revoke invitations from.
+# returns: 1 if success, undef if error
+# </LJFUNC>
+sub revoke_invites {
+    my $cu = shift;
+    my @uids = @_;
+    $cu = LJ::want_user($cu);
+    return undef unless ($cu && @uids);
+
+    foreach my $uid (@uids) {
+        return undef unless int($uid) > 0;
+    }
+    my $in = join(',', @uids);
+
+    return LJ::error('db') unless $cu->writer;
+    $cu->do("DELETE FROM invitesent WHERE commid = ? AND " .
+            "userid IN ($in)", undef, $cu->{userid});
+    return LJ::error('db') if $cu->err;
+
+    # remove from inviterecv also,
+    # otherwise invite cannot be resent for over 30 days
+    foreach my $uid (@uids) {
+        my $u =  LJ::want_user($uid);
+        $u->do("DELETE FROM inviterecv WHERE userid = ? AND " .
+               "commid = ?", undef, $uid, $cu->{userid});
+    }
+
+    # success
+    return 1;
 }
 
 # <LJFUNC>
diff -r e943df9d4340 -r f3ee87866768 htdocs/community/sentinvites.bml
--- a/htdocs/community/sentinvites.bml	Sat Jul 11 11:27:51 2009 +0000
+++ b/htdocs/community/sentinvites.bml	Sat Jul 11 11:40:49 2009 +0000
@@ -58,6 +58,23 @@ body<=
     }
 
     $ret .= LJ::maintainer_linkbar($c, "invites");
+
+    # Process revoked invitations
+    if ($POST{'action:revoke'}) {
+        # validate form auth
+        return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
+            unless LJ::check_form_auth();
+
+        my @userids;
+        foreach (grep { /^revoke_invite/ } keys %POST) {
+            push @userids, $POST{$_};
+        }
+        if (LJ::revoke_invites($c, @userids)) {
+            $ret .= "<div class='warningbar'> " .
+                    BML::ml('.invites.cancelled', { num => scalar @userids }) .
+                    "</div>";
+        }
+    }
 
     # columns of our table, excluding username
     my @attribs = ('post');
@@ -189,6 +206,10 @@ END
     $ret .= "<th><a href='${sortlink}status'>$ML{'.key.status'}</a></th>";
     $ret .= "</tr>\n";
 
+    $ret .= "<form method='post'>";
+    $ret .= LJ::form_auth();
+    my $can_revoke = 0;
+
     # checkboxes and such
     my $yes = '<img src="/img/check.gif" width="15" height="15" border="0">';
     my $no = '-';
@@ -205,11 +226,30 @@ END
         }
         $ret .= "<td>" . LJ::ljuser($_->{maintainer}, { type => 'P' }) . "</td>";
         $ret .= "<td>$_->{date}</td>";
-        $ret .= "<td>$_->{status}</td>";
+
+        # display checkbox for outstanding invites so they can be revoked
+        # also set flag indicating there are invitations that can be revoked
+        if ($_->{status} eq 'outstanding') {
+            $can_revoke = 1;
+            $ret .= "<td>$_->{status} " .
+                    LJ::html_check({ 'type' => 'checkbox',
+                                     'name' => 'revoke_invite_' . $_->{userid},
+                                     'value' => $_->{userid} }) .
+                    " </td>";
+        } else {
+            $ret .= "<td>$_->{status}</td>";
+        }
+
+
         $ret .= "</tr>\n";
     }
 
     $ret .= "</table>\n";
+    $ret .= "<p>" . LJ::html_submit( 'action:revoke', $ML{'.cancel'}) .  "</p>"
+        if $can_revoke;
+    $ret .= "</form>";
+
+
     $ret .= "<br /><a href='/community/members.bml?authas=$c->{user}'>$ML{'.send'}</a>";
     $ret .= "</div>\n\n";
     $ret .= $navbar;
diff -r e943df9d4340 -r f3ee87866768 htdocs/community/sentinvites.bml.text
--- a/htdocs/community/sentinvites.bml.text	Sat Jul 11 11:27:51 2009 +0000
+++ b/htdocs/community/sentinvites.bml.text	Sat Jul 11 11:40:49 2009 +0000
@@ -1,4 +1,7 @@
 ;; -*- coding: utf-8 -*-
+
+.cancel=Cancel Invitations
+
 .date=Date Sent
 
 .error.notcomm=[[user]] is not a community.
@@ -14,6 +17,8 @@
 .filterto.opts.outstanding=outstanding
 
 .filterto.opts.rejected=rejected
+
+.invites.cancelled=[[num]] [[?num|invitation|invitations]] cancelled.
 
 .key.date=Date
 
--------------------------------------------------------------------------------