Committer: anazarov
LJSUP-10288: Improve admin logs for selfpromoU trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm
Modified: trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm 2011-11-07 09:12:31 UTC (rev 11154) +++ trunk/cgi-bin/LJ/Console/Command/SelfPromo.pm 2011-11-07 12:18:46 UTC (rev 11155) @@ -13,7 +13,7 @@ } sub usage { - return '<cmd> <object> [norefund]'; + return '<cmd> <object> [norefund] <reason>'; } sub args_desc { @@ -28,6 +28,9 @@ 'norefund' => 'For "cancel" only, an optional flag that specifies ' . 'not to issue token refund to the promotion author.', + + 'reason' => + 'Why you are doing this.', ]; } @@ -41,6 +44,7 @@ my $entry = $args{'entry'}; my $refund = $args{'refund'}; + my $reason = $args{'reason'}; # refund defaults to 1 $refund = 1 unless defined $refund; @@ -49,6 +53,7 @@ my $message = 'admin cancel: ' . $entry->url; $message .= ', without refund' unless $refund; + $message .= '. Reason: '. $reason if $reason; LJ::statushistory_add( $entry->poster, $admin, 'selfpromo', $message ); @@ -61,6 +66,7 @@ sub execute { my ( $self, $cmd, $object, @args_remainder ) = @_; + my $admin = LJ::get_remote(); if ( ! defined $cmd || $cmd eq '' ) { return $self->error('No command specified'); @@ -90,21 +96,22 @@ return $self->error("Invalid object $object passed"); } - my $norefund = 0; + my ($norefund, $reason) = 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'"); + if ( $arg eq 'norefund' ) { + $norefund = 1; + shift @args_remainder; } - $norefund = 1; + $reason = join ' ', @args_remainder if @args_remainder; } + unless ( $reason ) { + return $self->error("Insufficient arguments"); + } + LJ::Pay::SelfPromo->check_current_entry; my $current_entry = LJ::Pay::SelfPromo->current_entry; @@ -126,7 +133,7 @@ $entry->url . ' is not the entry currently promoted' ); } - $self->_cancel_entry( 'entry' => $entry, 'refund' => !$norefund ); + $self->_cancel_entry( 'entry' => $entry, 'refund' => !$norefund, 'reason' => $reason ); $self->info( $entry->url . ' cancelled successfully' ); return 1; @@ -142,10 +149,11 @@ { $self->info('The ban will affect the currently promoted ' . 'entry, so cancelling that.'); - $self->_cancel_entry( 'entry' => $current_entry ); + $self->_cancel_entry( 'entry' => $current_entry, 'reason' => $reason ); } $u->set_prop( 'selfpromo_banned' => 1 ); + LJ::statushistory_add( $u, $admin, 'selfpromo', 'admin banned user. Reason: '. $reason ); $self->info( $u->display_name . ' banned successfully.'); return 1; @@ -160,10 +168,11 @@ { $self->info('The ban will affect the currently promoted ' . 'entry, so cancelling that.'); - $self->_cancel_entry( 'entry' => $current_entry ); + $self->_cancel_entry( 'entry' => $current_entry, 'reason' => $reason ); } $entry->set_prop( 'selfpromo_banned' => 1 ); + LJ::statushistory_add( $entry->journal, $admin, 'selfpromo', 'admin banned entry: '. $entry->url .'. Reason: '. $reason ); $self->info( $entry->url . ' banned successfully.'); return 1; @@ -175,12 +184,14 @@ if ( $cmd eq 'unban' ) { if ( $object->isa('LJ::User') ) { $object->clear_prop('selfpromo_banned'); + LJ::statushistory_add( $object, $admin, 'selfpromo', 'admin banned user. Reason: '. $reason ); $self->info( $object->display_name . ' unbanned successfully.'); return 1; } if ( $object->isa('LJ::Entry') ) { $object->set_prop( 'selfpromo_banned' => undef ); + LJ::statushistory_add( $object->journal, $admin, 'selfpromo', 'admin unbanned entry: '. $object->url .'. Reason: '. $reason ); $self->info( $object->url . ' unbanned successfully.'); return 1; }