[dw-free] add warning when buying paid time for a deleted account
[commit: http://hg.dwscoalition.org/dw-free/rev/e713bd994d2a]
http://bugs.dwscoalition.org/show_bug.cgi?id=1044
Shows a warning and asks you to submit again to confirm that you really want
to do this, if user is expunged/purged/suspended., and you're trying to buy
paid time for them. And bonus: remember the last form field values when
there's an error, because it's annoying to ask you to resubmit otherwise.
Patch by
fu.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1044
Shows a warning and asks you to submit again to confirm that you really want
to do this, if user is expunged/purged/suspended., and you're trying to buy
paid time for them. And bonus: remember the last form field values when
there's an error, because it's annoying to ask you to resubmit otherwise.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/en.dat
- cgi-bin/DW/Shop/Cart.pm
- cgi-bin/DW/Shop/Item/Account.pm
- cgi-bin/LJ/Widget/ShopItemOptions.pm
- htdocs/shop/account.bml
-------------------------------------------------------------------------------- diff -r 6d9638926000 -r e713bd994d2a bin/upgrading/en.dat --- a/bin/upgrading/en.dat Fri Dec 23 21:29:51 2011 +0800 +++ b/bin/upgrading/en.dat Fri Dec 23 23:14:19 2011 +0800 @@ -3542,6 +3542,8 @@ shop.item.account.canbeadded.noperms=There are no more seed accounts available for purchase at this time. +shop.item.account.canbeadded.notactive=[[user]] is not currently active. Submit your order again to confirm that you want to buy them paid time. + shop.item.account.conflicts.differentpaid=You cannot purchase two different types of paid accounts for the same person. shop.item.account.conflicts.multipleperms=You cannot purchase more than one seed account for the same person. diff -r 6d9638926000 -r e713bd994d2a cgi-bin/DW/Shop/Cart.pm --- a/cgi-bin/DW/Shop/Cart.pm Fri Dec 23 21:29:51 2011 +0800 +++ b/cgi-bin/DW/Shop/Cart.pm Fri Dec 23 23:14:19 2011 +0800 @@ -278,7 +278,7 @@ # make sure this item is allowed to be added my $error; - unless ( $item->can_be_added( errref => \$error ) ) { + unless ( $item->can_be_added( errref => \$error, user_confirmed => delete $item->{user_confirmed} ) ) { return ( 0, $error ); } diff -r 6d9638926000 -r e713bd994d2a cgi-bin/DW/Shop/Item/Account.pm --- a/cgi-bin/DW/Shop/Item/Account.pm Fri Dec 23 21:29:51 2011 +0800 +++ b/cgi-bin/DW/Shop/Item/Account.pm Fri Dec 23 23:14:19 2011 +0800 @@ -290,6 +290,12 @@ return 0; } + # check to make sure that the target user is valid: not deleted / suspended, etc + if ( ! $opts{user_confirmed} && LJ::isu( $target_u ) && $target_u->is_inactive ) { + $$errref = LJ::Lang::ml( 'shop.item.account.canbeadded.notactive', { user => $target_u->ljuser_display } ); + return 0; + } + # check to make sure the target user's current account type doesn't conflict with the item if ( LJ::isu( $target_u ) ) { my $account_type = DW::Pay::get_account_type( $target_u ); diff -r 6d9638926000 -r e713bd994d2a cgi-bin/LJ/Widget/ShopItemOptions.pm --- a/cgi-bin/LJ/Widget/ShopItemOptions.pm Fri Dec 23 21:29:51 2011 +0800 +++ b/cgi-bin/LJ/Widget/ShopItemOptions.pm Fri Dec 23 23:14:19 2011 +0800 @@ -69,6 +69,7 @@ name => $option_name, id => $full_item, value => $full_item, + selected => ($opts{post}->{$option_name} || "") eq $full_item, ) . " <label for='$full_item'>$price_string</label><br />"; } } @@ -154,7 +155,7 @@ # conflict or something if ( $post->{accttype} ) { my ( $rv, $err ) = $cart->add_item( - DW::Shop::Item::Account->new( type => $post->{accttype}, %item_data ) + DW::Shop::Item::Account->new( type => $post->{accttype}, user_confirmed => $post->{alreadyposted}, %item_data ) ); return ( error => $err ) unless $rv; } elsif ( $post->{item} eq "rename" ) { diff -r 6d9638926000 -r e713bd994d2a htdocs/shop/account.bml --- a/htdocs/shop/account.bml Fri Dec 23 21:29:51 2011 +0800 +++ b/htdocs/shop/account.bml Fri Dec 23 23:14:19 2011 +0800 @@ -67,17 +67,18 @@ $ret .= "<p>" . BML::ml( '.intro.new', { aopts => "href='$LJ::HELPURL{paidaccountinfo}'" } ) . "</p>"; } + my $post_fields = {}; if ( LJ::did_post() ) { return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>" unless LJ::check_form_auth(); my $error; - my $post_fields = LJ::Widget::ShopItemOptions->post_fields( \%POST ); + $post_fields = LJ::Widget::ShopItemOptions->post_fields( \%POST ); if ( keys %$post_fields ) { # make sure the user selected an account type # need to do this because all of these form fields are in the BML page instead of in the widget LJ::Widget->use_specific_form_fields( post => \%POST, widget => "ShopItemOptions", - fields => [ qw( for username email deliverydate_mm deliverydate_dd deliverydate_yyyy anonymous reason ) ] ); + fields => [ qw( for username email deliverydate_mm deliverydate_dd deliverydate_yyyy anonymous reason alreadyposted ) ] ); my %from_post = LJ::Widget->handle_post( \%POST, ( 'ShopItemOptions' ) ); $error = $from_post{error} if $from_post{error}; } else { @@ -95,14 +96,14 @@ $ret .= "<form method='post'>"; $ret .= LJ::form_auth(); $ret .= "<table summary='' class='shop-table'><tr>"; - $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'prem' ) . "</td>"; - $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'paid' ) . "</td>" + $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'prem', post => $post_fields ) . "</td>"; + $ret .= "<td>" . LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'paid', post => $post_fields ) . "</td>" if $for ne 'self' || DW::Shop::Item::Account->allow_account_conversion( $remote, 'paid' ); $ret .= "</tr>"; if ( DW::Pay::num_permanent_accounts_available() > 0 ) { $ret .= "<tr><td colspan='2'>"; - $ret .= LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'seed' ); + $ret .= LJ::Widget::ShopItemOptions->render( option_name => 'accttype', item => 'seed', post => $post_fields ); $ret .= "</td></tr>"; } @@ -112,7 +113,7 @@ $ret .= "<table summary='' class='shop-table-gift'>"; if ( $for eq 'gift' ) { - $ret .= "<tr><td>$ML{'.giftfor.username'}</td><td>" . LJ::html_text( { name => 'username', value => LJ::ehtml( $GET{user} ) } ) . "</td></tr>"; + $ret .= "<tr><td>$ML{'.giftfor.username'}</td><td>" . LJ::html_text( { name => 'username', value => LJ::ehtml( $POST{username} || $GET{user} ) } ) . "</td></tr>"; } elsif ( $for eq 'random' ) { if ( my $username = LJ::ehtml( $GET{user} ) ) { my $randomu = LJ::load_user( $username ); @@ -127,13 +128,16 @@ $ret .= LJ::html_hidden( username => '(random)' ); } } else { # $for eq 'new' - $ret .= "<tr><td>$ML{'.giftfor.email'}</td><td>" . LJ::html_text( { name => 'email' } ) . "</td></tr>"; + $ret .= "<tr><td>$ML{'.giftfor.email'}</td><td>" . LJ::html_text( { name => 'email', value => LJ::ehtml( $POST{email} ) } ) . "</td></tr>"; } $ret .= "<tr><td>$ML{'.giftfor.deliverydate'}</td>"; + my $deliverydate = $POST{deliverydate_mm} && $POST{deliverydate_dd} && $POST{deliverydate_yyyy} + ? "$POST{deliverydate_yyyy}-$POST{deliverydate_mm}-$POST{deliverydate_dd}" + : DateTime->today->date; $ret .= "<td>" . LJ::html_datetime( { name => 'deliverydate', - default => DateTime->today->date, + default => $deliverydate, notime => 1, } ) . "</td></tr>"; $ret .= "<tr><td>$ML{'.giftfor.anonymous'}</td>"; @@ -142,6 +146,7 @@ value => 1, selected => $remote ? 0 : 1, disabled => $remote ? 0 : 1, + selected => $POST{anonymous}, } ) . "</td></tr>"; if ( DW::Shop::Item::Account->can_have_reason ) { @@ -150,7 +155,8 @@ name => 'reason', rows => 6, cols => 60, - wrap => 'soft' + wrap => 'soft', + value => $POST{reason}, } ); $ret .= "</td></tr>"; } @@ -159,6 +165,7 @@ } $ret .= LJ::html_hidden( for => $GET{for} ); + $ret .= LJ::html_hidden( alreadyposted => 1 ) if LJ::did_post(); $ret .= "<p>" . LJ::html_submit( $ML{'.btn.addtocart'} ) . "</p>"; $ret .= "</form>"; --------------------------------------------------------------------------------