Lists and administrates aliases on main domain (Closes #1459).
authorStéphane Jacob <sj@m4x.org>
Sat, 2 Apr 2011 23:01:08 +0000 (01:01 +0200)
committerStéphane Jacob <sj@m4x.org>
Sat, 2 Apr 2011 23:01:08 +0000 (01:01 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
modules/lists.php
templates/admin/index.tpl
templates/lists/admin_aliases.tpl [new file with mode: 0644]
templates/lists/admin_edit_alias.tpl [new file with mode: 0644]

index 5fd4551..8fb9376 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 ================================================================================
 VERSION 1.1.1                                                         XX XX XXXX
 
+Bug/Wish:
+
+    * Emails:
+        - #1459: Lists and administrates aliases on main domain            -JAC
+
 From 1.1.0 branch:
 
     * Search:
index e1bfb11..eec6fa2 100644 (file)
@@ -44,6 +44,7 @@ class ListsModule extends PLModule
             'lists/soptions'     => $this->make_hook('soptions',  AUTH_MDP),
             'lists/check'        => $this->make_hook('check',     AUTH_MDP),
             'admin/lists'        => $this->make_hook('admin_all', AUTH_MDP,    'admin'),
+            'admin/aliases'      => $this->make_hook('aaliases',  AUTH_MDP,    'admin')
         );
     }
 
@@ -886,6 +887,62 @@ class ListsModule extends PLModule
         $listes = $this->client->get_all_lists();
         $page->assign_by_ref('listes', $listes);
     }
+
+    function handler_aaliases($page, $alias = null)
+    {
+        global $globals;
+        require_once 'emails.inc.php';
+        $page->setTitle('Administration - Aliases');
+
+        if (Post::has('new_alias')) {
+            pl_redirect('admin/aliases/' . Post::t('new_alias') . '@' . $globals->mail->domain);
+        }
+
+        // If no alias, list them all.
+        if (is_null($alias)) {
+            $page->changeTpl('lists/admin_aliases.tpl');
+            $page->assign('aliases', array_merge(iterate_list_alias($globals->mail->domain), iterate_list_alias($globals->mail->domain2)));
+            return;
+        }
+
+        list($local_part, $domain) = explode('@', $alias);
+        if (!($globals->mail->domain == $domain || $globals->mail->domain2 == $domain)
+              || !preg_match("/^[a-zA-Z0-9\-\.]*$/", $local_part)) {
+            $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
+        }
+
+        // Now we can perform the action.
+        if (Post::has('del_alias')) {
+            S::assert_xsrf_token();
+
+            delete_list_alias($local_part, $domain);
+            $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
+        }
+
+        if (Post::has('add_member')) {
+            S::assert_xsrf_token();
+
+            if (add_to_list_alias(Post::t('add_member'), $local_part, $domain)) {
+                $page->trigSuccess('Ajout réussit.');
+            } else {
+                $page->trigError('Ajout infructueux.');
+            }
+        }
+
+        if (Get::has('del_member')) {
+            S::assert_xsrf_token();
+
+            if (delete_from_list_alias(Get::t('del_member'), $local_part, $domain)) {
+                $page->trigSuccess('Suppression réussie.');
+            } else {
+                $page->trigError('Suppression infructueuse.');
+            }
+        }
+
+        $page->changeTpl('lists/admin_edit_alias.tpl');
+        $page->assign('members', list_alias_members($local_part, $domain));
+        $page->assign('alias', $alias);
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index e491163..fbb6ad3 100644 (file)
@@ -51,6 +51,8 @@
     <td>
       <a href="admin/lists">MLs</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
+      <a href="admin/aliases">aliases</a>
+      &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/mx/broken">MX défaillants</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/emails/lost">Perdus de vue</a>
diff --git a/templates/lists/admin_aliases.tpl b/templates/lists/admin_aliases.tpl
new file mode 100644 (file)
index 0000000..8e9dfd6
--- /dev/null
@@ -0,0 +1,50 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Aliases</h1>
+
+<table cellspacing="0" cellpadding="0" class="tinybicol">
+  <tr>
+    <th>Aliases</th>
+  </tr>
+  {if $aliases|@count}
+  {foreach from=$aliases item=alias}
+  <tr>
+    <td><a href="admin/aliases/{$alias}">{$alias}</a></td>
+  </tr>
+  {/foreach}
+  {else}
+  <tr>
+    <td>Aucun alias</td>
+  </tr>
+  {/if}
+</table>
+
+<form method="post" action="admin/aliases">
+  {xsrf_token_field}
+  <p class="center">
+    <input type="text" name="new_alias" />
+    <input type="submit" value="Créer l'alias" />
+  </p>
+</form>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
diff --git a/templates/lists/admin_edit_alias.tpl b/templates/lists/admin_edit_alias.tpl
new file mode 100644 (file)
index 0000000..1ec1f16
--- /dev/null
@@ -0,0 +1,92 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<p>[<a href="admin/aliases">Retour à la liste des aliases</a>]</p>
+
+<h1>Membres de {$alias}</h1>
+
+<table class="tinybicol">
+  {if $members.users|@count}
+  {foreach from=$members.users item=member}
+  <tr>
+    <td>
+      {if $member->hasProfile()}
+      <a href="https://www.polytechnique.org/profile/{$member->hruid}" class="popup2">{$member->fullName()}</a>
+      {else}
+      {$member->fullName()}
+      {/if}
+    </td>
+    <td class="right">{$member->promo()}</td>
+    <td class="center">
+      <a href="admin/aliases/{$alias}?del_member={$member->id()}&amp;token={xsrf_token}">
+      {icon name=delete title="retirer membre"}
+      </a>
+    </td>
+  </tr>
+  {/foreach}
+  {/if}
+  {if $members.nonusers|@count}
+  {foreach from=$members.nonusers item=member}
+  <tr>
+    <td>{$member}</td>
+    <td></td>
+    <td class="center">
+      <a href="admin/aliases/{$alias}?del_member={$member}&amp;token={xsrf_token}">
+      {icon name=delete title="retirer membre"}
+      </a>
+    </td>
+  </tr>
+  {/foreach}
+  {/if}
+  {if $members.users|@count eq 0 && $members.nonusers|@count eq 0}
+  <tr>
+    <td colspan="3">
+      <em>aucun membre&hellip;</em>
+    </td>
+  </tr>
+  {/if}
+  <tr>
+    <th colspan="3">Ajouter</th>
+  </tr>
+  <tr>
+    <td colspan="3" class="center">
+      <form method="post" action="admin/aliases/{$alias}">
+        {xsrf_token_field}
+        <div>
+        <input type="text" name="add_member" />
+        &nbsp;
+        <input type="submit" value="ajouter" />
+        </div>
+      </form>
+    </td>
+  </tr>
+</table>
+
+
+<form method="post" action="admin/aliases/{$alias}">
+  {xsrf_token_field}
+  <p class="center">
+    <input type="submit" name="del_alias" value="Supprimer l'alias" onclick="return confirm('ES tu sûr de vouloir supprimer cet alias.')" />
+  </p>
+</form>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}