[ljcom] r5356: Don't allow users to send vgifts to peop...

Aug 17, 2007 22:44


Committer: janineDon't allow users to send vgifts to people who have banned them.

http://rt.livejournal.org/Ticket/Display.html?id=4204

U trunk/cgi-bin/LJ/Pay/ShopVGift.pm
U trunk/cgi-bin/paylib.pl
U trunk/htdocs/pay/modify.bml

Modified: trunk/cgi-bin/LJ/Pay/ShopVGift.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/ShopVGift.pm 2007-08-17 21:46:28 UTC (rev 5355)
+++ trunk/cgi-bin/LJ/Pay/ShopVGift.pm 2007-08-17 22:44:50 UTC (rev 5356)
@@ -209,8 +209,7 @@
sub should_check_cart {
my $self = shift;

- # return true if vgift is free
- return $self->is_free ? 1 : 0;
+ return 1;
}

sub tracking {
@@ -231,7 +230,7 @@

# check validity of vgifts in cart
sub check_cart {
- my ($cartobj, $additem) = @_;
+ my ($cartobj, $additem, $rcptuser) = @_;

my $u = LJ::get_remote();
return unless ($u);
@@ -262,6 +261,9 @@
}
}

+ # check to see if the recipient has banned the sender
+ push @errs, "You can't send vgifts to this user" if $rcptuser->has_banned($u);
+
return @errs;
}

@@ -280,6 +282,23 @@
return $count;
}

+# return true if none of the vgifts are being sent to users that have banned the sender
+sub can_checkout_vgifts {
+ my ($cartobj) = @_;
+
+ my $u = LJ::get_remote();
+ return 0 unless $u;
+
+ foreach my $it (@{$cartobj->{items}}) {
+ next unless $it->{item} eq "vgift";
+
+ my $rcptuser = LJ::load_userid($it->{rcptid});
+ return 0 if $rcptuser && $rcptuser->has_banned($u);
+ }
+
+ return 1;
+}
+
# return true if the number of free vgifts doesn't put the user over the limit
sub can_checkout_freevgifts {
my ($cartobj) = @_;

Modified: trunk/cgi-bin/paylib.pl
===================================================================
--- trunk/cgi-bin/paylib.pl 2007-08-17 21:46:28 UTC (rev 5355)
+++ trunk/cgi-bin/paylib.pl 2007-08-17 22:44:50 UTC (rev 5356)
@@ -2791,6 +2791,7 @@
return undef if $u->underage;
}

+ return undef unless LJ::Pay::ShopVGift::can_checkout_vgifts($cartobj);
return undef unless LJ::Pay::ShopVGift::can_checkout_freevgifts($cartobj);

return 1;

Modified: trunk/htdocs/pay/modify.bml
===================================================================
--- trunk/htdocs/pay/modify.bml 2007-08-17 21:46:28 UTC (rev 5355)
+++ trunk/htdocs/pay/modify.bml 2007-08-17 22:44:50 UTC (rev 5356)
@@ -858,7 +858,7 @@
if $POST{vgiftnote} && length $POST{vgiftnote} > 65535;
my $vg = LJ::Pay::ShopVGift->new($subitem);
if ($vg->should_check_cart) {
- my @errs = LJ::Pay::ShopVGift::check_cart($cartobj, $item);
+ my @errs = LJ::Pay::ShopVGift::check_cart($cartobj, $item, $rcptuser);
return $err->(@errs) if (@errs);
}
}

Previous post Next post
Up