Skip to content

Commit

Permalink
Merge branch 'release-1.14' into develop
Browse files Browse the repository at this point in the history
* release-1.14:
  (Bug 4857) Limit /shop/refundtopoints use to once every 30 days
  • Loading branch information
afuna committed Mar 21, 2013
2 parents 1d6dd70 + 09923e5 commit 35a787c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bin/upgrading/proplists.dat
Expand Up @@ -1142,6 +1142,14 @@ userproplist.shop_points:
multihomed: 0
prettyname: How many shop points the user has available

userproplist.shop_refund_time:
cldversion: 0
datatype: num
des: Unix time at which a refund to points was last applied to this account
indexed: 0
multihomed: 0
prettyname: Last refund time

userproplist.sidx_bdate:
cldversion: 0
datatype: char
Expand Down
6 changes: 4 additions & 2 deletions cgi-bin/DW/Controller/Shop.pm
Expand Up @@ -334,16 +334,17 @@ sub shop_refund_to_points_handler {
$rv->{status} = DW::Pay::get_paid_status( $rv->{remote} );
$rv->{rate} = DW::Pay::get_refund_points_rate( $rv->{remote} );
$rv->{type} = DW::Pay::get_account_type_name( $rv->{remote} );
$rv->{can_refund} = DW::Pay::can_refund_points( $rv->{remote} );

if ( ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) {
if ( $rv->{can_refund} && ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) {
$rv->{blocks} = int($rv->{status}->{expiresin} / (86400 * 30));
$rv->{days} = $rv->{blocks} * 30;
$rv->{points} = $rv->{blocks} * $rv->{rate};
}

my $r = DW::Request->get;
return DW::Template->render_template( 'shop/refundtopoints.tt', $rv )
unless $r->did_post;
unless $r->did_post && $rv->{can_refund};

# User posted, so let's refund them if we can.
die "Should never get here in a normal flow.\n"
Expand All @@ -358,6 +359,7 @@ sub shop_refund_to_points_handler {
$rv->{remote}->give_shop_points( amount => $rv->{points},
reason => sprintf('refund %d days of %s time', $rv->{days}, $rv->{type}) )
or die "Failed to refund points.\n";
$rv->{remote}->set_prop( "shop_refund_time", time() );
DW::Pay::update_paid_status( $rv->{remote}, expiretime =>
$rv->{status}->{expiretime} - ($rv->{days} * 86400) );

Expand Down
20 changes: 19 additions & 1 deletion cgi-bin/DW/Pay.pm
Expand Up @@ -7,7 +7,7 @@
# Authors:
# Mark Smith <mark@dreamwidth.org>
#
# Copyright (c) 2008-2009 by Dreamwidth Studios, LLC.
# Copyright (c) 2008-2013 by Dreamwidth Studios, LLC.
#
# This program is free software; you may redistribute it and/or modify it under
# the same terms as Perl itself. For a copy of the license, please reference
Expand Down Expand Up @@ -283,6 +283,24 @@ sub get_refund_points_rate {
return $LJ::CAP{$typeid}->{_refund_points} || 0;
}


################################################################################
# DW::Pay::can_refund_points
#
# ARGUMENTS: uuserid
#
# uuserid required user object or userid to get refundable status of
#
# RETURN: 1/0
#
sub can_refund_points {
my $u = LJ::want_user( $_[0] );
return 0 unless LJ::isu( $u );

my $secs_since_refund = time() - ( $u->prop( "shop_refund_time" ) || 0 );
return $secs_since_refund > 86400 * 30 ? 1 : 0;
}

################################################################################
# DW::Pay::get_account_type_name
#
Expand Down
10 changes: 7 additions & 3 deletions views/shop/refundtopoints.tt
Expand Up @@ -12,16 +12,20 @@

<p>[% '.about' | ml(sitename = site.nameshort) %]</p>

<p>[% '.about2' | ml %]</p>
<p>[% '.about3' | ml %]</p>

[% IF rate == 0 %]
[% IF NOT rate %]

<p><strong>[% '.noteligible' | ml %]</strong></p>

[% ELSIF points == 0 %]
[% ELSIF NOT points %]

<p><strong>[% '.toofew' | ml %]</strong><p>

[% ELSIF NOT can_refund %]

<p><strong>[% '.toosoon' | ml %]</strong></p>

[% ELSE %]

<p>[% '.refund' | ml(sitename = site.nameshort, points = points, days = days, type = type) %]</p>
Expand Down
4 changes: 3 additions & 1 deletion views/shop/refundtopoints.tt.text
@@ -1,7 +1,7 @@
;; -*- coding: utf-8 -*-
.about=This page allows you to convert your personal account's paid time back to [[sitename]] Points.

.about2=Exchanges can only be done if you have at least 30 days of paid time. We will only convert time in multiples of 30 days. In other words, if your account has 40 days of paid time left, this page will let you get an exchange for only 30 days of that.
.about3=Exchanges can only be done if you have at least 30 days of paid time, and can only be done once every 30 days. We will only convert time in multiples of 30 days. In other words, if your account has 40 days of paid time left, this page will let you get an exchange for only 30 days of that.

.addtocart=Convert Paid Time to [[points]] Points

Expand All @@ -18,3 +18,5 @@
.title=[[sitename]] Convert to Points Tool

.toofew=Sorry, you have less than 30 days of paid time on your account.

.toosoon=Sorry, you can only refund paid time once every thirty days.

0 comments on commit 35a787c

Please sign in to comment.