From da2fff3814d0963ae6aa8a03a45c867c648d0eb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sat, 4 Jun 2011 23:55:18 +0200 Subject: [PATCH] Fixes homonyms handling. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit By the way, factorises all warning and correcting homonyms related functions. Signed-off-by: Stéphane Jacob --- bin/cron/homonyms.php | 4 +- configs/platal.cron.in | 2 +- include/validations/homonymes.inc.php | 55 +++++++------------ modules/admin.php | 24 ++++---- modules/admin/homonyms.inc.php | 88 +++++++++++++++++++++++++----- templates/admin/homonymes.tpl | 34 +----------- templates/include/form.valid.homonymes.tpl | 2 +- 7 files changed, 109 insertions(+), 100 deletions(-) diff --git a/bin/cron/homonyms.php b/bin/cron/homonyms.php index 1c2177b..fd7bb48 100755 --- a/bin/cron/homonyms.php +++ b/bin/cron/homonyms.php @@ -21,14 +21,14 @@ ***************************************************************************/ /** - * Requires destruction of aliases: a first notification 10 days before + * Requires destruction of aliases: a first notification 7 days before * destruction, a second on the date. */ require 'connect.db.inc.php'; $resRobot = XDB::iterator("SELECT uid, email, expire FROM email_source_account - WHERE (expire = NOW() + INTERVAL 7 DAY OR expire <= NOW())"); + WHERE expire <= NOW() + INTERVAL 7 DAY"); while ($old = $resRobot->next()) { $res = XDB::query('SELECT a.hruid FROM homonyms_list AS h diff --git a/configs/platal.cron.in b/configs/platal.cron.in index 4dd0058..a5796e0 100644 --- a/configs/platal.cron.in +++ b/configs/platal.cron.in @@ -30,7 +30,7 @@ WD=/home/web/prod/platal/bin/cron 15 * * * * web cd $WD; ./newsletters.send.php | mail -e -s "Envoi des NLs des groupes" br@staff.m4x.org # homonymes -0 0 4 * * web cd $WD; ./homonyms.php +0 0 * * 1 web cd $WD; ./homonyms.php # ml moderation * * * * * web cd $WD; ./cron_ml_moderate.php > /dev/null diff --git a/include/validations/homonymes.inc.php b/include/validations/homonymes.inc.php index b7e189c..33e8da1 100644 --- a/include/validations/homonymes.inc.php +++ b/include/validations/homonymes.inc.php @@ -25,7 +25,7 @@ class HomonymeReq extends Validate { // {{{ properties - public $loginbis; + public $email; public $homonymes_hruid; public $warning = true; public $rules = "Accepter, sauf cas particulier d'utilisateur dont l'homonymie est traité plus … manuellement."; @@ -33,14 +33,14 @@ class HomonymeReq extends Validate // }}} // {{{ constructor - public function __construct(User $_user, $_loginbis, $_homonymes_hruid, $warning=true) + public function __construct(User $_user, $_email, $_homonymes_hruid, $warning = true) { $this->warning = $warning; parent::__construct($_user, true, $this->title()); $this->refuse = false; - $this->loginbis = $_loginbis; + $this->email = $_email; $this->homonymes_hruid = $_homonymes_hruid; } @@ -67,7 +67,7 @@ class HomonymeReq extends Validate { return "[Polytechnique.org/Support] " . ($this->warning ? "Dans une semaine : suppression de l'alias " : "Mise en place du robot") - . " $loginbis@" . $this->user->mainEmailDomain(); + . " $email@" . $this->user->mainEmailDomain(); } // }}} @@ -79,11 +79,11 @@ class HomonymeReq extends Validate " Comme nous t'en avons informé par email il y a quelques temps, pour respecter nos engagements en terme d'adresses email devinables, -tu te verras bientôt retirer l'alias " . $this->loginbis . "@" . $this->user->mainEmailDomain() . " pour +tu te verras bientôt retirer l'alias " . $this->email . "@" . $this->user->mainEmailDomain() . " pour ne garder que " . $this->user->forlifeEmail() . ". -Toute personne qui écrira à " . $this->loginbis . "@" . $this->user->mainEmailDomain() . " recevra la -réponse d'un robot qui l'informera que " . $this->loginbis . "@" . $this->user->mainEmailDomain() . " +Toute personne qui écrira à " . $this->email . "@" . $this->user->mainEmailDomain() . " recevra la +réponse d'un robot qui l'informera que " . $this->email . "@" . $this->user->mainEmailDomain() . " est ambigu pour des raisons d'homonymie et signalera ton email exact."; } @@ -92,42 +92,25 @@ est ambigu pour des raisons d'homonymie et signalera ton email exact."; protected function sendmail($isok) { - if (!$isok) return false; - global $globals; - $mailer = new PlMailer; - $cc = "support+homonyme@" . $globals->mail->domain; - $from = "\"Support Polytechnique.org\" <$cc>"; - $mailer->setSubject($this->_mail_subj()); - $mailer->setFrom($from); - $mailer->addTo("\"{$this->user->fullName()}\" <{$this->user->bestEmail()}>"); - $mailer->addCc($cc); - - $body = $this->user->displayName() . ",\n\n" - . $this->_mail_body($isok) - . (Env::has('comm') ? "\n\n".Env::v('comm') : '') - . "\n\nCordialement,\n\n-- \nL'équipe de Polytechnique.org\n"; - - $mailer->setTxtBody(wordwrap($body)); - $mailer->send(); + if (!$isok) { + return false; + } + + Platal::load('admin', 'homonyms.inc.php'); + if ($this->warning) { + send_warning_homonym($this->user, $this->email); + } else { + send_robot_homonym($this->user, $this->email); + } } // }}} // {{{ function commit() public function commit() { - Platal::load('admin', 'homonyms.inc.php'); if (!$this->warning) { - require_once 'emails.inc.php'; - - XDB::execute('DELETE FROM email_source_account - WHERE email = {?} AND type = \'alias\'', - $this->loginbis); - XDB::execute('INSERT INTO email_source_other (hrmid, email, domain, type, expire) - SELECT {?}, {?}, id, \'homonym\', NOW() - FROM email_virtual_domains - WHERE name = {?}', - User::makeHomonymHrmid($this->loginbis), $this->loginbis, $this->user->mainEmailDomain()); - fix_bestalias($this->user); + Platal::load('admin', 'homonyms.inc.php'); + fix_homonym($this->user, $this->email); } return true; diff --git a/modules/admin.php b/modules/admin.php index 9778979..81c0182 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -969,14 +969,12 @@ class AdminModule extends PLModule // When we have a valid target, prepare emails. if ($target) { - require_once 'emails.inc.php'; // Examine what operation needs to be performed. switch ($op) { case 'mail': S::assert_xsrf_token(); - send_warning_homonyme($user, $loginbis); - fix_bestalias($user); + send_warning_homonym($user, $loginbis); $op = 'list'; $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.'); break; @@ -984,16 +982,8 @@ class AdminModule extends PLModule case 'correct': S::assert_xsrf_token(); - XDB::execute('DELETE FROM email_source_account - WHERE email = {?} AND type = \'alias\'', - $loginbis); - XDB::execute('INSERT INTO email_source_other (hrmid, email, domain, type, expire) - SELECT {?}, {?}, id, \'homonym\', NOW() - FROM email_virtual_domains - WHERE name = {?}', - User::makeHomonymHrmid($loginbis), $loginbis, $user->mainEmailDomain()); - fix_bestalias($user); - send_robot_homonyme($user, $loginbis); + fix_homonym($user, $loginbis); + send_robot_homonym($user, $loginbis); $op = 'list'; $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.'); break; @@ -1028,6 +1018,14 @@ class AdminModule extends PLModule } $page->assign_by_ref('homonyms_to_fix', $homonyms_to_fix); } + + if ($op == 'correct-conf') { + $page->assign('robot_mail_text', get_robot_mail_text($user, $loginbis)); + } + + if ($op == 'mail-conf') { + $page->assign('warning_mail_text', get_warning_mail_text($user, $loginbis)); + } } function handler_deaths($page, $promo = 0, $validate = false) diff --git a/modules/admin/homonyms.inc.php b/modules/admin/homonyms.inc.php index ea4a1c7..2f99303 100644 --- a/modules/admin/homonyms.inc.php +++ b/modules/admin/homonyms.inc.php @@ -19,36 +19,94 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function select_if_homonym(PlUser $user) { +function select_if_homonym(PlUser $user) +{ return XDB::fetchOneCell('SELECT email FROM email_source_account WHERE uid = {?} AND expire IS NOT NULL', $user->id()); } -function send_warning_homonyme(PlUser $user, $loginbis) { - global $globals; - $cc = "support+homonyme@" . $globals->mail->domain; - $FROM = "\"Support Polytechnique.org\" <$cc>"; +function send_warning_homonym(PlUser $user, $email) +{ + $cc = "validation+homonyme@" . Platal::globals()->mail->domain; + $from = "\"Support Polytechnique.org\" <$cc>"; + $body = Post::has('mailbody') ? Post::t('mailbody') : get_warning_mail_text($user, $email); + $mymail = new PlMailer(); - $mymail->setFrom($FROM); + $mymail->setFrom($from); $mymail->addCc($cc); - $mymail->setSubject("Dans 2 semaines, suppression de $loginbis@" . $user->mainEmailDomain()); - $mymail->setTxtBody(Env::v('mailbody')); + $mymail->setSubject("Dans 1 semaine, suppression de $email@" . $user->mainEmailDomain()); + $mymail->setTxtBody($body); $mymail->sendTo($user); } -function send_robot_homonyme(PlUser $user, $loginbis) { - global $globals; - $cc = "support+homonyme@" . $globals->mail->domain; - $FROM = "\"Support Polytechnique.org\" <$cc>"; +function send_robot_homonym(PlUser $user, $email) +{ + $cc = "validation+homonyme@" . Platal::globals()->mail->domain; + $from = "\"Support Polytechnique.org\" <$cc>"; + $body = Post::has('mailbody') ? Post::t('mailbody') : get_robot_mail_text($user, $email); + $user = User::getSilentWithUID($user->id()); + $mymail = new PlMailer(); - $mymail->setFrom($FROM); - $mymail->setSubject("Mise en place du robot $loginbis@" . $user->mainEmailDomain()); + $mymail->setFrom($from); + $mymail->setSubject("Mise en place du robot $email@" . $user->mainEmailDomain()); $mymail->addCc($cc); - $mymail->setTxtBody(Env::v('mailbody')); + $mymail->setTxtBody($body); $mymail->sendTo($user); } +function get_warning_mail_text(PlUser $user, $email) +{ + $display_name = $user->displayName(); + $former_email = $email . '@' . $user->mainEmailDomain(); + $forlife_email = $user->forlifeEmail(); + + return "$display_name,\n\nComme nous t'en avons informé par email il y a " + . "quelques temps, pour respecter nos engagements en terme d'adresses " + . "email devinables, tu te verras bientôt retirer l'alias $former_email " + . "pour ne garder que $forlife_email.\n\nToute personne qui écrira à " + . "$former_email recevra la réponse d'un robot qui l'informera que " + . "$former_email est ambigu pour des raisons d'homonymie et signalera " + . "ton email exact.\n\nCordialement,\n-- \nl'équipe de Polytechnique.org" + . "\nLe portail des élèves & anciens élèves de l'École polytechnique"; +} + +function get_robot_mail_text(PlUser $user, $email) +{ + $display_name = $user->displayName(); + $former_email = $email . '@' . $user->mainEmailDomain(); + + return "$display_name,\n\nComme nous t'en avons informé par email il y a " + . "quelques temps, nous t'avons retiré de façon définitive l'adresse " + . "$former_email.\n\nToute personne qui écrit à $former_email reçoit " + . "la réponse d'un robot qui l'informe que $former_email est ambigu " + . "pour des raisons d'homonymie et indique ton email exact.\n\nTu peux " + . "faire l'essai toi-même en écrivant à $former_email.\n\nCordialement," + . "\n-- \nl'équipe de Polytechnique.org" + . "\nLe portail des élèves & anciens élèves de l'École polytechnique"; +} + +function fix_homonym(PlUser $user, $email) +{ + XDB::execute('DELETE FROM email_source_account + WHERE email = {?} AND type = \'alias\'', + $email); + + $hrmid = User::makeHomonymHrmid($email); + XDB::execute('INSERT INTO email_source_other (hrmid, email, domain, type, expire) + SELECT {?}, {?}, id, \'homonym\', NOW() + FROM email_virtual_domains + WHERE name = {?}', + $hrmid, $email, $user->mainEmailDomain()); + XDB::execute("INSERT INTO email_redirect_other (hrmid, redirect, type, action) + VALUES ({?}, '', 'homonym', 'homonym')", + $hrmid); + + + require_once 'emails.inc.php'; + fix_bestalias($user); +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/templates/admin/homonymes.tpl b/templates/admin/homonymes.tpl index 8babe84..17639c7 100644 --- a/templates/admin/homonymes.tpl +++ b/templates/admin/homonymes.tpl @@ -103,22 +103,7 @@ - + @@ -139,22 +124,7 @@ L'équipe Polytechnique.org - + diff --git a/templates/include/form.valid.homonymes.tpl b/templates/include/form.valid.homonymes.tpl index 9a5da91..7037bfa 100644 --- a/templates/include/form.valid.homonymes.tpl +++ b/templates/include/form.valid.homonymes.tpl @@ -23,7 +23,7 @@ Adresse litigieuse : - {$valid->loginbis}@polytechnique.org + {$valid->email}@polytechnique.org -- 2.1.4