[dw-free] Tie community to admin promo codes
[commit: http://hg.dwscoalition.org/dw-free/rev/4c1f8b40aa26]
http://bugs.dwscoalition.org/show_bug.cgi?id=1988
Add ability for a promo code to be tied to a community or user. If a
community, it suggests the community for you to join. If a user, it does
the normal 'suggest the user, and find what comms they're in to suggest
those too'.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1988
Add ability for a promo code to be tied to a community or user. If a
community, it suggests the community for you to join. If a user, it does
the normal 'suggest the user, and find what comms they're in to suggest
those too'.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- bin/upgrading/update-db-general.pl
- cgi-bin/LJ/User.pm
- cgi-bin/LJ/Widget/CreateAccount.pm
- cgi-bin/LJ/Widget/CreateAccountInviter.pm
-------------------------------------------------------------------------------- diff -r 63b5c594edb8 -r 4c1f8b40aa26 bin/upgrading/update-db-general.pl --- a/bin/upgrading/update-db-general.pl Wed Oct 28 14:46:07 2009 -0500 +++ b/bin/upgrading/update-db-general.pl Fri Oct 30 23:15:10 2009 +0000 @@ -2978,6 +2978,7 @@ CREATE TABLE acctcode_promo ( max_count int(10) unsigned not null default 0, current_count int(10) unsigned not null default 0, active enum('1','0') not null default 1, + suggest_journalid int unsigned, PRIMARY KEY ( code ) ) @@ -3829,6 +3830,10 @@ EOF q{ALTER TABLE clustertrack2 ADD COLUMN accountlevel SMALLINT UNSIGNED AFTER clusterid} ); } + unless ( column_type( 'acctcode_promo', 'suggest_journalid' ) ) { + do_alter( 'acctcode_promo', + q{ALTER TABLE acctcode_promo ADD COLUMN suggest_journalid INT UNSIGNED} ); + } }); diff -r 63b5c594edb8 -r 4c1f8b40aa26 cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Wed Oct 28 14:46:07 2009 -0500 +++ b/cgi-bin/LJ/User.pm Fri Oct 30 23:15:10 2009 +0000 @@ -217,7 +217,9 @@ sub create_personal { if ( $inviter ) { LJ::set_rel( $u, $inviter, 'I' ); LJ::statushistory_add( $u, $inviter, 'create_from_invite', "Created new account." ); - LJ::Event::InvitedFriendJoins->new( $inviter, $u )->fire; + if ( $inviter->is_individual ) { + LJ::Event::InvitedFriendJoins->new( $inviter, $u )->fire; + } } } # if we have initial friends for new accounts, add them. diff -r 63b5c594edb8 -r 4c1f8b40aa26 cgi-bin/LJ/Widget/CreateAccount.pm --- a/cgi-bin/LJ/Widget/CreateAccount.pm Wed Oct 28 14:46:07 2009 -0500 +++ b/cgi-bin/LJ/Widget/CreateAccount.pm Fri Oct 30 23:15:10 2009 +0000 @@ -390,6 +390,15 @@ sub handle_post { my $userid = $u ? $u->id : 0; if ( DW::InviteCodes->check_code( code => $code, userid => $userid ) ) { $from_post{code_valid} = 1; + + # and if this is a community promo code, set the inviter + if ( my $pc = DW::InviteCodes->get_promo_code_info( code => $code ) ) { + if ( $pc->{suggest_journalid} ) { + my $invu = LJ::load_userid( $pc->{suggest_journalid} ); + $post->{from} = $invu->user if $invu; + } + } + } else { my $r = DW::Request->get; my $args = $r->query_string; diff -r 63b5c594edb8 -r 4c1f8b40aa26 cgi-bin/LJ/Widget/CreateAccountInviter.pm --- a/cgi-bin/LJ/Widget/CreateAccountInviter.pm Wed Oct 28 14:46:07 2009 -0500 +++ b/cgi-bin/LJ/Widget/CreateAccountInviter.pm Fri Oct 30 23:15:10 2009 +0000 @@ -46,31 +46,42 @@ sub render_body { $ret .= $class->html_hidden( from => $inviter->user ); - if ( $u->can_trust( $inviter ) ) { - my $inviter_trust_name = 'inviter_trust_' . $inviter->id; - $ret .= $class->html_check( - name => $inviter_trust_name, - value => 1, - selected => defined $post->{$inviter_trust_name} ? $post->{$inviter_trust_name} : 1, - id => $inviter_trust_name, - ); - $ret .= " <label for='$inviter_trust_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.trust', { user => $inviter->ljuser_display } ) . "</label><br />"; + # if the invite code came from a comm (promo) then don't offer to watch/trust + if ( $inviter->is_individual ) { + if ( $u->can_trust( $inviter ) ) { + my $inviter_trust_name = 'inviter_trust_' . $inviter->id; + $ret .= $class->html_check( + name => $inviter_trust_name, + value => 1, + selected => defined $post->{$inviter_trust_name} ? $post->{$inviter_trust_name} : 1, + id => $inviter_trust_name, + ); + $ret .= " <label for='$inviter_trust_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.trust', { user => $inviter->ljuser_display } ) . "</label><br />"; + } + + if ( $u->can_watch( $inviter ) ) { + my $inviter_watch_name = 'inviter_watch_' . $inviter->id; + $ret .= $class->html_check( + name => $inviter_watch_name, + value => 1, + selected => defined $post->{$inviter_watch_name} ? $post->{$inviter_watch_name} : 1, + id => $inviter_watch_name, + ); + $ret .= " <label for='$inviter_watch_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.watch', { user => $inviter->ljuser_display } ) . "</label><br />"; + } } - if ( $u->can_watch( $inviter ) ) { - my $inviter_watch_name = 'inviter_watch_' . $inviter->id; - $ret .= $class->html_check( - name => $inviter_watch_name, - value => 1, - selected => defined $post->{$inviter_watch_name} ? $post->{$inviter_watch_name} : 1, - id => $inviter_watch_name, - ); - $ret .= " <label for='$inviter_watch_name'>" . $class->ml( 'widget.createaccountinviter.addinviter.watch', { user => $inviter->ljuser_display } ) . "</label><br />"; + my %comms; + if ( $inviter->is_individual ) { + %comms = $inviter->relevant_communities; + } elsif ( $inviter->is_community ) { + %comms = ( $inviter->id => { u => $inviter, istatus => 'normal' } ); } - my %comms = $inviter->relevant_communities; if ( keys %comms ) { $ret .= "<br />"; + + my ( $any_mm, $any_mod ); my $i = 0; foreach my $commid ( sort { $comms{$a}->{u}->display_username cmp $comms{$b}->{u}->display_username } keys %comms ) { @@ -79,13 +90,21 @@ sub render_body { my $commu = $comms{$commid}->{u}; my $note_mm = $comms{$commid}->{istatus} eq 'mm' ? ' *' : ''; + $any_mm ||= $note_mm; + my $note_moderated = $commu->is_moderated_membership ? ' **' : ''; # we will only get moderated or open communities + $any_mod ||= $note_moderated; + my $comm_join_name = "inviter_join_$commid"; + + # selected if they have a link in that says to join, OR if they were invited + # by a community (which is the only one in the list) + my $sel = ( defined $post->{$comm_join_name} ? $post->{$comm_join_name} : 0 ) || $inviter->is_community; $ret .= $class->html_check( name => $comm_join_name, value => 1, - selected => defined $post->{$comm_join_name} ? $post->{$comm_join_name} : 0, + selected => $sel, id => $comm_join_name, ); $ret .= " <label for='$comm_join_name'>"; @@ -95,10 +114,14 @@ sub render_body { $i++; } - $ret .= "<div style='margin: 10px;'>"; - $ret .= "<?de * " . $class->ml( 'widget.createaccountinviter.addcomms.note.mm', { user => $inviter->ljuser_display } ) . " de?>"; - $ret .= "<?de ** " . $class->ml( 'widget.createaccountinviter.addcomms.note.moderated' ) . " de?>"; - $ret .= "</div>"; + if ( $any_mm || $any_mod ) { + $ret .= "<div style='margin: 10px;'>"; + $ret .= "<?de * " . $class->ml( 'widget.createaccountinviter.addcomms.note.mm', { user => $inviter->ljuser_display } ) . " de?><br />" + if $any_mm; + $ret .= "<?de ** " . $class->ml( 'widget.createaccountinviter.addcomms.note.moderated' ) . " de?>" + if $any_mod; + $ret .= "</div>"; + } } return $ret; --------------------------------------------------------------------------------