Either deletes or notifies site administrators if it was the last group of a xnet...
authorStéphane Jacob <sj@m4x.org>
Sat, 7 Aug 2010 16:17:04 +0000 (18:17 +0200)
committerStéphane Jacob <sj@m4x.org>
Sat, 7 Aug 2010 17:31:45 +0000 (19:31 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
configs/mails.conf
modules/xnetgrp.php
templates/xnetgrp/unsubscription.mail.tpl [new file with mode: 0644]

index 059b0d9..459d521 100644 (file)
@@ -62,6 +62,10 @@ cc=validation+googleapps@polytechnique.org
 [xnet_unsubscription]
 from="Gestion des groupes X sur Polytechnique.net" <support@polytechnique.org>
 
+[xnet_unsubscription_account]
+from=br@staff.polytechnique.org
+to=br@staff.polytechnique.org
+
 [registration]
 from="Webmaster Polytechnique.org" <web@polytechnique.org>
 to=registration+watch@staff.m4x.org
index 2ec9e2c..dbb2d07 100644 (file)
@@ -834,11 +834,34 @@ class XnetGrpModule extends PLModule
             S::assert_xsrf_token();
         }
 
+        $hasSingleGroup = $user->hasSingleGroup();
+
         if ($this->unsubscribe($user)) {
             $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe&nbsp;!");
         } else {
             $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent&nbsp;!");
         }
+
+        // Either deletes or notifies site administrators if it was the last group
+        // of a xnet account.
+        if ($user->type == 'xnet' && $hasSingleGroup) {
+            if ($user->state == 'pending') {
+                // If the user has never logged in the site, we delete her account.
+                XDB::execute('DELETE FROM  acounts
+                                    WHERE  uid = {?}',
+                             $user->id());
+            } else {
+                // It the user has already logged in the site, we notify site
+                // administrators that there is a new xnet account without any
+                // group.
+                global $globals;
+                $mailer = new PlMailer('xnetgrp/unsubscription.mail.tpl');
+                $mailer->assign('user', $user);
+                $mailer->assign('groupId', $globals->asso('id'));
+                $mailer->assign('groupName', $globals->asso('nom'));
+                $mailer->send();
+            }
+        }
     }
 
     private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login)
diff --git a/templates/xnetgrp/unsubscription.mail.tpl b/templates/xnetgrp/unsubscription.mail.tpl
new file mode 100644 (file)
index 0000000..2e8e722
--- /dev/null
@@ -0,0 +1,33 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2010 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{config_load file="mails.conf" section="xnet_unsubscription_account"}
+{if $mail_part eq 'head'}
+{from full=#from#}
+{to full=#to#}
+{subject text="Nouveau compte xnet sans groupe."}
+{elseif $mail_part eq 'wiki'}
+Bonjour,
+
+{$user->fullName()} (hruid : {$user->hruid}) vient d'être désinscrit du groupe {$groupName} (id : {$groupName}). Son compte a été conservé bien qu'il ne soit plus inscrit à aucun groupe.
+
+{* vim:set et sw=2 sts=2 sws=2: *}