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-04-12 04:45 pm

[dw-free] approved members in moderated comms not members

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

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

Make joining/accepting invites work properly for moderated communities

Patch by [personal profile] janinedog.

Files modified:
  • bin/test/test-wtf
  • cgi-bin/DW/User/Edges/CommMembership.pm
  • cgi-bin/communitylib.pl
  • htdocs/community/members.bml
  • htdocs/tools/endpoints/changerelation.bml
--------------------------------------------------------------------------------
diff -r 93a83347871e -r 80b4818c9e5b bin/test/test-wtf
--- a/bin/test/test-wtf	Sun Apr 12 16:19:04 2009 +0000
+++ b/bin/test/test-wtf	Sun Apr 12 16:44:48 2009 +0000
@@ -486,7 +486,7 @@ push @tests, [ 'join community', sub
 push @tests, [ 'join community', sub
 {
     rst();
-    $u1->add_edge( $uc, member => 1 );
+    $u1->add_edge( $uc, member => {} );
     return ( scalar( $uc->member_userids ) == 1 ) ? 1 : 0;
 } ];
 
diff -r 93a83347871e -r 80b4818c9e5b cgi-bin/DW/User/Edges/CommMembership.pm
--- a/cgi-bin/DW/User/Edges/CommMembership.pm	Sun Apr 12 16:19:04 2009 +0000
+++ b/cgi-bin/DW/User/Edges/CommMembership.pm	Sun Apr 12 16:44:48 2009 +0000
@@ -23,8 +23,11 @@ DW::User::Edges::define_edge(
 DW::User::Edges::define_edge(
         member =>
             {
-                type => 'bool',
+                type => 'hashref',
                 db_edge => 'E',
+                options => {
+                    moderated_add => { required => 0, type => 'bool', default => 0 },
+                },
                 add_sub => \&_add_m_edge,
                 del_sub => \&_del_m_edge,
             }
@@ -37,11 +40,11 @@ sub _add_m_edge {
     # bail unless there is a membership edge; note that we have to remove
     # the edge, as per the Edges specification.  (if we don't, we will get
     # called over and over...)
-    delete $edges->{member}
+    my $member_edge = delete $edges->{member}
         or return;
 
     # error check adding an edge
-    return 0 unless $from_u->can_join( $to_u );
+    return 0 unless $from_u->can_join( $to_u, moderated_add => $member_edge->{moderated_add} ? 1 : 0 );
 
     # simply add the reluser edge
     LJ::set_rel( $to_u, $from_u, 'E' );
@@ -130,6 +133,7 @@ sub can_join {
     $tu = LJ::want_user( $tu );
 
     my $errref = $opts{errref};
+    my $moderated_add = $opts{moderated_add} ? 1 : 0;
 
     # if the user is a maintainer, skip every other check
     return 1 if $tu && $u->can_manage( $tu );
@@ -171,8 +175,8 @@ sub can_join {
             return 0;
         }
 
-        # the community must be open membership
-        unless ( $tu->is_open_membership ) {
+        # the community must be open membership or we must be adding to a moderated community
+        unless ( $tu->is_open_membership || $opts{moderated_add} ) {
             $$errref = LJ::Lang::ml( 'edges.join.error.targetnotopen' );
             return 0;
         }
diff -r 93a83347871e -r 80b4818c9e5b cgi-bin/communitylib.pl
--- a/cgi-bin/communitylib.pl	Sun Apr 12 16:19:04 2009 +0000
+++ b/cgi-bin/communitylib.pl	Sun Apr 12 16:44:48 2009 +0000
@@ -157,7 +157,7 @@ sub accept_comm_invite {
 
     # valid invite.  let's accept it as far as the community listing us goes.
     # 1, 0 means add comm to user's friends list, but don't auto-add P edge.
-    LJ::join_community($u, $cu, 1, 0) if $args->{member};
+    LJ::join_community( $u, $cu, 1, 0, moderated_add => 1 ) if $args->{member};
 
     # now grant necessary abilities
     my %edgelist = (
@@ -261,7 +261,7 @@ sub leave_community {
 
     # remove community membership
     return undef
-        unless $u->remove_edge( $cu, member => 1 );
+        unless $u->remove_edge( $cu, member => {} );
 
     # clear edges that effect this relationship
     foreach my $edge (qw(P N A M)) {
@@ -288,7 +288,7 @@ sub leave_community {
 #          comm, db error, etc)
 # </LJFUNC>
 sub join_community {
-    my ($uuid, $ucid, $watch, $canpost) = @_;
+    my ( $uuid, $ucid, $watch, $canpost, %opts ) = @_;
     my $u = LJ::want_user($uuid);
     my $cu = LJ::want_user($ucid);
     $watch = $watch ? 1 : 0;
@@ -296,7 +296,9 @@ sub join_community {
     return LJ::error('comm_not_comm') unless $cu->{journaltype} eq 'C';
 
     # try to join the community, and return if it didn't work
-    $u->add_edge( $cu, member => 1 );
+    $u->add_edge( $cu, member => {
+        moderated_add => $opts{moderated_add} ? 1 : 0,
+    } );
     return undef unless $u->member_of( $cu );
 
     # add edges that effect this relationship... if the user sent a fourth
@@ -405,7 +407,7 @@ sub approve_pending_member {
 
     # step 2, make user join the community
     # 1 means "add community to user's friends list"
-    return unless LJ::join_community($u->{userid}, $cu->{userid}, 1);
+    return unless LJ::join_community( $u, $cu, 1, undef, moderated_add => 1 );
 
     # step 3, email the user
     my %params = (event => 'CommunityJoinApprove', journal => $u);
diff -r 93a83347871e -r 80b4818c9e5b htdocs/community/members.bml
--- a/htdocs/community/members.bml	Sun Apr 12 16:19:04 2009 +0000
+++ b/htdocs/community/members.bml	Sun Apr 12 16:44:48 2009 +0000
@@ -239,7 +239,7 @@ body<=
         foreach my $uid ( keys %{ $delete{member} || {} } ) {
             my $temp_u = LJ::load_userid( $uid )
                 or next;
-            $temp_u->remove_edge( $cid, member => 1 );
+            $temp_u->remove_edge( $cid, member => {} );
         }
 
         # create a closure to send a notification email to a user if they are
diff -r 93a83347871e -r 80b4818c9e5b htdocs/tools/endpoints/changerelation.bml
--- a/htdocs/tools/endpoints/changerelation.bml	Sun Apr 12 16:19:04 2009 +0000
+++ b/htdocs/tools/endpoints/changerelation.bml	Sun Apr 12 16:44:48 2009 +0000
@@ -54,7 +54,7 @@
         if ( $can_join ) {
             $success = LJ::join_community( $remote, $targetu );
         } else {
-            if ( $error eq LJ::Lang::ml( 'edges.membership.error.targetnotopen' ) && $targetu->is_moderated_membership ) {
+            if ( $error eq LJ::Lang::ml( 'edges.join.error.targetnotopen' ) && $targetu->is_moderated_membership ) {
                 LJ::comm_join_request( $targetu, $remote );
                 $ret{note} = BML::ml( '/community/join.bml.reqsubmitted.body' );
             } else {
--------------------------------------------------------------------------------