Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[ljcom] r11137: LJSUP-9901: Add ability to put entry fro...

Committer: anazarov
LJSUP-9901: Add ability to put entry from community to owner and maintainers
U   trunk/bin/upgrading/update-db-local.pl
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
U   trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm
U   trunk/htdocs/shop/selfpromo.bml.text.local
Modified: trunk/bin/upgrading/update-db-local.pl
===================================================================
--- trunk/bin/upgrading/update-db-local.pl	2011-11-02 08:13:09 UTC (rev 11136)
+++ trunk/bin/upgrading/update-db-local.pl	2011-11-02 08:48:12 UTC (rev 11137)
@@ -1702,6 +1702,7 @@
         `promoid`   int(11) NOT NULL auto_increment,
         `journalid` int(11) NOT NULL default '0',
         `posterid`  int(11) NOT NULL default '0',
+        `promoterid` int(11) NOT NULL default '0',
         `jitemid`   int(11) NOT NULL default '0',
         `ditemid`   int(11) NOT NULL default '0',
         `started`   int(11) NOT NULL default '0',
@@ -2242,6 +2243,13 @@
         );
     }
 
+    unless (column_type('selfpromo', 'promoterid')) {
+        do_alter(
+            'selfpromo',
+            'ALTER TABLE selfpromo ADD COLUMN promoterid INT NOT NULL DEFAULT 0',
+        );
+    }
+
     unless (column_type("userapps", "userhead")) {
         do_alter("userapps", qq{
             ALTER TABLE userapps

Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-11-02 08:13:09 UTC (rev 11136)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-11-02 08:48:12 UTC (rev 11137)
@@ -165,7 +165,7 @@
         my $entry = $self->get_entry;
 
         my $cost = $self->get_amt * LJ::Pay::Wallet::EXCHANGE_RATE();
-        LJ::Pay::SelfPromo->activate_entry( $entry, $cost );
+        LJ::Pay::SelfPromo->activate_entry( $entry, $cost, $buyer_u );
 
         $email_subject = $ml->('selfpromo.notification.activate.subject');
 

Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-11-02 08:13:09 UTC (rev 11136)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-11-02 08:48:12 UTC (rev 11137)
@@ -60,10 +60,24 @@
         return $err->('journal_adult_content');
     }
 
+    ## community checks
+    my $need_promoter_check = 1;
+    unless ( $LJ::DISABLED{'community_selfpromo'} ) {
+        if ( $journal->is_community and $promoter->can_manage($journal) ) {
+            $need_promoter_check = 0;
+        }
+    }
+
     ## poster checks
     unless ( $poster->is_visible ) { return $err->('poster_invisible'); }
-    unless ( LJ::u_equals( $poster, $promoter ) ) {
-        return $err->('promoter_poster_mismatch');
+    if ( $need_promoter_check ) {
+        unless ( LJ::u_equals( $poster, $promoter ) ) {
+            unless ( $LJ::DISABLED{'community_selfpromo'} ) {
+                return $err->('cannot_manage') if $journal->is_community;
+            }
+
+            return $err->('promoter_poster_mismatch');
+        }
     }
 
     ## entry checks
@@ -137,7 +151,7 @@
         if ( my $promo = $class->current_entry_info ) {
             $refund         = $class->calculate_refund($promo);
             $refund_promoid = $promo->promoid;
-            $refund_userid  = $promo->posterid;
+            $refund_userid  = $promo->promoterid || $promo->posterid;
         }
 
         my $refund_remainder =
@@ -221,7 +235,7 @@
         }
 
         my $refund_promoid = $promo->promoid;
-        my $refund_userid  = $promo->posterid;
+        my $refund_userid  = $promo->promoterid || $promo->posterid;
 
         my $refund_remainder =
             $refund % $LJ::SELF_PROMO_CONF->{'refund_step'};
@@ -273,26 +287,37 @@
 sub withdraw_entry {
     my ( $class, $entry ) = @_;
 
-    my $promo = $class->current_entry_info;
+    my $promo    = $class->current_entry_info;
+    my $journal  = $entry->journal;
+    my $poster   = $entry->poster;
+    my $promoter = $promo->promoter;
 
     die 'entry mismatch'
         unless $promo->journalid == $entry->journalid
             && $promo->jitemid == $entry->jitemid;
 
     $class->deactivate_promo(
-        $promo->promoid, $entry->poster,
+        $promo->promoid, $promoter,
         'reason'    => 'withdraw',
         'entry'     => $entry,
         'entry_url' => $entry->url,
     );
 
     $class->send_notification(
-        $entry->poster, 'deactivate',
+        $promoter, 'deactivate',
         'reason'    => 'withdraw',
         'entry_url' => $entry->url,
         'duration'  => $promo->exptime - $promo->started,
     );
 
+    unless ( LJ::u_equals($poster, $promoter) ) {
+        $class->send_notification(
+            $poster, 'deactivate',
+            'reason'    => 'withdraw',
+            'entry_url' => $entry->url,
+            'duration'  => $promo->exptime - $promo->started,
+        );
+    }
 }
 
 sub current_entry {
@@ -312,31 +337,41 @@
     my $entry = $class->current_entry;
 
     return unless $promo;    # everything's fine if nothing's promoted
+    my $poster   = $promo->poster;
+    my $promoter = $promo->promoter;
 
     unless ($entry) {
-        my $poster = $promo->poster;
 
         # we no longer have an entry because it's been deleted,
         # so let's reconstruct the URL
         my $entry_url = $promo->entry_url;
 
         $class->deactivate_promo(
-            $promo->promoid, $poster,
+            $promo->promoid, $promoter,
             'reason'    => 'deleted',
             'entry_url' => $entry_url,
             'promoinfo' => $promo,
         );
 
         $class->send_notification(
-            $poster, 'deactivate',
+            $promoter, 'deactivate',
             'reason'    => 'deleted',
             'entry_url' => $entry->url,
             'duration'  => time - $promo->started,
         );
+
+        unless ( LJ::u_equals($poster, $promoter) ) {
+            $class->send_notification(
+                $poster, 'deactivate',
+                'reason'    => 'deleted',
+                'entry_url' => $entry->url,
+                'duration'  => time - $promo->started,
+            );
+        }
     }
 
     my $reason;
-    unless ( $class->is_entry_eligible( $entry, $entry->poster, \$reason ) ) {
+    unless ( $class->is_entry_eligible( $entry, $promoter, \$reason ) ) {
         $class->deactivate_entry(
             'entry'   => $entry,
             'reason'  => 'ineligible',
@@ -344,25 +379,46 @@
         );
 
         $class->send_notification(
-            $entry->poster, 'deactivate',
+            $promoter, 'deactivate',
             'reason'    => 'ineligible',
             'details'   => $reason,
             'entry'     => $entry,
             'entry_url' => $entry->url,
             'duration'  => time - $promo->started,
         );
+
+        unless ( LJ::u_equals($poster, $promoter) ) {
+            $class->send_notification(
+                $poster, 'deactivate',
+                'reason'    => 'ineligible',
+                'details'   => $reason,
+                'entry'     => $entry,
+                'entry_url' => $entry->url,
+                'duration'  => time - $promo->started,
+            );
+        }
     }
 
     unless ( $promo->exptime > time ) {
         $class->deactivate_entry( 'entry' => $entry, 'reason' => 'expired' );
 
         $class->send_notification(
-            $entry->poster, 'deactivate',
+            $promoter, 'deactivate',
             'reason'    => 'expired',
             'entry'     => $entry,
             'entry_url' => $entry->url,
             'duration'  => time - $promo->started,
         );
+
+        unless ( LJ::u_equals($poster, $promoter) ) {
+            $class->send_notification(
+                $poster, 'deactivate',
+                'reason'    => 'expired',
+                'entry'     => $entry,
+                'entry_url' => $entry->url,
+                'duration'  => time - $promo->started,
+            );
+        }
     }
 }
 
@@ -464,7 +520,7 @@
 #
 # called from LJ::Pay::Payment::PayItem::SelfPromo
 sub activate_entry {
-    my ( $class, $entry, $cost ) = @_;
+    my ( $class, $entry, $cost, $promoter ) = @_;
 
     $class->check_current_entry;
 
@@ -486,6 +542,7 @@
         'started'   => time,
         'exptime'   => time + $LJ::SELF_PROMO_CONF->{'duration'},
         'cost'      => $cost,
+        'promoterid' => $promoter? $promoter->userid : $entry->posterid,
     );
 
     $class->clear_memcache;
@@ -516,7 +573,7 @@
     }
 
     $class->deactivate_promo(
-        $promo->promoid, $entry->poster,
+        $promo->promoid, $promo->promoter,
         'reason'    => $opts{'reason'},
         'details'   => $opts{'details'},
         'entry'     => $opts{'entry'},
@@ -527,13 +584,13 @@
 
 # supported opts: reason, details, entry, entry_url, refund
 sub deactivate_promo {
-    my ( $class, $promoid, $poster, %opts ) = @_;
+    my ( $class, $promoid, $promoter, %opts ) = @_;
 
     $class->db_update_promo( $promoid, 'active' => 0, 'finished' => time );
     $class->clear_memcache;
 
     $class->log(
-        $poster,
+        $promoter,
         'entry_url' => $opts{'entry_url'},
         'event'     => 'deactivate',
         'reason'    => $opts{'reason'},
@@ -747,7 +804,7 @@
 __PACKAGE__->mk_accessors(
     qw(
         promoid journalid posterid jitemid ditemid
-        started exptime cost active finished
+        started exptime cost active finished promoterid
     )
 );
 
@@ -766,6 +823,11 @@
     return LJ::load_userid( $self->posterid );
 }
 
+sub promoter {
+    my ($self) = @_;
+    return LJ::load_userid( $self->promoterid || $self->posterid );
+}
+
 sub entry {
     my ($self) = @_;
     return LJ::Entry->new( $self->journalid, 'jitemid' => $self->jitemid );

Modified: trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm	2011-11-02 08:13:09 UTC (rev 11136)
+++ trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm	2011-11-02 08:48:12 UTC (rev 11137)
@@ -29,6 +29,7 @@
     my $buyout_cost      = LJ::Pay::SelfPromo->buyout_cost;
     my $ml_current_price = LJ::Lang::ml( '/shop/selfpromo.bml.current_price',
         { 'price' => $buyout_cost } );
+    my $hide_buyout = 0;
 
     my $data_selfpromo = LJ::PersonalStats->get_selfpromo_data;
     foreach my $row (@$data_selfpromo) {
@@ -36,11 +37,13 @@
             LJ::Entry->new( $row->{'journal_id'},
             'ditemid' => $row->{'post_id'}, );
 
-        $row->{'can_withdraw'} = $entry->poster->equals($remote);
-
         my $promo =
             LJ::Pay::SelfPromo->current_entry_info( $row->{'promoid'} );
 
+        my $can_withdraw = LJ::u_equals($promo->promoter, $remote) || LJ::u_equals($promo->poster, $remote);
+        $hide_buyout = $can_withdraw;
+        $row->{'can_withdraw'} = $can_withdraw;
+
         # if for some reason the entry has already expired, this silently
         # casts its remaining time to zero:
         my $remtime         = List::Util::max( $promo->exptime - time, 0 );
@@ -57,12 +60,6 @@
         );
     }
 
-    my $hide_buyout = 0;
-
-    if ( my $entry = LJ::Pay::SelfPromo->current_entry ) {
-        $hide_buyout = ( $entry->poster->equals($remote) );
-    }
-
     LJ::need_string('/shop/selfpromo.bml.confirm.delete.promoted');
 
     return {

Modified: trunk/htdocs/shop/selfpromo.bml.text.local
===================================================================
--- trunk/htdocs/shop/selfpromo.bml.text.local	2011-11-02 08:13:09 UTC (rev 11136)
+++ trunk/htdocs/shop/selfpromo.bml.text.local	2011-11-02 08:48:12 UTC (rev 11137)
@@ -12,6 +12,8 @@
 .current_price|staleness=1
 .current_price=[[price]] [[?price|LJ Token|LJ Tokens|LJ Tokens]]
 
+.error.entry_ineligible.cannot_manage=You cannot promote the entry at <a href="[[entry_url]]">[[entry_url]]</a> because you are not its author or community's owner/maintainer.
+
 .error.entry_ineligible.entry_adult_content=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it is marked as containing adult content.
 
 .error.entry_ineligible.entry_banned|staleness=1

Tags: anazarov, ljcom, local, nfokz, pl, 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