Типа я (zilogic) wrote in changelog,
Типа я
zilogic
changelog

[ljcom] r13025: LJSUP-14527: Improve reset_password admi...

Committer: amyshkin
LJSUP-14527: Improve reset_password admin console command
U   trunk/cgi-bin/LJ/Sendmail.pm
U   trunk/htdocs/admin/sendmail/send.bml
Modified: trunk/cgi-bin/LJ/Sendmail.pm
===================================================================
--- trunk/cgi-bin/LJ/Sendmail.pm	2012-12-11 15:10:21 UTC (rev 13024)
+++ trunk/cgi-bin/LJ/Sendmail.pm	2012-12-12 08:19:39 UTC (rev 13025)
@@ -18,8 +18,13 @@
 
     push @cansend, 'community' if LJ::check_priv($u, "supportread", "community");
     push @cansend, 'support' if LJ::check_priv($u, "supportread", "support");
-    push @cansend, 'abuse' if LJ::check_priv($u, "supportread", "abuse");
 
+    if ( LJ::check_priv($u, "supportread", "abuse") ) {
+        push @cansend,
+             'abuse',
+             'console';
+    }
+
     # Grouping this check for now, but leaving it so
     # it could be split up in the future should a need
     # arise

Modified: trunk/htdocs/admin/sendmail/send.bml
===================================================================
--- trunk/htdocs/admin/sendmail/send.bml	2012-12-11 15:10:21 UTC (rev 13024)
+++ trunk/htdocs/admin/sendmail/send.bml	2012-12-12 08:19:39 UTC (rev 13025)
@@ -102,9 +102,11 @@
     foreach my $from (@cansend) {
         my $stocks = LJ::Sendmail::Stock::fetch_all(fromaddr => $from);
         my @stocks;
+
         foreach my $stock (@$stocks) {
             push @stocks, { title => LJ::ehtml($stock->title), body => $stock->body };
         }
+
         $map->{$from} = \@stocks;
     }
 
@@ -134,14 +136,15 @@
         $body .= "<tr><td><label for='from'>From:</label></td><td>";
 
         my @from = ("", "-- Select One --");
-        push @from, ('abuse' => "abuse\@$LJ::DOMAIN") if $cansend{'abuse'};
-        push @from, ('accounts' => "accounts\@$LJ::DOMAIN") if $cansend{'accounts'};
-        push @from, ('community' => "community\@$LJ::DOMAIN") if $cansend{'community'};
-        push @from, ('coppa' => "coppa\@$LJ::DOMAIN") if $cansend{'coppa'};
-        push @from, ('feedback' => "feedback\@$LJ::DOMAIN") if $cansend{'feedback'};
-        push @from, ('support' => "support\@$LJ::DOMAIN") if $cansend{'support'};
-        push @from, ('ljspotlight' => "ljspotlight\@$LJ::DOMAIN") if $cansend{'ljspotlight'};
-        push @from, ('livejournal' => "livejournal\@$LJ::DOMAIN") if $cansend{'livejournal'};
+        push @from, ('abuse'       => "abuse\@$LJ::DOMAIN")        if $cansend{'abuse'};
+        push @from, ('accounts'    => "accounts\@$LJ::DOMAIN")     if $cansend{'accounts'};
+        push @from, ('community'   => "community\@$LJ::DOMAIN")    if $cansend{'community'};
+        push @from, ('coppa'       => "coppa\@$LJ::DOMAIN")        if $cansend{'coppa'};
+        push @from, ('feedback'    => "feedback\@$LJ::DOMAIN")     if $cansend{'feedback'};
+        push @from, ('support'     => "support\@$LJ::DOMAIN")      if $cansend{'support'};
+        push @from, ('ljspotlight' => "ljspotlight\@$LJ::DOMAIN")  if $cansend{'ljspotlight'};
+        push @from, ('livejournal' => "livejournal\@$LJ::DOMAIN")  if $cansend{'livejournal'};
+        push @from, ('console'     => "do-not-reply\@$LJ::DOMAIN") if $cansend{'console'};
 
         my $selfrom = $edit_mode == 1 ? $POST{'from'} : $GET{'from'};
         $selfrom = "community" if !$selfrom && $cansend{'community'};
@@ -258,9 +261,11 @@
         $body .= "<tr><th style='text-align: left'>From:</th><td>";
 
         my $from = LJ::trim($POST{'from'});
+
         if ($cansend{$from}) {
             $body .= "$from\@$LJ::DOMAIN";
-        } else {
+        }
+        else {
             $errors = 1;
             $body .= "<font color='red'>Invalid address chosen</font>";
         }
@@ -268,6 +273,7 @@
         $body .= "</tr><tr><th style='text-align: left'>To:</th><td>";
 
         my @to;
+
         if (LJ::trim($POST{'user'}) ne '') {
             # Split on comma or comma space
             my @users = split(/,\s?/, LJ::trim($POST{'user'}));
@@ -285,32 +291,41 @@
             }
             $body .= join(", ", map { LJ::ljuser($_) . " (" . $_->email_raw . ")" } @to)
                 unless $errors;
-        } elsif (LJ::trim($POST{'maints'}) ne '') {
+        }
+        elsif (LJ::trim($POST{'maints'}) ne '') {
             my $u = LJ::load_user($POST{'maints'});
+
             if ($u->{journaltype} ne 'C') {
                 $body .= "<font color='red'>Community specified is not a community</font>";
-            } else {
+            }
+            else {
                 my $ids = LJ::load_rel_user($u->{userid}, 'A');
+
                 foreach (@$ids) {
                     my $maint = LJ::load_userid($_);
                     push @to, $maint;
                 }
+
                 $body .= "Maintainers of ";
                 $body .= LJ::ljuser($u) . " (";
                 $body .= join(", ", map { LJ::ljuser($_) . " (" . $_->email_raw . ")" } @to) . ")";
             }
-        } elsif (LJ::trim($POST{'email'}) ne '') {
+        }
+        elsif (LJ::trim($POST{'email'}) ne '') {
             # Split on comma or comma space
             my @addrs = split(/,\s?/, LJ::trim($POST{'email'}));
 
             my $emailerror = 0;
+
             foreach my $addr (@addrs) {
                 my @email_errors;
                 LJ::check_email($addr, \@email_errors);
+
                 if (@email_errors) {
                     $emailerror = 1;
                     last;
-                } else {
+                }
+                else {
                     push @to, $addr;
                 }
             }
@@ -320,26 +335,31 @@
                 $body .= "<font color='red'>";
                 $body .= "One of the email addresses input appears invalid.";
                 $body .= "</font>";
-            } else {
+            }
+            else {
                 $body .= join(', ', @to);
             }
-        } else {
+        }
+        else {
             $errors = 1;
             $body .= "<font color='red'>You must enter a recipient</font>";
         }
 
         my $bcc = LJ::trim($POST{'bcc'});
+
         if ($bcc ne '') {
             $body .= "<tr><th style='text-align: left'>Bcc:</th><td>";
 
             my @bcc_errors;
             LJ::check_email($bcc, \@bcc_errors);
+
             if (@bcc_errors) {
                 $errors = 1;
                 $body .= "<font color='red'>";
                 $body .= join(", ", @bcc_errors);
                 $body .= "</font>";
-            } else {
+            }
+            else {
                 $body .= $bcc;
             }
 
@@ -348,57 +368,68 @@
 
         my $request = LJ::trim($POST{'request'});
         $body .= "<tr><th style='text-align: left; white-space: nowrap'>Request #:</th><td>";
-            if ($request ne '') {
-                unless ($request =~ /^\d+$/) {
-                    $body .= "<font color='red'>Request id must be numeric</font>";
-                    $errors = 1;
-                } else {
-                    $body .= $request;
-                }
-            } else {
-                $body .= "<font color='orange'>No request specified</font>";
+
+        if ($request ne '') {
+            unless ($request =~ /^\d+$/) {
+                $body .= "<font color='red'>Request id must be numeric</font>";
+                $errors = 1;
             }
+            else {
+                $body .= $request;
+            }
+        }
+        else {
+            $body .= "<font color='orange'>No request specified</font>";
+        }
+
         $body .= "</td></tr>";
 
         my $subject = LJ::trim($POST{'subject'});
         $body .= "<tr><th style='text-align: left'>Subject:</th><td>";
+
         if ($subject eq '') {
             $body .= "<font color='red'>You must specify a subject</font>";
             $errors = 1;
-        } else {
+        }
+        else {
             $body .= $subject;
         }
+
         $body .= "</td></tr>";
 
         my $note = LJ::trim($POST{'note'});
         $body .= "<tr><th style='text-align: left'>Internal Note:</th><td>";
+
         if ($note eq '') {
             $body .= "<font color='grey'>(none)</font>";
-        } else {
+        }
+        else {
             $body .= $note;
         }
+
         $body .= "</td></tr>";
 
-
         my $message = LJ::trim($POST{'message'});
         $body .= "<tr><th style='vertical-align: top; text-align: left'>Message:</th><td>";
+
         if ($message eq '') {
             $body .= "<font color='red'>You must specify a message</font>";
             $errors = 1;
-        } else {
+        }
+        else {
             my $tmp_mess = $message;
             $tmp_mess =~ s/\r?\n/<br \/>\n/g;
             $tmp_mess =~ s/(\[\[$_\]\])/<b>$1<\/b>/g foreach qw(username realname email community);
             $body .= $tmp_mess;
         }
+
         $body .= "</td></tr>";
-
         $body .= "<tr><td colspan='2'>";
-
         $body .= "<form action='send.bml?action=send' method='post' id='preview'>";
 
         my @emails;
         my @users;
+
         foreach (@to) {
             if (LJ::isu($_)) {
                 push @emails, $_->email_raw;
@@ -409,10 +440,19 @@
             }
         }
 
-        $body .= LJ::html_hidden('from', $from, 'to', join(',', @emails), 'bcc', $bcc,
-                                 'subject', $subject, 'notes', $note, 'message', $message, 'email', $POST{'email'},
-                                 'maints', $POST{'maints'}, 'user', $POST{'user'}, 'request',
-                                 $request, 'users', join(',', @users));
+        $body .= LJ::html_hidden(
+            'from'    => $from,
+            'to'      => join(',', @emails),
+            'bcc'     => $bcc,
+            'subject' => $subject,
+            'notes'   => $note,
+            'message' => $message,
+            'email'   => $POST{'email'},
+            'maints'  => $POST{'maints'},
+            'user'    => $POST{'user'},
+            'request' => $request,
+            'users'   => join(',', @users),
+        );
 
         $body .= LJ::html_hidden('extra', $POST{'extra'}) if $POST{'extra'};
         $body .= LJ::form_auth();
@@ -444,14 +484,16 @@
         my @users  = split(',', $POST{'users'});
         my $comm = $POST{'maints'};
 
-        my %prettynames;
-        $prettynames{'abuse'} = "$LJ::SITENAMESHORT Abuse Prevention Team";
-        $prettynames{'accounts'} = "$LJ::SITENAMESHORT Accounts";
-        $prettynames{'community'} = "$LJ::SITENAMESHORT Community";
-        $prettynames{'coppa'} = "$LJ::SITENAMESHORT COPPA Enforcement";
-        $prettynames{'feedback'} = "$LJ::SITENAMESHORT Feedback";
-        $prettynames{'support'} = "$LJ::SITENAMESHORT Support Team";
-        $prettynames{'ljspotlight'} = "$LJ::SITENAMESHORT Spotlight";
+        my %prettynames = (
+            'abuse'       => "$LJ::SITENAMESHORT Abuse Prevention Team",
+            'accounts'    => "$LJ::SITENAMESHORT Accounts",
+            'community'   => "$LJ::SITENAMESHORT Community",
+            'coppa'       => "$LJ::SITENAMESHORT COPPA Enforcement",
+            'feedback'    => "$LJ::SITENAMESHORT Feedback",
+            'support'     => "$LJ::SITENAMESHORT Support Team",
+            'ljspotlight' => "$LJ::SITENAMESHORT Spotlight",
+            '' => "",
+        );
 
         my $fromname = $prettynames{$POST{'from'}};
 
@@ -463,25 +505,54 @@
             # that the message didn't bounce, only that the sendmail process didn't croak
 
             if(!LJ::send_mail({
-                'to' => $email,
-                'bcc' => $POST{'bcc'},
-                'from' => "$POST{'from'}\@$LJ::DOMAIN",
+                'to'       => $email,
+                'bcc'      => $POST{'bcc'},
+                'from'     => "$POST{'from'}\@$LJ::DOMAIN",
                 'fromname' => $fromname,
-                'charset' => "utf-8",
-                'subject' => $POST{'subject'},
-                'body' => $message,
+                'charset'  => "utf-8",
+                'subject'  => $POST{'subject'},
+                'body'     => $message,
             }))
             {
                 $status = "F";
                 push @errors, "<strong>Error:</strong><br />Mail not sent to $email";
             }
 
-            my $query = "INSERT INTO abuse_mail (mailid, userid, spid, status, timesent, mailto, " .
-                "subject, message, type) " .
-                "VALUES (NULL, ?, ?, ?, NOW(), ?, ?, ?, ?)";
+            my $query = "
+                INSERT INTO abuse_mail (
+                    mailid,
+                    userid,
+                    spid,
+                    status,
+                    timesent,
+                    mailto,
+                    subject,
+                    message,
+                    type
+                )
+                VALUES (
+                    NULL,
+                    ?,
+                    ?,
+                    ?,
+                    NOW(),
+                    ?,
+                    ?,
+                    ?,
+                    ?
+                )";
 
-            $dbh->do($query, undef, $remote->{'userid'}, $POST{'request'}, $status,
-                     $email, $POST{'subject'}, $message, $POST{'from'});
+            $dbh->do(
+                $query,
+                undef,
+                $remote->{'userid'},
+                $POST{'request'},
+                $status,
+                $email,
+                $POST{'subject'},
+                $message,
+                $POST{'from'},
+            );
 
             if ($dbh->err) {
                 my $error = $dbh->errstr;
@@ -518,7 +589,8 @@
                 $extranote = "(maintainers: @users)";
                 LJ::statushistory_add($c->{userid}, $remote->{userid}, 'email_sent', "$note $extranote") if $c;
             }
-        } else {
+        }
+        else {
             foreach (@emails) {
                 my $message = $POST{'message'};
                 $message =~ s/\[\[email\]\]/$_/g;
@@ -543,7 +615,8 @@
 
         if (@errors) {
             $body .= join("<br /><br />", @errors);
-        } else {
+        }
+        else {
             $body .= "Email(s) sent successfully";
         }
     };
@@ -553,12 +626,15 @@
     if (LJ::did_post()) {
         if ($GET{'action'} eq 'preview') {
             $preview->();
-        } elsif ($GET{'action'} eq 'edit') {
+        }
+        elsif ($GET{'action'} eq 'edit') {
             $compose->(1);
-        } elsif ($GET{'action'} eq 'send') {
+        }
+        elsif ($GET{'action'} eq 'send') {
             $send->();
         }
-    } else {
+    }
+    else {
         $compose->(0);
     }
 }

Tags: amyshkin, bml, ljcom, pm, zilogic
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