Skip to content
This repository
Browse code

Merge pull request #326 from afuna/pointless-bug4857-live

(Bug 4857) Limit /shop/refundtopoints use to once every 30 days
  • Loading branch information...
commit 09923e5cbd08893c4946d305f32498fd21954e38 2 parents 6d95032 + 12ec769
Afuna authored March 21, 2013
8  bin/upgrading/proplists.dat
@@ -1142,6 +1142,14 @@ userproplist.shop_points:
1142 1142
   multihomed: 0
1143 1143
   prettyname: How many shop points the user has available
1144 1144
 
  1145
+userproplist.shop_refund_time:
  1146
+  cldversion: 0
  1147
+  datatype: num
  1148
+  des: Unix time at which a refund to points was last applied to this account
  1149
+  indexed: 0
  1150
+  multihomed: 0
  1151
+  prettyname: Last refund time
  1152
+
1145 1153
 userproplist.sidx_bdate:
1146 1154
   cldversion: 0
1147 1155
   datatype: char
6  cgi-bin/DW/Controller/Shop.pm
@@ -306,8 +306,9 @@ sub shop_refund_to_points_handler {
306 306
     $rv->{status} = DW::Pay::get_paid_status( $rv->{remote} );
307 307
     $rv->{rate} = DW::Pay::get_refund_points_rate( $rv->{remote} );
308 308
     $rv->{type} = DW::Pay::get_account_type_name( $rv->{remote} );
  309
+    $rv->{can_refund} = DW::Pay::can_refund_points( $rv->{remote} );
309 310
 
310  
-    if ( ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) {
  311
+    if ( $rv->{can_refund} && ref $rv->{status} eq 'HASH' && $rv->{rate} > 0 ) {
311 312
         $rv->{blocks} = int($rv->{status}->{expiresin} / (86400 * 30));
312 313
         $rv->{days} = $rv->{blocks} * 30;
313 314
         $rv->{points} = $rv->{blocks} * $rv->{rate};
@@ -315,7 +316,7 @@ sub shop_refund_to_points_handler {
315 316
 
316 317
     my $r = DW::Request->get;
317 318
     return DW::Template->render_template( 'shop/refundtopoints.tt', $rv )
318  
-        unless $r->did_post;
  319
+        unless $r->did_post && $rv->{can_refund};
319 320
 
320 321
     # User posted, so let's refund them if we can.
321 322
     die "Should never get here in a normal flow.\n"
@@ -330,6 +331,7 @@ sub shop_refund_to_points_handler {
330 331
     $rv->{remote}->give_shop_points( amount => $rv->{points},
331 332
             reason => sprintf('refund %d days of %s time', $rv->{days}, $rv->{type}) )
332 333
         or die "Failed to refund points.\n";
  334
+    $rv->{remote}->set_prop( "shop_refund_time", time() );
333 335
     DW::Pay::update_paid_status( $rv->{remote}, expiretime =>
334 336
             $rv->{status}->{expiretime} - ($rv->{days} * 86400) );
335 337
 
20  cgi-bin/DW/Pay.pm
@@ -7,7 +7,7 @@
7 7
 # Authors:
8 8
 #      Mark Smith <mark@dreamwidth.org>
9 9
 #
10  
-# Copyright (c) 2008-2009 by Dreamwidth Studios, LLC.
  10
+# Copyright (c) 2008-2013 by Dreamwidth Studios, LLC.
11 11
 #
12 12
 # This program is free software; you may redistribute it and/or modify it under
13 13
 # the same terms as Perl itself.  For a copy of the license, please reference
@@ -283,6 +283,24 @@ sub get_refund_points_rate {
283 283
     return $LJ::CAP{$typeid}->{_refund_points} || 0;
284 284
 }
285 285
 
  286
+
  287
+################################################################################
  288
+# DW::Pay::can_refund_points
  289
+#
  290
+# ARGUMENTS: uuserid
  291
+#
  292
+#   uuserid     required    user object or userid to get refundable status of
  293
+#
  294
+# RETURN: 1/0
  295
+#
  296
+sub can_refund_points {
  297
+    my $u = LJ::want_user( $_[0] );
  298
+    return 0 unless LJ::isu( $u );
  299
+
  300
+    my $secs_since_refund = time() - ( $u->prop( "shop_refund_time" ) || 0 );
  301
+    return $secs_since_refund > 86400 * 30 ? 1 : 0;
  302
+}
  303
+
286 304
 ################################################################################
287 305
 # DW::Pay::get_account_type_name
288 306
 #
10  views/shop/refundtopoints.tt
@@ -12,16 +12,20 @@
12 12
 
13 13
 <p>[% '.about' | ml(sitename = site.nameshort) %]</p>
14 14
 
15  
-<p>[% '.about2' | ml %]</p>
  15
+<p>[% '.about3' | ml %]</p>
16 16
 
17  
-[% IF rate == 0 %]
  17
+[% IF NOT rate %]
18 18
 
19 19
 <p><strong>[% '.noteligible' | ml %]</strong></p>
20 20
 
21  
-[% ELSIF points == 0 %]
  21
+[% ELSIF NOT points %]
22 22
 
23 23
 <p><strong>[% '.toofew' | ml %]</strong><p>
24 24
 
  25
+[% ELSIF NOT can_refund %]
  26
+
  27
+<p><strong>[% '.toosoon' | ml %]</strong></p>
  28
+
25 29
 [% ELSE %]
26 30
 
27 31
 <p>[% '.refund' | ml(sitename = site.nameshort, points = points, days = days, type = type) %]</p>
4  views/shop/refundtopoints.tt.text
... ...
@@ -1,7 +1,7 @@
1 1
 ;; -*- coding: utf-8 -*-
2 2
 .about=This page allows you to convert your personal account's paid time back to [[sitename]] Points.
3 3
 
4  
-.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.
  4
+.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.
5 5
 
6 6
 .addtocart=Convert Paid Time to [[points]] Points
7 7
 
@@ -18,3 +18,5 @@
18 18
 .title=[[sitename]] Convert to Points Tool
19 19
 
20 20
 .toofew=Sorry, you have less than 30 days of paid time on your account.
  21
+
  22
+.toosoon=Sorry, you can only refund paid time once every thirty days.

0 notes on commit 09923e5

Please sign in to comment.
Something went wrong with that request. Please try again.