Allow edition of the email of the user from the admin page.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 4 Oct 2010 15:41:32 +0000 (17:41 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 4 Oct 2010 15:43:22 +0000 (17:43 +0200)
This is possible only if the user email is not managed by the site (so for
user without the 'mail' permission). Changing the email update the
subscription in mailman.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
bin/lists.rpc.py
modules/admin.php
templates/admin/user.tpl

index 8441ed4..5ce3c68 100755 (executable)
@@ -849,6 +849,27 @@ def get_all_user_lists(userdesc, perms, vhost, email):
             continue
     return result
 
+def change_user_email(userdesc, perms, vhost, from_email, to_email):
+    """ Change the email of a user
+            @root
+    """
+    from_email = from_email.lower()
+    to_email = to_email.lower()
+    for list in Utils.list_names():
+        try:
+            mlist = MailList.MailList(list, lock=0)
+        except:
+            continue
+        try:
+            mlist.Lock()
+            mlist.ApprovedChangeMemberAddress(from_email, to_email, 0)
+            mlist.Save()
+            mlist.Unlock()
+        except:
+            mlist.Unlock()
+    return 1
+
+
 def create_list(userdesc, perms, vhost, listname, desc, advertise, modlevel, inslevel, owners, members):
     """ Create a new list.
             @root
@@ -1041,6 +1062,7 @@ server.register_function(check_options)
 # create + del
 server.register_function(get_all_lists)
 server.register_function(get_all_user_lists)
+server.register_function(change_user_email)
 server.register_function(create_list)
 server.register_function(delete_list)
 # utilisateurs.php
index da4b804..5c3a1ac 100644 (file)
@@ -385,6 +385,7 @@ class AdminModule extends PLModule
             pl_redirect('admin/accounts');
         }
 
+        $listClient = new MMList(S::user());
         $login = $user->login();
         $registered = ($user->state != 'pending');
 
@@ -488,6 +489,10 @@ class AdminModule extends PLModule
             if (Post::t('comment') != $user->comment) {
                 $to_update['comment'] = Post::blank('comment') ? null : Post::t('comment');
             }
+            if (!$user->checkPerms(User::PERM_MAIL) && Post::t('email') != $user->forlifeEmail()) {
+                $to_update['email'] = Post::t('email');
+                $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
+            }
         }
         if (!empty($to_update)) {
             $res = XDB::query('SELECT  *
@@ -504,9 +509,9 @@ class AdminModule extends PLModule
                 $diff[$k] = array($oldValues[$k], trim($value, "'"));
                 unset($oldValues[$k]);
             }
-            XDB::execute('UPDATE  accounts
-                             SET  ' . implode(', ', $set) . '
-                           WHERE  uid = ' . XDB::format('{?}', $user->id()));
+            XDB::rawExecute('UPDATE  accounts
+                                SET  ' . implode(', ', $set) . '
+                              WHERE  uid = ' . XDB::format('{?}', $user->id()));
             $page->trigSuccess('Données du compte mise à jour avec succès');
             $user = User::getWithUID($user->id());
 
@@ -672,8 +677,7 @@ class AdminModule extends PLModule
         $page->assign('host', $host);
 
         // Display mailing lists
-        $list = new MMList(S::user());
-        $page->assign('mlists', $list->get_all_user_lists($user->forlifeEmail()));
+        $page->assign('mlists', $listClient->get_all_user_lists($user->forlifeEmail()));
 
         // Display active aliases.
         $page->assign('virtuals', $user->emailAliases());
index ece9ad6..3a20e9d 100644 (file)
@@ -160,6 +160,10 @@ $(document).ready(function() {
         <label><input type="radio" name="sex" value="male" {if !$user->isFemale()}checked="checked"{/if} /> homme</label>
       </td>
     </tr>
+    <tr>
+      <td class="titre">Email</td>
+      <td>{if $user->checkPerms('mail')}{$user->forlifeEmail()}{else}<input type="text" name="email" size="40" maxlength="255" value="{$user->forlifeEmail()}" />{/if}</td>
+    </tr>
     <tr class="impair">
       <td class="titre">Mot de passe</td>
       <td>