[dw-free] fix finduser display for account status
[commit: http://hg.dwscoalition.org/dw-free/rev/037560b72db0]
http://bugs.dwscoalition.org/show_bug.cgi?id=3247
Refactor this logic to a new method and call it so that we're sure we're
always doing the right thing.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3247
Refactor this logic to a new method and call it so that we're sure we're
always doing the right thing.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/DW/Hooks/Display.pm
- cgi-bin/DW/Pay.pm
- htdocs/shop/gifts.bml
-------------------------------------------------------------------------------- diff -r 81a94e892108 -r 037560b72db0 cgi-bin/DW/Hooks/Display.pm --- a/cgi-bin/DW/Hooks/Display.pm Wed Nov 24 19:12:44 2010 +0800 +++ b/cgi-bin/DW/Hooks/Display.pm Wed Nov 24 19:24:30 2010 +0800 @@ -32,8 +32,11 @@ LJ::Hooks::register_hook( 'finduser_extr my $paidstatus = DW::Pay::get_paid_status( $u ); my $numinvites = DW::InviteCodes->unused_count( userid => $u->id ); - if ( $paidstatus ) { - $ret .= " " . DW::Pay::type_name( $paidstatus->{typeid} ) . ", expiring " . LJ::mysql_time( $paidstatus->{expiretime} ) . "\n"; + unless ( DW::Pay::is_default_type( $paidstatus ) ) { + $ret .= " " . DW::Pay::type_name( $paidstatus->{typeid} ); + $ret .= $paidstatus->{permanent} ? ", never expires" : + ", expiring " . LJ::mysql_time( $paidstatus->{expiretime} ); + $ret .= "\n"; } if ( $numinvites ) { diff -r 81a94e892108 -r 037560b72db0 cgi-bin/DW/Pay.pm --- a/cgi-bin/DW/Pay.pm Wed Nov 24 19:12:44 2010 +0800 +++ b/cgi-bin/DW/Pay.pm Wed Nov 24 19:24:30 2010 +0800 @@ -148,6 +148,24 @@ sub default_typeid { } ################################################################################ +# DW::Pay::is_default_type +# +# ARGUMENTS: hashref returned from get_paid_status +# +# RETURN: 1 if default_typeid should be used, 0 otherwise +# +sub is_default_type { + my $stat = $_[0]; + + # free accounts: no row, or expired (but not permanent) + return 1 unless defined $stat; + return 1 unless $stat->{permanent} || $stat->{expiresin} > 0; + + # use typeid defined in row + return 0; +} + +################################################################################ # DW::Pay::get_current_account_status # # ARGUMENTS: uuserid @@ -160,9 +178,8 @@ sub get_current_account_status { # try to get current paid status my $stat = DW::Pay::get_paid_status( @_ ); - # free accounts: no row, or expired - return DW::Pay::default_typeid() unless defined $stat; - return DW::Pay::default_typeid() unless $stat->{permanent} || $stat->{expiresin} > 0; + # default check + return DW::Pay::default_typeid() if DW::Pay::is_default_type( $stat ); # valid row, return whatever type it is return $stat->{typeid}; @@ -707,7 +724,7 @@ sub sync_caps { my $default = DW::Pay::default_typeid(); # either they're free, or they expired (not permanent) - if ( ! $ps || ( ! $ps->{permanent} && $ps->{expiresin} < 0 ) ) { + if ( DW::Pay::is_default_type( $ps ) ) { # reset back to the default, and turn off all other bits; then set the # email count to defined-but-0 $u->modify_caps( [ $default ], [ grep { $_ != $default } @bits ] ); diff -r 81a94e892108 -r 037560b72db0 htdocs/shop/gifts.bml --- a/htdocs/shop/gifts.bml Wed Nov 24 19:12:44 2010 +0800 +++ b/htdocs/shop/gifts.bml Wed Nov 24 19:24:30 2010 +0800 @@ -44,7 +44,7 @@ body<= # wouldn't show, since get_paid_status only returns undef if # the account has never been paid, not if it's not currently # paid...): - push @free, $target unless $paidstatus && $paidstatus->{expiresin} > 0 || $paidstatus->{permanent}; + push @free, $target if DW::Pay::is_default_type( $paidstatus ); # account is expiring soon if the expiration time is # within the next month: --------------------------------------------------------------------------------