From: Stéphane Jacob Date: Fri, 29 Apr 2011 12:31:51 +0000 (+0200) Subject: Enables creation of multiple Xnet accounts for groups. X-Git-Tag: xorg/1.1.1~44 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c329751f62f22c9ece9cd351f2a93d3b7d1d1347;p=platal.git Enables creation of multiple Xnet accounts for groups. Signed-off-by: Stéphane Jacob --- diff --git a/ChangeLog b/ChangeLog index 9a99433..e6308bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ ================================================================================ VERSION 1.1.1 XX XX XXXX +New: + + * XnetGrp: + - Enables creation of multiple Xnet accounts for groups -JAC + Bug/Wish: * Auth: diff --git a/bin/cron/cron_xnet_accounts.php b/bin/cron/cron_xnet_accounts.php new file mode 100755 index 0000000..4ccc4fc --- /dev/null +++ b/bin/cron/cron_xnet_accounts.php @@ -0,0 +1,59 @@ +#!/usr/bin/php5 -q +setTo($user['email']); + $mailer->assign('hash', $user['hash']); + $mailer->assign('hruid', $user['hruid']); + $mailer->assign('group', $user['group_name']); + $mailer->assign('sender_name', $user['sender_name']); + $mailer->send(); + + XDB::execute('UPDATE accounts + SET state = \'pending\' + WHERE uid = {?}', + $user['uid']); + + if ($i == $limit) { + $i = 0; + sleep(60); + } else { + ++$i; + } +} + + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/configs/platal.cron.in b/configs/platal.cron.in index f1e5936..4dd0058 100644 --- a/configs/platal.cron.in +++ b/configs/platal.cron.in @@ -41,4 +41,7 @@ WD=/home/web/prod/platal/bin/cron # Clean-up of our logging tables 45 0 1 * * web cd $WD; ./compliance.php | mail -e -s "Logging compliance" br@staff.m4x.org +# xnet accounts creation +0 * * * * web cd $WD; ./cron_xnet_accounts.php + # vim:set noet syntax=crontab ts=8 sw=8 sts=8 enc=utf-8: diff --git a/htdocs/images/icons/group_gear.gif b/htdocs/images/icons/group_gear.gif new file mode 100644 index 0000000..ccf6337 Binary files /dev/null and b/htdocs/images/icons/group_gear.gif differ diff --git a/include/validations/account.inc.php b/include/validations/account.inc.php index 6c380db..68b10a5 100644 --- a/include/validations/account.inc.php +++ b/include/validations/account.inc.php @@ -89,21 +89,9 @@ class AccountReq extends Validate public function commit() { $hash = rand_url_id(12); - XDB::execute('UPDATE accounts - SET state = \'pending\' - WHERE uid = {?}', - $this->uid); - XDB::execute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash) - VALUES ({?}, {?}, {?}, NOW(), {?})', - $this->uid, $this->hruid, $this->email, $hash); - - $mailer = new PlMailer('xnet/account.mail.tpl'); - $mailer->setTo($this->email); - $mailer->assign('hash', $hash); - $mailer->assign('hruid', $this->hruid); - $mailer->assign('group', $this->group); - $mailer->assign('user', $this->user); - $mailer->send(); + XDB::execute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) + VALUES ({?}, {?}, {?}, NOW(), {?}, {?}, {?})', + $this->uid, $this->hruid, $this->email, $hash, $this->user->fullName(), $this->group); return true; } diff --git a/include/validations/bulkaccounts.inc.php b/include/validations/bulkaccounts.inc.php new file mode 100644 index 0000000..b3fbcf2 --- /dev/null +++ b/include/validations/bulkaccounts.inc.php @@ -0,0 +1,125 @@ +group = $group; + $this->users = XDB::fetchAllAssoc('SELECT uid, hruid, email + FROM accounts + WHERE uid IN {?}', + $uids); + } + + // }}} + // {{{ function formu() + + public function formu() + { + return 'include/form.valid.bulk_accounts.tpl'; + } + + // }}} + // {{{ function _mail_subj + + protected function _mail_subj() + { + return "[Polytechnique.org] Création de comptes Polytechnique.net"; + } + + // }}} + // {{{ function _mail_body + + protected function _mail_body($isok) + { + if ($isok) { + return " Un email vient d'être envoyé aux personnes concernées pour qu'elles puissent activer leur compte sur Polytechnique.net."; + } else { + return " Nous n'avons pas jugé bon d'activer les comptes Polytechnique.net demandés."; + } + } + + // }}} + // {{{ function commit() + + public function commit() + { + $values = array(); + $i = 0; + foreach ($this->users as $user) { + $values[] = XDB::format('({?}, {?}, {?}, NOW(), {?}, {?}, {?})', + $user['uid'], $user['hruid'], $user['email'], rand_url_id(12), $this->user->fullName(), $this->group); + + if ($i == $this->limit) { + XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) + VALUES ' . implode(', ', $values)); + $i = 0; + $values = array(); + } else { + ++$i; + } + } + XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) + VALUES ' . implode(', ', $values)); + + return true; + } + + // }}} + // {{{ function isPending() + + static public function isPending($uid) + { + $res = XDB::iterRow('SELECT data + FROM requests + WHERE type = \'bulk_accounts\' + ORDER BY stamp'); + + while (list($data) = $res->next()) { + $request = Validate::unserialize($data); + foreach ($request->users as $user) { + if ($user['uid'] == $uid) { + return true; + } + } + } + return false; + } + + // }}} +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 08342a0..dd225ac 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -36,6 +36,7 @@ class XnetGrpModule extends PLModule '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'), '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'), '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_MDP, 'groupadmin'), + '%grp/directory/unact' => $this->make_hook('non_active', AUTH_MDP, 'groupadmin'), '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'), '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'), '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), @@ -509,6 +510,45 @@ class XnetGrpModule extends PLModule $page->assign('nonusers', $nonusers); } + function handler_non_active($page) + { + global $globals; + $page->changeTpl('xnetgrp/non_active.tpl'); + + $uids = XDB::fetchColumn('SELECT g.uid + FROM group_members AS g + INNER JOIN accounts AS a ON (a.uid = g.uid) + LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid) + WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL', + $globals->asso('id')); + foreach ($uids as $key => $uid) { + if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) { + unset($uids[$key]); + } + } + + if (Post::has('enable_accounts')) { + S::assert_xsrf_token(); + + $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids); + + $user = S::user(); + $group = Platal::globals()->asso('nom'); + $request = new BulkAccountsReq($user, $uids_to_enable, $group); + $request->submit(); + $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.'); + + foreach ($uids as $key => $uid) { + if (in_array($uid, $uids_to_enable)) { + unset($uids[$key]); + } + } + } + + $users = User::getBulkUsersWithUIDs($uids); + $page->assign('users', $users); + } + private function removeSubscriptionRequest($uid) { global $globals; @@ -869,7 +909,7 @@ class XnetGrpModule extends PLModule FROM register_pending_xnet WHERE uid = {?}', $user->id()); - $requested = AccountReq::isPending($user->id()); + $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id()); if ($active || $pending || $requested) { return false; diff --git a/templates/include/form.valid.bulk_accounts.tpl b/templates/include/form.valid.bulk_accounts.tpl new file mode 100644 index 0000000..59c27a4 --- /dev/null +++ b/templates/include/form.valid.bulk_accounts.tpl @@ -0,0 +1,37 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 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 *} +{* *} +{**************************************************************************} + + + Groupe demandeur : + {$valid->group} + + + Adresses emails : + + | + {foreach from=$valid->users item=user} +  {$user.email} | + {/foreach} + + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnet/account.mail.tpl b/templates/xnet/account.mail.tpl index cdea70d..0746413 100644 --- a/templates/xnet/account.mail.tpl +++ b/templates/xnet/account.mail.tpl @@ -29,7 +29,7 @@ {elseif $mail_part eq 'text'} Bonjour, -{$user->fullName()} nous a demandé de vous créer un compte pour que vous puissiez disposer pleinement de toutes les fonctionnalités liées au groupe {$group}. +{$sender_name} nous a demandé de vous créer un compte pour que vous puissiez disposer pleinement de toutes les fonctionnalités liées au groupe {$group}. Après activation, vos paramètres de connexion seront : diff --git a/templates/xnetgrp/annuaire.tpl b/templates/xnetgrp/annuaire.tpl index d18bffd..f86c54c 100644 --- a/templates/xnetgrp/annuaire.tpl +++ b/templates/xnetgrp/annuaire.tpl @@ -40,6 +40,12 @@ Le groupe {$asso->nom} compte {$nb_tot} membres : Synchroniser avec les listes +
  • + + {icon name=group_gear title="Lister les membres du groupe sans compte actif"} + Lister les membres du groupe sans compte actif + +
  • {if $asso->has_ml}
  • diff --git a/templates/xnetgrp/non_active.tpl b/templates/xnetgrp/non_active.tpl new file mode 100644 index 0000000..cd71c74 --- /dev/null +++ b/templates/xnetgrp/non_active.tpl @@ -0,0 +1,79 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 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 *} +{* *} +{**************************************************************************} + +{if $users|@count} +
    + {xsrf_token_field} + + + + + + + {foreach from=$users item=user} + + + + + + {/foreach} + + + +
    NomEmail + {icon name="arrow_refresh" title="Tout (dé)cocher"} +
    {profile user=$user promo=true}{$user->email}
    + +
    + + + +
    +{else} +

    Tous les inscrits au groupe ont un compte leur permettant d'accéder aux pages du groupe.

    +{/if} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/upgrade/1.1.1/13_bulk_xnet_account.sql b/upgrade/1.1.1/13_bulk_xnet_account.sql new file mode 100644 index 0000000..2615e13 --- /dev/null +++ b/upgrade/1.1.1/13_bulk_xnet_account.sql @@ -0,0 +1,4 @@ +ALTER TABLE register_pending_xnet ADD COLUMN sender_name VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE register_pending_xnet ADD COLUMN group_name VARCHAR(255) NOT NULL DEFAULT ''; + +-- vim:set syntax=mysql: