slartyblartfast (slartyblartfast) wrote in changelog,
slartyblartfast
slartyblartfast
changelog

[ljcom] r8127: LJSUP-5434: Vgifts admin: age limits and...

Committer: mchernyshev
LJSUP-5434: Vgifts admin: age limits and show/hide to signed off users
- added translatable message;
- added two columns into table;
- added two fields for it in admin form;
- added filters to restrict access to vgifts accourding this parameters.
U   trunk/bin/upgrading/en_LJ.dat
U   trunk/bin/upgrading/update-db-local.pl
U   trunk/cgi-bin/LJ/Pay/ShopVGift.pm
U   trunk/htdocs/admin/vgift/edit.bml
Modified: trunk/bin/upgrading/en_LJ.dat
===================================================================
--- trunk/bin/upgrading/en_LJ.dat	2010-01-25 04:39:43 UTC (rev 8126)
+++ trunk/bin/upgrading/en_LJ.dat	2010-01-25 04:59:25 UTC (rev 8127)
@@ -2666,6 +2666,8 @@
 
 ljcom.userInfo.optionlinks.sendvgift.title.too_many_sponsored=There are too many sponsored vgifts in your cart.
 
+ljcom.userInfo.optionlinks.sendvgift.title.underage=You can't send this vgift to this recipient.
+
 ljcom.userInfo.optionlinks.sendvgift.title.comm.cannot=Sorry, you can't send this virtual gift to this community.
 
 ljcom.userinfo.optionlinks.sendvgift.title.comm.disabled=Sorry, you cannot send a v-gift to this community because the maintainer has chosen not to receive v-gifts.

Modified: trunk/bin/upgrading/update-db-local.pl
===================================================================
--- trunk/bin/upgrading/update-db-local.pl	2010-01-25 04:39:43 UTC (rev 8126)
+++ trunk/bin/upgrading/update-db-local.pl	2010-01-25 04:59:25 UTC (rev 8127)
@@ -1729,6 +1729,18 @@
         );
     }
 
+    unless (column_type("shop_vgifts", "is_hidden_for_not_logged_in")) {
+        do_alter("shop_vgifts",
+                "ALTER TABLE shop_vgifts ADD COLUMN is_hidden_for_not_logged_in " .
+                    "enum('0','1') NOT NULL DEFAULT '0'"
+        );
+    }
+
+    unless (column_type("shop_vgifts", "min_age")) {
+        do_alter("shop_vgifts",
+                "ALTER TABLE shop_vgifts ADD COLUMN min_age int(10) UNSIGNED DEFAULT NULL"
+        );
+    }
 });
 
 1;  # true

Modified: trunk/cgi-bin/LJ/Pay/ShopVGift.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/ShopVGift.pm	2010-01-25 04:39:43 UTC (rev 8126)
+++ trunk/cgi-bin/LJ/Pay/ShopVGift.pm	2010-01-25 04:59:25 UTC (rev 8127)
@@ -136,14 +136,21 @@
 
     return 0 unless $self->can_show_restricted;
     return 0 if $self->is_disabled;
-    my $date_start = $self->{date_start} || time() - 60;
-    my $date_end = $self->{date_end} || time() + 60;
-    if (($date_start < time()) and (time() < $date_end)) {
-        return 1;
+
+    my $remote = LJ::get_remote();
+    if ($remote) {
+        my $age = $remote->age();
+        return 0 if $age && $self->{min_age} && $self->{min_age} > $age;
     } else {
-        return 0;
+        return 0 if $self->{is_hidden_for_not_logged_in};
     }
-    return 1;
+
+    my $date_start = $self->{date_start};
+    my $date_end = $self->{date_end};
+    my $time = time();
+
+    # If $date_* specified and time is in this limit, return true, else return false;
+    return !(($date_start && $time < $date_start) || ($date_end && $time > $date_end));
 }
 
 ### FREE VGIFTS
@@ -183,6 +190,7 @@
 
 ### HIDDEN VGIFTS
 sub is_hidden { my $self = shift; $self->{is_hidden} }
+sub is_hidden_for_not_logged_in { $_[0]->{is_hidden_for_not_logged_in} }
 sub can_show_restricted { 1 }
 
 # return true if should check vgifts in shopping cart
@@ -191,13 +199,14 @@
 ## Update VGift
 ## Input (HASH):
 ##    vgift_name, perl_class, price, date_start, date_end,
-##    is_hidden, is_promo, is_disabled, is_charity, is_sponsored
+##    is_hidden, is_promo, is_disabled, is_charity, is_sponsored,
+##    min_age, is_hidden_for_not_logged_in
 sub update_vgift {
     my $self = shift;
     my %opts = @_;
 
     my (@fields, @fields_values);
-    for ('vgift_name', 'perl_class', 'price', 'date_start', 'date_end', 'is_hidden', 'is_promo', 'is_disabled', 'is_charity', 'is_sponsored', 'avail_for', 'cnt_for_send') {
+    for ('vgift_name', 'perl_class', 'price', 'date_start', 'date_end', 'is_hidden', 'is_promo', 'is_disabled', 'is_charity', 'is_sponsored', 'avail_for', 'cnt_for_send', 'min_age', 'is_hidden_for_not_logged_in') {
         if ( defined $opts{$_} ) {
             push @fields, $_;
             push @fields_values, $opts{$_};
@@ -458,18 +467,30 @@
             $spon_ct += $additem->{'qty'} if $new_vg->is_sponsored;
         }
 
-        # Don't allow free vgifts to be sent anonymously
+        # Don't allow free or restricted vgifts to be sent anonymously
         push @errs, LJ::Lang::ml('ljcom.userInfo.optionlinks.sendvgift.title.anonymously')
-            if ($new_vg->is_sponsored && (!$u || $additem->{'anon'}));
+            if (($new_vg->{is_hidden_for_not_logged_in} || $new_vg->is_sponsored)
+                && (!$u || $additem->{'anon'}));
     }
 
     my $rcpt_disable_vgifts = LJ::run_hook('opt_disable_vgifts_value', $rcptuser);
+    my $rcpt_user_age = $rcptuser->age();
+    my $remote = LJ::get_remote();
+    my $remote_age = $remote ? ($remote->age()) : 0;
 
     # check to see if the recipient has:
+    # - underaged
     # - banned the sender
     # - disabled all vgifts
     # - disabled sponsored vgifts
     if ($new_vg) {
+
+        my $vg_min_age = $new_vg->{min_age};
+        push @errs,
+            LJ::Lang::ml('ljcom.userinfo.optionlinks.sendvgift.title.underage')
+                if ($vg_min_age && $rcpt_user_age && $rcpt_user_age < $vg_min_age) ||
+                   ($vg_min_age && $remote_age && $remote_age < $vg_min_age);
+
         if ($u && $rcptuser->has_banned($u) || $rcpt_disable_vgifts eq "all") {
             push @errs,
                 LJ::Lang::ml(
@@ -534,12 +555,12 @@
     my $dbh = LJ::get_db_writer();
     $dbh->do("
         INSERT INTO shop_vgifts (
-            vgift_name, perl_class, price, date_start, date_end, is_hidden, is_promo, is_disabled, is_charity, is_sponsored
+            vgift_name, perl_class, price, date_start, date_end, min_age, is_hidden, is_hidden_for_not_logged_in, is_promo, is_disabled, is_charity, is_sponsored
         ) VALUES (
-            ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
+            ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
         )
-    ", undef, $opts{vgift_name}, $opts{perl_class}, $opts{price}||undef, $opts{date_start}||undef, $opts{date_end}||undef,
-              $opts{is_hidden}, $opts{is_promo}, $opts{is_disabled}, $opts{is_charity}, $opts{is_sponsored})||die $dbh->errstr;
+    ", undef, $opts{vgift_name}, $opts{perl_class}, $opts{price}||undef, $opts{date_start}||undef, $opts{date_end}||undef,$opts{min_age}||undef,
+              $opts{is_hidden}, $opts{is_hidden_for_not_logged_in}, $opts{is_promo}, $opts{is_disabled}, $opts{is_charity}, $opts{is_sponsored})||die $dbh->errstr;
 
     my $vgift_id = $dbh->last_insert_id (undef, undef, "shop_vgifts", undef);
 

Modified: trunk/htdocs/admin/vgift/edit.bml
===================================================================
--- trunk/htdocs/admin/vgift/edit.bml	2010-01-25 04:39:43 UTC (rev 8126)
+++ trunk/htdocs/admin/vgift/edit.bml	2010-01-25 04:59:25 UTC (rev 8127)
@@ -34,7 +34,7 @@
         my $vgift;
 
         ## Set boolean params
-        for ('is_hidden','is_promo','is_disabled','is_charity','is_sponsored') {
+        for ('is_hidden','is_hidden_for_not_logged_in','is_promo','is_disabled','is_charity','is_sponsored') {
             $POST{$_} = ($POST{$_} eq 'on') ? 1 : 0;
         }
     
@@ -113,6 +113,7 @@
     $ret .= "<table border='1'>";
 	$ret .= "<tr><td>VGift Id</td><td><input type='hidden' name='vgift_id' value='" . $vgift->{vgift_id} . "'>" . $vgift->{vgift_id} . "</td></tr>";
 	$ret .= "<tr><td>Is Hidden</td><td><input type='checkbox' name='is_hidden'" . ($vgift->is_hidden eq '1' ? " checked = 'checked' " : "") . "></td></tr>";
+	$ret .= "<tr><td>Is Hidden for not logged in</td><td><input type='checkbox' name='is_hidden_for_not_logged_in'" . ($vgift->{is_hidden_for_not_logged_in} eq '1' ? " checked = 'checked' " : "") . "></td></tr>";
 	$ret .= "<tr><td>VGift name</td><td><input type='text' name='vgift_name' value='" . $vgift->keyname . "'" . ($GET{vgift_id} ? " disabled='disabled'" : "") . "></td></tr>";
 	$ret .= "<tr><td>Is Promo</td><td><input type='checkbox' name='is_promo'" . ($vgift->is_promo eq '1' ? " checked = 'checked' " : "") . "></td></tr>";
 	$ret .= "<tr><td>Is Disabled</td><td><input type='checkbox' name='is_disabled'" . ($vgift->is_disabled eq '1' ? " checked = 'checked' " : "") . "></td></tr>";
@@ -142,6 +143,7 @@
     $ret .= "<tr><td>Message 'From'</td><td><input size='30' type='text' name='fromuser' value='" . $fromuser . "'></td></tr>";
     $ret .= "<tr><td>Message 'Anon'</td><td><input size='30' type='text' name='anon' value='" . $anon . "'></td></tr>";
     $ret .= "<tr><td>VGift available for</td><td><select name='avail_for'><option value='a' ".($vgift->{avail_for} eq 'a' ? "selected" : "").">All</option><option value='p' ".($vgift->{avail_for} eq 'p' ? "selected" : "").">Paid</option><option value='n' ".($vgift->{avail_for} eq 'n' ? "selected" : "").">Not paid</option></tr>";
+    $ret .= "<tr><td>VGift available from age</td><td><input type='text' name='min_age' value='".$vgift->{min_age}."'></td></tr>";
     $ret .= "<tr><td>Each user may send not more then</td><td><input type='text' name='cnt_for_send' value='".$vgift->{cnt_for_send}."'></td></tr>";
     $ret .= "";
     $ret .= "<tr><td colspan='2' align='center'><input type='hidden' name='mode' value='changevgift'><input type='submit' value='" . ($GET{vgift_id} > 0 ? "save" : "add") . "'></td></tr>";

Tags: bml, dat, ljcom, pl, pm, slartyblartfast
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments