[dw-free] Add admin console options for adding paid time and revoking it, as well as some statushist
[commit: http://hg.dwscoalition.org/dw-free/rev/b57c962b1dbe]
Add admin console options for adding paid time and revoking it, as well as
some statushistory logging thereof.
Patch by
mark.
Files modified:
Add admin console options for adding paid time and revoking it, as well as
some statushistory logging thereof.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/DW/Pay.pm
- htdocs/admin/pay/index.bml
-------------------------------------------------------------------------------- diff -r fbab4cbda526 -r b57c962b1dbe cgi-bin/DW/Pay.pm --- a/cgi-bin/DW/Pay.pm Fri May 01 14:43:55 2009 +0000 +++ b/cgi-bin/DW/Pay.pm Sat May 02 00:01:08 2009 +0000 @@ -263,17 +263,21 @@ sub expire_user { sub expire_user { DW::Pay::clear_error(); - my $u = LJ::want_user( shift() ) + my ( $u, %opts ) = @_; + $u = LJ::want_user( $u ) or return error( ERR_FATAL, "Invalid/not a user object." ); - my $ps = DW::Pay::get_paid_status( $u ); - return 1 unless $ps; # free already - return error( ERR_FATAL, "Cannot expire a permanent account." ) - if $ps->{permanent}; - return error( ERR_FATAL, "Account not ready for expiration." ) - if $ps->{expiresin} > 0; + unless ( $opts{force} ) { + my $ps = DW::Pay::get_paid_status( $u ); + return 1 unless $ps; # free already + return error( ERR_FATAL, "Cannot expire a permanent account." ) + if $ps->{permanent}; + return error( ERR_FATAL, "Account not ready for expiration." ) + if $ps->{expiresin} > 0; + } # so we have to update their status now + LJ::statushistory_add( $u, undef, 'paidstatus', 'Expiring account; forced=' . ( $opts{force} ? 1 : 0 ) . '.' ); DW::Pay::update_paid_status( $u, _expire => 1 ); DW::Pay::sync_caps( $u ); diff -r fbab4cbda526 -r b57c962b1dbe htdocs/admin/pay/index.bml --- a/htdocs/admin/pay/index.bml Fri May 01 14:43:55 2009 +0000 +++ b/htdocs/admin/pay/index.bml Sat May 02 00:01:08 2009 +0000 @@ -16,6 +16,40 @@ unless LJ::check_priv($remote, 'payments'); my $body = '<h1>Payment Manager</h1>'; + + if ( LJ::did_post() ) { + return "failed auth" + unless LJ::check_form_auth(); + + if ( $POST{givetime} ) { + my ( $who, $type, $months ) = ( $POST{user}, $POST{type}, $POST{months} ); + my $u = LJ::load_user( $who ) + or return "invalid user"; + return "invalid type" + unless $type =~ /^(?:seed|premium|paid|expire)$/; + $months = 99 if $type eq 'seed'; + + if ( $type eq 'expire' ) { + my $rv = DW::Pay::expire_user( $u, force => 1 ); + if ( $rv ) { + LJ::statushistory_add( $u, $remote, 'paidstatus', + "Admin override: expired account." ); + return BML::redirect( "$LJ::SITEROOT/admin/pay/index?view=$u->{user}" ); + } + + } else { + my $rv = DW::Pay::add_paid_time( $u, $type, $months ); + if ( $rv ) { + LJ::statushistory_add( $u, $remote, 'paidstatus', + "Admin override: gave paid time to user: months=$months type=$type" ); + return BML::redirect( "$LJ::SITEROOT/admin/pay/index?view=$u->{user}" ); + } + } + return "Error: " . DW::Pay::error_text() . "\n"; + } + + return "invalid option"; + } if ($GET{view}) { $body .= '<p>[ <a href="/admin/pay/index.bml"><< Back to Index</a> ]</p>'; @@ -42,18 +76,32 @@ } else { $body .= '; <strong>expired</strong>.'; - } } - } else { $body .= '<p>User has never had a paid account of any kind.</p>'; - } - $body .= qq|<p><a href="/admin/statushistory.bml?user=$u->{user}">View statushistory for user.</a></p>|; - - $body .= "<h2>View Carts</h2>"; + # give the box for adding paid time to the user + my $auth = LJ::form_auth(); + $body .= <<EOF; +<br /><br /> + <form method="post"><input type="hidden" name="givetime" value="1"> + <input type="hidden" name="user" value="$u->{user}">$auth +Give Paid Time: + <select name="type"> + <option value="paid">Paid Account</option> + <option value="premium">Paid Premium Account</option> + <option value="seed">Seed Account</option> + <option value="blank"></option> + <option value="expire">FORCE EXPIRATION</option> + </select> + for <input type="text" name="months" maxlength="2" size="3" /> months + <input type="submit" value="Give!" /> +</form> +<p><a href="/admin/statushistory.bml?user=$u->{user}">View statushistory for user.</a></p> +<h2>View Carts</h2> +EOF my @carts = DW::Shop::Cart->get_all( $u ); --------------------------------------------------------------------------------