Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r11016: LJSUP-9791 (Self promo console command i...

Committer: ailyin
LJSUP-9791 (Self promo console command improvements)
U   trunk/bin/upgrading/en_LJ.dat
U   trunk/bin/upgrading/proplists-local.dat
A   trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm
U   trunk/cgi-bin/LJ/Console/Command/SelfPromoCancel.pm
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
U   trunk/htdocs/shop/selfpromo.bml.text.local
Modified: trunk/bin/upgrading/en_LJ.dat
===================================================================
--- trunk/bin/upgrading/en_LJ.dat	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/bin/upgrading/en_LJ.dat	2011-09-19 07:02:31 UTC (rev 11016)
@@ -5529,6 +5529,23 @@
 
 selfpromo.notification.deactivate.admin2.subject=Entry promotion discontinued
 
+selfpromo.notification.deactivate.admin2.norefund.body<<
+Dear [[poster]],
+
+Promotion of your entry at [[entry_url]] has been discontinued due to a Terms of Use violation. Your entry stayed promoted for [[duration_hours]] [[?duration_hours|hour|hours|hours]] [[duration_min]] [[?duration_min|minute|minutes|minutes]].
+
+If you want to promote an entry again, you can purchase another promotion at the promotion page (http://www.livejournal.com/shop/selfpromo.bml).
+
+If you think it was removed in error, please contact our Support team (http://www.livejournal.com/support/) and let us know.
+
+Thank you for using the service!
+
+LiveJournal Team
+http://www.livejournal.com
+.
+
+selfpromo.notification.deactivate.admin2.norefund.subject=Entry promotion discontinued
+
 selfpromo.notification.deactivate.buyout2.body<<
 Dear [[poster]],
 

Modified: trunk/bin/upgrading/proplists-local.dat
===================================================================
--- trunk/bin/upgrading/proplists-local.dat	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/bin/upgrading/proplists-local.dat	2011-09-19 07:02:31 UTC (rev 11016)
@@ -801,3 +801,15 @@
   indexed: 0
   prettyname: Application promo userhead appid.
 
+userproplist.selfpromo_banned:
+  cldversion: 8
+  datatype: bool
+  prettyname: User banned from selfpromo
+  des: If set to true, the user's journal and all user's community entries are banned from SelfPromo
+  indexed: 0
+
+logproplist.selfpromo_banned:
+  datatype: bool
+  prettyname: User banned from selfpromo
+  des: If set to true, the user's journal and all user's community entries are banned from SelfPromo
+  sortorder: 105

Added: trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm	2011-09-19 07:02:31 UTC (rev 11016)
@@ -0,0 +1,192 @@
+package LJ::Console::Command::SelfPromo;
+use strict;
+use warnings;
+
+use base qw( LJ::Console::Command );
+
+use LJ::Pay::SelfPromo;
+
+sub cmd {'selfpromo'}
+
+sub desc {
+    return 'SelfPromo administration tools';
+}
+
+sub usage {
+    return '<cmd> <object> [norefund]';
+}
+
+sub args_desc {
+    return [
+        'cmd' => 'The command to run, one of "cancel", "ban", or "unban"',
+
+        'object' =>
+            'For "cancel", the entry URL to cancel. For "ban" ' .
+            'and "unban", either the entry URL or the username ' .
+            'to ban or unban.',
+
+        'norefund' =>
+            'For "cancel" only, an optional flag that specifies ' .
+            'not to issue token refund to the promotion author.',
+    ];
+}
+
+sub can_execute {
+    my $remote = LJ::get_remote();
+    return LJ::check_priv( $remote, 'siteadmin', 'selfpromo' );
+}
+
+sub _cancel_entry {
+    my ( $self, %args ) = @_;
+
+    my $entry  = $args{'entry'};
+    my $refund = $args{'refund'};
+
+    # refund defaults to 1
+    $refund = 1 unless defined $refund;
+
+    my $admin = LJ::get_remote();
+
+    my $message = 'admin cancel: ' . $entry->url;
+    $message .= ', without refund' unless $refund;
+
+    LJ::statushistory_add( $entry->poster, $admin, 'selfpromo', $message );
+
+    LJ::Pay::SelfPromo->admin_cancel_promo(
+        'entry'  => $entry,
+        'admin'  => $admin,
+        'refund' => $refund,
+    );
+}
+
+sub execute {
+    my ( $self, $cmd, $object, @args_remainder ) = @_;
+
+    if ( ! defined $cmd || $cmd eq '' ) {
+        return $self->error('No command specified');
+    }
+
+    unless ( $cmd eq 'cancel' || $cmd eq 'ban' || $cmd eq 'unban' ) {
+        return $self->error("Invalid command $cmd specified");
+    }
+
+    if ( ! defined $object || $object eq '' ) {
+        return $self->error("No object to $cmd specified");
+    }
+
+    # either it's an entry URL, or a username, or something unknown
+    my $object_orig = $object;
+    if ( $object =~ m{^http://} ) {
+        $object = LJ::Entry->new_from_url($object);
+        unless ( $object && $object->valid ) {
+            return $self->error("No entry found at $object_orig");
+        }
+    } elsif ( $object =~ /^[a-z\-_]+$/i ) {
+        $object = LJ::load_user($object);
+        unless ($object) {
+            return $self->error("No such user $object_orig");
+        }
+    } else {
+        return $self->error("Invalid object $object passed");
+    }
+
+    my $norefund = 0;
+    if (@args_remainder) {
+        unless ( $cmd eq 'cancel' || @args_remainder > 1 ) {
+            return $self->error("Too many arguments for $cmd");
+        }
+
+        my ($arg) = @args_remainder;
+
+        unless ( $arg eq 'norefund' ) {
+            return $self->error("Invalid argument '$arg'");
+        }
+
+        $norefund = 1;
+    }
+
+    LJ::Pay::SelfPromo->check_current_entry;
+    my $current_entry = LJ::Pay::SelfPromo->current_entry;
+
+    if ( $cmd eq 'cancel' ) {
+        unless ( $object->isa('LJ::Entry') ) {
+            return $self->error('"cancel" requires an entry URL');
+        }
+
+        my $entry = $object;
+
+        unless ($current_entry) {
+            return $self->error('No entry currently promoted');
+        }
+
+        unless ( $entry->journalid == $current_entry->journalid
+            && $entry->jitemid == $current_entry->jitemid )
+        {
+            return $self->error(
+                $entry->url . ' is not the entry currently promoted' );
+        }
+
+        $self->_cancel_entry( 'entry' => $entry, 'refund' => !$norefund );
+
+        $self->info( $entry->url . ' cancelled successfully' );
+        return 1;
+    }
+
+    if ( $cmd eq 'ban' ) {
+        if ( $object->isa('LJ::User') ) {
+            my $u = $object;
+
+            if ( $current_entry
+                && ( $current_entry->poster->equals($u)
+                || $current_entry->journal->equals($u) ) )
+            {
+                $self->info('The ban will affect the currently promoted '
+                    . 'entry, so cancelling that.');
+                $self->_cancel_entry( 'entry' => $current_entry );
+            }
+
+            $u->set_prop( 'selfpromo_banned' => 1 );
+
+            $self->info( $u->display_name . ' banned successfully.');
+            return 1;
+        }
+
+        if ( $object->isa('LJ::Entry') ) {
+            my $entry = $object;
+
+            if ( $current_entry
+                && $current_entry->journalid == $entry->journalid
+                && $current_entry->jitemid == $entry->jitemid )
+            {
+                $self->info('The ban will affect the currently promoted '
+                    . 'entry, so cancelling that.');
+                $self->_cancel_entry( 'entry' => $current_entry );
+            }
+
+            $entry->set_prop( 'selfpromo_banned' => 1 );
+
+            $self->info( $entry->url . ' banned successfully.');
+            return 1;
+        }
+
+        return 1;
+    }
+
+    if ( $cmd eq 'unban' ) {
+        if ( $object->isa('LJ::User') ) {
+            $object->clear_prop('selfpromo_banned');
+            $self->info( $object->display_name . ' unbanned successfully.');
+            return 1;
+        }
+
+        if ( $object->isa('LJ::Entry') ) {
+            $object->set_prop( 'selfpromo_banned' => undef );
+            $self->info( $object->url . ' unbanned successfully.');
+            return 1;
+        }
+
+        return 1;
+    }
+}
+
+1;

Modified: trunk/cgi-bin/LJ/Console/Command/SelfPromoCancel.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/SelfPromoCancel.pm	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/cgi-bin/LJ/Console/Command/SelfPromoCancel.pm	2011-09-19 07:02:31 UTC (rev 11016)
@@ -1,3 +1,5 @@
+# this one is obsolete; see SelfPromo.pm (cmd=selfpromo) instead
+
 package LJ::Console::Command::SelfPromoCancel;
 use strict;
 use warnings;
@@ -2,54 +4,7 @@
 
-use LJ::Pay::SelfPromo;
-
 use base qw( LJ::Console::Command );
 
-sub cmd {
-    return 'selfpromo_cancel';
-}
+sub cmd {'selfpromo_cancel'}
+sub can_execute {0}
 
-sub desc {
-    return 'Cancel entry promotion in SelfPromo';
-}
-
-sub usage {
-    return '<entry_url>';
-}
-
-sub args_desc {
-    return [ 'entry_url' => 'The URL of the entry to cancel', ];
-}
-
-sub can_execute {
-    my $remote = LJ::get_remote();
-    return LJ::check_priv( $remote, 'siteadmin', 'selfpromo' );
-}
-
-sub execute {
-    my ( $self, $entry_url, @args_remainder ) = @_;
-
-    return $self->error('Too many arguments') if @args_remainder;
-
-    my $entry = LJ::Entry->new_from_url($entry_url);
-    return $self->error( 'No such entry: ' . $entry_url ) unless $entry;
-
-    my $promoted_entry = LJ::Pay::SelfPromo->current_entry;
-    return $self->error('No entry currently promoted') unless $promoted_entry;
-    return $self->error( $entry_url . ' is not the entry currently promoted' )
-        unless $entry->journalid == $promoted_entry->journalid
-            && $entry->jitemid == $promoted_entry->jitemid;
-
-    my $admin = LJ::get_remote();
-    LJ::statushistory_add(
-        $entry->poster, $admin,
-        'selfpromo',
-        'admin cancel: ' . $entry->url,
-    );
-
-    LJ::Pay::SelfPromo->admin_cancel_promo( $entry, LJ::get_remote() );
-
-    $self->info( $entry_url . ' cancelled successfully' );
-    return 1;
-}
-
 1;

Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-09-19 07:02:31 UTC (rev 11016)
@@ -96,24 +96,26 @@
             'details' => $self->get_piid,
         );
 
-        if ( my $refund = $self->get_prop('selfpromo_refund') ) {
+        if ( my $refund_userid = $self->get_prop('selfpromo_refund_userid') ) {
             my $promoid = $self->get_prop('selfpromo_refund_promoid');
-            my $refund_to_userid = $self->get_prop('selfpromo_refund_userid');
-            my $refund_to        = LJ::load_userid($refund_to_userid);
+            my $refund_to        = LJ::load_userid($refund_userid);
 
             my $promo = LJ::Pay::SelfPromo->current_entry_info($promoid);
 
-            # credit them:
-            LJ::Pay::Wallet->try_add( $refund_to, $refund );
-            LJ::Pay::Wallet::Log->log(
-                'userid'   => $refund_to_userid,
-                'action'   => LJ::Pay::Wallet::Log::ACTION_ADD,
-                'qty'      => $refund,
-                'payid'    => $self->get_payid,
-                'piid'     => $self->get_piid,
-                'status'   => LJ::Pay::Wallet::Log::STATUS_FINISHED,
-                'time_end' => time,
-            );
+            my $refund = $self->get_prop('selfpromo_refund');
+            if ($refund) {
+                # credit them:
+                LJ::Pay::Wallet->try_add( $refund_to, $refund );
+                LJ::Pay::Wallet::Log->log(
+                    'userid'   => $refund_userid,
+                    'action'   => LJ::Pay::Wallet::Log::ACTION_ADD,
+                    'qty'      => $refund,
+                    'payid'    => $self->get_payid,
+                    'piid'     => $self->get_piid,
+                    'status'   => LJ::Pay::Wallet::Log::STATUS_FINISHED,
+                    'time_end' => time,
+                );
+            }
 
             my $entry_url = $promo->entry_url;
 

Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-09-19 07:02:31 UTC (rev 11016)
@@ -74,6 +74,18 @@
         return $err->('entry_adult_content');
     }
 
+    # bans; this is separate because poster needs to be checked before
+    # journal
+    if ( $poster->prop('selfpromo_banned') ) {
+        return $err->('poster_banned');
+    }
+    if ( $journal->prop('selfpromo_banned') ) {
+        return $err->('journal_banned');
+    }
+    if ( $entry->prop('selfpromo_banned') ) {
+        return $err->('entry_banned');
+    }
+
     # TODO: check if this is the very entry being promoted right now?
 
     return 1;
@@ -178,8 +190,11 @@
 }
 
 sub admin_cancel_promo {
-    my ( $class, $entry, $admin ) = @_;
+    my ( $class, %args ) = @_;
 
+    my $entry = $args{'entry'};
+    my $admin = $args{'admin'};
+
     my $promo = $class->current_entry_info;
     unless ( $promo
         && $promo->journalid == $entry->journalid
@@ -200,7 +215,11 @@
         # user who purchased the selfpromo being cancelled,
         # and a part of it is a rounding error that goes to a
         # special account made for these purposes
-        my $refund         = $class->calculate_refund($promo);
+        my $refund = 0;
+        if ( $args{'refund'} ) {
+            $refund = $class->calculate_refund($promo);
+        }
+
         my $refund_promoid = $promo->promoid;
         my $refund_userid  = $promo->posterid;
 
@@ -213,7 +232,8 @@
         my $remainder_userid = $remainder_to ? $remainder_to->userid : 0;
 
         $cart = $class->create_shop_cart(
-            {   'cart_owner'       => $admin,
+            {
+                'cart_owner'       => $admin,
                 'entry'            => undef,
                 'price'            => 0,
                 'profit'           => 0,
@@ -590,6 +610,9 @@
 
         if ( $reason eq 'admin' ) {
             $ml_var = 'selfpromo.notification.deactivate.admin2';
+            unless ( $opts{'refund_amount'} > 0 ) {
+                $ml_var .= '.norefund';
+            }
         }
 
         if ( $reason eq 'buyout' ) {
@@ -615,7 +638,7 @@
         }
 
     }
-    
+
     my $lang = $poster->prop('browselang') || $LJ::DEFAULT_LANG;
     my $subject =
         LJ::Lang::get_text( $lang, "$ml_var.subject", undef,
@@ -780,7 +803,7 @@
 
 sub DESTROY {
     my ($self) = @_;
-    
+
     ## warning: this code may be called during exception "stack unwind" step.
     ## if original exception ($@) is not saved, it will be lost.
     local $@;

Modified: trunk/htdocs/shop/selfpromo.bml.text.local
===================================================================
--- trunk/htdocs/shop/selfpromo.bml.text.local	2011-09-19 06:36:55 UTC (rev 11015)
+++ trunk/htdocs/shop/selfpromo.bml.text.local	2011-09-19 07:02:31 UTC (rev 11016)
@@ -6,16 +6,22 @@
 
 .error.entry_ineligible.entry_adult_content=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it is set to indicate that it contains adult content.
 
+.error.entry_ineligible.entry_banned=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it was banned from this service. If you believe this is in error, <a href="http://www.livejournal.com/support">contact our Support team</a>.
+
 .error.entry_ineligible.entry_invisible=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it is not a visible entry.
 
 .error.entry_ineligible.entry_not_public=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it is not publicly-available.
 
 .error.entry_ineligible.journal_adult_content=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because [[journal_ljuser]] is set to indicate that it contains adult content.
 
+.error.entry_ineligible.journal_banned=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because the journal it is in was banned from this service. If you believe this is in error, <a href="http://www.livejournal.com/support">contact our Support team</a>.
+
 .error.entry_ineligible.journal_invisible=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because [[journal_ljuser]] is not a visible journal.
 
 .error.entry_ineligible.not_found=We couldn't find any entry at <a href="[[entry_url]]">[[entry_url]]</a>.
 
+.error.entry_ineligible.poster_banned=You cannot promote the entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because you were banned from using this service. If you believe this is in error, <a href="http://www.livejournal.com/support">contact our Support team</a>.
+
 .error.entry_ineligible.poster_invisible=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because its author, [[poster_ljuser]], is not a visible user.
 
 .error.entry_ineligible.promoter_poster_mismatch=You cannot promote the entry at <a href="[[entry_url]]">[[entry_url]]</a> because you are not its author.

Tags: andy, dat, ljcom, local, pm
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