Committer: anazarov
LJSV-1696: Add "reason" arg to some admin console commandsU trunk/cgi-bin/LJ/Console/Command/ChangeCommunityAdmin.pm U trunk/cgi-bin/LJ/Console/Command/ChangeJournalStatus.pm U trunk/cgi-bin/LJ/Console/Command/ChangeJournalType.pm U trunk/cgi-bin/LJ/Console/Command/SetOwner.pm
Modified: trunk/cgi-bin/LJ/Console/Command/ChangeCommunityAdmin.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/ChangeCommunityAdmin.pm 2011-10-11 11:56:45 UTC (rev 20284) +++ trunk/cgi-bin/LJ/Console/Command/ChangeCommunityAdmin.pm 2011-10-11 11:58:56 UTC (rev 20285) @@ -11,9 +11,10 @@ sub args_desc { [ 'community' => "The username of the community.", 'new_owner' => "The username of the new owner of the community.", + 'reason' => "Why you are changing community admin (optional)." ] } -sub usage { '<community> <new_owner>' } +sub usage { '<community> <new_owner> [ <reason> ]' } sub can_execute { my $remote = LJ::get_remote(); @@ -23,8 +24,8 @@ sub execute { my ($self, $comm, $maint, @args) = @_; - return $self->error("This command takes exactly two arguments. Consult the reference") - unless $comm && $maint && scalar(@args) == 0; + return $self->error("This command takes two mandatory arguments. Consult the reference") + unless $comm && $maint; my $ucomm = LJ::load_user($comm); my $unew = LJ::load_user($maint); @@ -54,10 +55,12 @@ # log to statushistory my $remote = LJ::get_remote(); - LJ::statushistory_add($ucomm, $remote, "communityxfer", "Changed maintainer to ". $unew->user ." (". $unew->id .")."); - LJ::statushistory_add($unew, $remote, "communityxfer", "Control of '". $ucomm->user ."' (". $ucomm->id .") given."); + my $reason = ''; + $reason = join ' ', ' Reason:', @args if @args; + LJ::statushistory_add($ucomm, $remote, "communityxfer", "Changed maintainer to ". $unew->user ." (". $unew->id .")." . $reason); + LJ::statushistory_add($unew, $remote, "communityxfer", "Control of '". $ucomm->user ."' (". $ucomm->id .") given." . $reason); - return $self->print("Transferred maintainership of '" . $ucomm->user . "' to '" . $unew->user . "'."); + return $self->print("Transferred maintainership of '" . $ucomm->user . "' to '" . $unew->user . "'". $reason); } 1; Modified: trunk/cgi-bin/LJ/Console/Command/ChangeJournalStatus.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/ChangeJournalStatus.pm 2011-10-11 11:56:45 UTC (rev 20284) +++ trunk/cgi-bin/LJ/Console/Command/ChangeJournalStatus.pm 2011-10-11 11:58:56 UTC (rev 20285) @@ -11,9 +11,10 @@ sub args_desc { [ 'account' => "The account to update.", 'status' => "One of 'normal', 'memorial' (no new entries), 'locked' (no new entries or comments), or 'readonly' (no new entries or comments, but can log in and delete entries and comments), 'deleted'.", + 'reason' => "Why you are changing journal status (optional).", ] } -sub usage { '<account> <status>' } +sub usage { '<account> <status> [ <reason> ]' } sub can_execute { my $remote = LJ::get_remote(); @@ -23,8 +24,8 @@ sub execute { my ($self, $user, $status, @args) = @_; - return $self->error("This command takes exactly two arguments. Consult the reference") - unless $user && $status && scalar(@args) == 0; + return $self->error("This command takes two mandatory arguments. Consult the reference") + unless $user && $status; my $u = LJ::load_user($user); return $self->error("Invalid username: $user") @@ -43,7 +44,9 @@ # update statushistory first so we have the old statusvis my $remote = LJ::get_remote(); - LJ::statushistory_add($u, $remote, "journal_status", "Changed status to $status from " . $u->statusvis); + my $reason = ''; + $reason = join ' ', '. Reason:', @args if @args; + LJ::statushistory_add($u, $remote, "journal_status", "Changed status to $status from " . $u->statusvis. $reason); # we cannot call set_statusvis directly - it does not make all needed hooks, only sets statusvis # so call set_* method @@ -61,7 +64,7 @@ die "No call to setter for $statusvis case"; } - return $self->print("Account has been marked as $status"); + return $self->print("Account has been marked as $status". $reason); } 1; Modified: trunk/cgi-bin/LJ/Console/Command/ChangeJournalType.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/ChangeJournalType.pm 2011-10-11 11:56:45 UTC (rev 20284) +++ trunk/cgi-bin/LJ/Console/Command/ChangeJournalType.pm 2011-10-11 11:58:56 UTC (rev 20285) @@ -12,10 +12,11 @@ 'journal' => "The username of the journal that type is changing.", 'type' => "Either 'person', 'community', or 'news'.", 'owner' => "The person to become the maintainer of the community/news journal. If changing to type 'person', the account will adopt the email address and password of the owner.", - 'force' => "Specify this to create a community from a non-empty journal. The maintainer of the community will be the owner of the journal's entries." + 'force' => "Specify this to create a community from a non-empty journal. The maintainer of the community will be the owner of the journal's entries (optional).", + 'reason' => "Why you are changing journal type (optional).", ] } -sub usage { '<journal> <type> <owner> [force]' } +sub usage { '<journal> <type> <owner> [ force ] [ <reason> ]' } sub can_execute { my $remote = LJ::get_remote(); @@ -26,9 +27,12 @@ my ($self, $user, $type, $owner, @args) = @_; my $remote = LJ::get_remote(); - return $self->error("This command takes from three to four arguments. Consult the reference.") - unless $user && $type && $owner && (@args==0 || @args==1 && $args[0] eq 'force' && $type eq 'community'); + return $self->error("This command takes three mandatory arguments. Consult the reference.") + unless $user && $type && $owner; + return $self->error("Keyword 'force' can be used only with type community.") + if @args >= 1 and $args[0] eq 'force' and $type ne 'community'; + return $self->error("Type argument must be 'person', 'community', or 'news'.") unless $type =~ /^(?:person|community|news)$/; @@ -59,6 +63,12 @@ return $self->error("Owner email address isn't validated.") unless $ou->is_validated; + my $force; + if ( @args and $args[0] eq 'force' ) { + $force = 1; + shift @args; + } + my $dbh = LJ::get_db_writer(); ############################# @@ -78,7 +88,7 @@ my $count = $dbcr->selectrow_array('SELECT COUNT(*) FROM log2 WHERE journalid = ? AND posterid = journalid', undef, $u->id); if ($count) { - if ($args[0] eq 'force') { + if ($force) { $u->do("UPDATE log2 SET posterid = ? WHERE journalid = ? AND posterid = journalid", undef, $ou->id, $u->id) or return $self->error($DBI::errstr); $self->info("$count entries of user '$u->{user}' belong to '$ou->{user}' now"); @@ -156,10 +166,12 @@ ############################# # register this action in statushistory my $msg = "account '" . $u->user . "' converted to $type"; - $msg .= " (owner/parent is '" . $ou->user . "')"; - LJ::statushistory_add($u, $remote, "change_journal_type", $msg); + $msg = " (owner/parent is '" . $ou->user . "')"; + my $reason = ''; + $reason = join ' ', '. Reason:', @args if @args; + LJ::statushistory_add($u, $remote, "change_journal_type", $msg. $reason); - return $self->print("User " . $u->user . " converted to a $type account."); + return $self->print("User " . $u->user . " converted to a $type account". $reason); } 1; Modified: trunk/cgi-bin/LJ/Console/Command/SetOwner.pm =================================================================== --- trunk/cgi-bin/LJ/Console/Command/SetOwner.pm 2011-10-11 11:56:45 UTC (rev 20284) +++ trunk/cgi-bin/LJ/Console/Command/SetOwner.pm 2011-10-11 11:58:56 UTC (rev 20285) @@ -11,10 +11,10 @@ sub args_desc { [ 'community' => "The community for which to set supermaintainer", 'username' => "The username of the account to set as supermaintainer", - 'reason' => "Why you're setting the account as supermaintainer.", + 'reason' => "Why you're setting the account as supermaintainer (optional).", ] } -sub usage { '<community> <username> <reason>' } +sub usage { '<community> <username> [ <reason> ]' } sub can_execute { my $remote = LJ::get_remote(); @@ -22,10 +22,10 @@ } sub execute { - my ($self, $comm, $user, $reason, @args) = @_; + my ($self, $comm, $user, @args) = @_; - return $self->error("This command takes two arguments. Consult the reference.") - unless $comm && $user && scalar(@args) == 0; + return $self->error("This command takes two mandatory arguments. Consult the reference.") + unless $comm && $user; my $remote = LJ::get_remote(); my $c = LJ::load_user($comm); @@ -59,13 +59,15 @@ } } - LJ::statushistory_add($c, $remote, 'set_owner', "Console set owner and new maintainer as ".$u->{user}); + my $reason = ''; + $reason = join ' ', '. Reason: ', @args if @args; + LJ::statushistory_add($c, $remote, 'set_owner', "Console set owner and new maintainer as " . $u->{'user'}. $reason); LJ::set_rel($c->{userid}, $u->{userid}, 'S'); ## Set a new supermaintainer as maintainer too. LJ::set_rel($c->{userid}, $u->{userid}, 'A'); $c->log_event('maintainer_add', { actiontarget => $u->{userid}, remote => $remote }); - $self->print("User '$user' setted as supermaintainer for '$comm'."); + $self->print("User '$user' setted as supermaintainer for '$comm'". $reason); return 1; }