half of the member list is done.
authorx2000habouzit <x2000habouzit>
Fri, 10 Sep 2004 21:28:53 +0000 (21:28 +0000)
committerx2000habouzit <x2000habouzit>
Fri, 10 Sep 2004 21:28:53 +0000 (21:28 +0000)
I achieve that with tricky things to avoid sql queries

htdocs/listes/liste.php [new file with mode: 0644]
scripts/mailman/mailman-rpc.py
templates/listes/index.tpl
templates/listes/liste.tpl [new file with mode: 0644]

diff --git a/htdocs/listes/liste.php b/htdocs/listes/liste.php
new file mode 100644 (file)
index 0000000..c587aaa
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 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                *
+ ***************************************************************************
+        $Id: liste.php,v 1.1 2004-09-10 21:28:53 x2000habouzit Exp $
+ ***************************************************************************/
+
+if(empty($_REQUEST['liste'])) header('Location: index.php');
+$liste = $_REQUEST['liste'];
+
+require("auto.prepend.inc.php");
+new_skinned_page('listes/liste.tpl', AUTH_COOKIE, true);
+include('xml-rpc-client.inc.php');
+
+$res = $globals->db->query("SELECT password FROM auth_user_md5 WHERE user_id={$_SESSION['uid']}");
+list($pass) = mysql_fetch_row($res);
+mysql_free_result($res);
+
+$client = new xmlrpc_client("http://{$_SESSION['uid']}:$pass@localhost:4949");
+$members = $client->get_members($liste);
+
+if(is_array($members)) {
+    $membres = Array();
+    foreach($members[1] as $member) {
+       if(preg_match('/^([^.]*.[^.]*.(\d\d\d\d))@polytechnique.org$/', $member[1], $matches)) {
+           $membres[$matches[2]][] = Array('n' => $member[0], 'l' => $matches[1]);
+       } else {
+           $membres[0][] = Array('l' => $member[1]);
+       }
+    }
+    ksort($membres);
+
+    $moderos = Array();
+    foreach($members[2] as $owner) {
+       list($m) = split('@',$owner);
+       $res = $globals->db->query("SELECT  CONCAT(prenom, ' ', nom), promo
+                                     FROM  auth_user_md5 AS u
+                               INNER JOIN  aliases AS a ON u.user_id = a.id
+                                    WHERE  a.alias = '$m'");
+       if(list($nom, $promo) = mysql_fetch_row($res)) {
+           $moderos[$promo][] = Array('n' => $nom, 'l' => $m);
+       } else {
+           $moderos[0][] = Array('l' => $owner);
+       }
+       mysql_free_result($res);
+    }
+    ksort($membres);
+
+    $page->assign_by_ref('details', $members[0]);
+    $page->assign_by_ref('members', $membres);
+    $page->assign_by_ref('owners',  $moderos);
+
+} else
+    $page->assign('no_list',true);
+
+$page->run();
+?>
index 5803521..cd76a75 100755 (executable)
@@ -18,7 +18,7 @@
 #*  Foundation, Inc.,                                                      *
 #*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
 #***************************************************************************
-#       $Id: mailman-rpc.py,v 1.14 2004-09-10 11:52:37 x2000habouzit Exp $
+#       $Id: mailman-rpc.py,v 1.15 2004-09-10 21:28:53 x2000habouzit Exp $
 #***************************************************************************
 
 import base64, MySQLdb
@@ -141,9 +141,21 @@ def get_members((userdesc,perms),listname):
         mlist = MailList.MailList(listname, lock=0)
     except:
         return 0
-    members = mlist.getRegularMemberKeys()
     if ( mlist.advertised ) or ( is_admin_on(userdesc, perms, mlist) ) or ( userdesc.address in members ):
-        return (members,mlist.owner)
+        members = mlist.getRegularMemberKeys()
+        members.sort()
+        is_member = userdesc.address in members
+        is_owner  = userdesc.address in mlist.owner
+        details = { 'addr' : listname+'@polytechnique.org',
+                    'desc' : mlist.description,
+                    'diff' : mlist.generic_nonmember_action,
+                    'ins'  : mlist.subscribe_policy > 0,
+                    'priv' : (1-mlist.advertised)+2*(mm_cfg.ADMIN_ML_OWNER in mlist.owner),
+                    'info' : mlist.info,
+                    'you'  : is_member + 2*is_owner
+                  }
+        members = map(lambda member: (mlist.getMemberName(member) or '', member), members)
+        return (details,members,mlist.owner)
     return 0
 
 def subscribe((userdesc,perms),listname):
@@ -194,8 +206,11 @@ def mass_subscribe((userdesc,perms),listname,users):
         if not is_admin_on(userdesc, perms, mlist):
             return None
         
+        members = mlist.getRegularMemberKeys()
         added = []
         for user in users:
+            if user+'@polytechnique.org' in members:
+                continue
             mysql.execute ("""SELECT  CONCAT(u.prenom,' ',u.nom)
                                 FROM  auth_user_md5 AS u
                           INNER JOIN  aliases       AS a ON (a.id=u.user_id AND alias='%s')
@@ -255,15 +270,6 @@ def del_owner((userdesc,perms),listname,user):
         mlist.Unlock()
         return True
 
-def get_welcome((userdesc,perms),listname):
-    try:
-        mlist = MailList.MailList(listname, lock=0)
-    except:
-        return 0
-    if not is_admin_on(userdesc, perms, mlist):
-        return 0
-    return mlist.info
-
 def set_welcome((userdesc,perms),listname,info):
     try:
         mlist = MailList.MailList(listname)
@@ -301,7 +307,6 @@ server.register_function(mass_subscribe)
 server.register_function(mass_unsubscribe)
 server.register_function(add_owner)
 server.register_function(del_owner)
-server.register_function(get_welcome)
 server.register_function(set_welcome)
 
 server.serve_forever()
index b2ab516..1eaed86 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: index.tpl,v 1.1 2004-09-10 11:52:37 x2000habouzit Exp $
+        $Id: index.tpl,v 1.2 2004-09-10 21:28:53 x2000habouzit Exp $
  ***************************************************************************}
 
- {dynamic}
+<div class="rubrique">
+  Listes de diffusion de Polytechnique.org
+</div>
+
+<p>
+Les listes de diffusion publiques sont visibles par tous les X inscrits à Polytechnique.org.
+</p>
+
+<div class='ssrubrique'>
+  L'inscription à une liste de diffusion
+</div>
+
+<p>
+Certaines listes sont à inscription modérée, pour t'y inscrire, il te faut envoyer un mail aux
+modérateurs en cliquant sur le lien "s'inscrire", si tu es déjà inscrit, le mot "inscrit" apparaît
+près de la case à cocher.  Les autres listes sont dites libres : il suffit de cocher la case à
+cocher et de cliquer sur le bouton "Enregistrer".
+</p>
+
+<p>
+Dans tous les cas, pour se désinscrire, il suffit de décocher la case et de cliquer sur
+"Enregistrer".  
+</p>
+
+<p>
+Si tu vois une * derrière le nom d'une liste, cela signifie que tu en es gestionnaire.  En cliquant
+sur la liste, tu pourras administrer les abonnés et les gestionnaires de la liste.
+</p>
+
+<div class='ssrubrique'>
+  La diffusion sur une liste de diffusion 
+</div>
+<p>
+Certaines listes sont à diffusion modérée, l'envoi d'un mail à la liste est alors filtré par des
+modérateurs : eux seuls peuvent accepter un message envoyé à la liste.  Pour les autres listes, la
+diffusion est immédiate.
+</p>
+<p class='smaller'>
+NB : les gestionnaires d'une liste sont aussi ses modérateurs.  
+</p>
+
+{dynamic}
 
 <div class="rubrique">
   Listes de diffusion publiques
   {/foreach}
 </table>
 
+{perms level=admin}
 <div class="rubrique">
   Listes d'administration
 </div>
   {/if}
   {/foreach}
 </table>
+{/perms}
 
 {/dynamic}
 
diff --git a/templates/listes/liste.tpl b/templates/listes/liste.tpl
new file mode 100644 (file)
index 0000000..e21d773
--- /dev/null
@@ -0,0 +1,116 @@
+{***************************************************************************
+ *  Copyright (C) 2003-2004 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                *
+ ***************************************************************************
+        $Id: liste.tpl,v 1.1 2004-09-10 21:28:53 x2000habouzit Exp $
+ ***************************************************************************}
+
+{dynamic}
+
+{if $no_list}
+
+<p class='erreur'>La liste n'existe pas ou tu n'as pas le droit d'en voir les détails</p>
+
+{else}
+
+<div class="rubrique">
+  Liste {$smarty.request.liste}
+</div>
+
+<table class='tinybicol' cellpadding='0' cellspacing='0'>
+  <tr>
+    <td class='titre'> Adresse </td>
+    <td>{mailto address=$details.addr}</td>
+  </tr>
+  <tr>
+    <td class='titre'> Sujet </td>
+    <td>{$details.desc}</td>
+  </tr>
+  <tr>
+    <td class='titre'> Visibilité </td>
+    <td>{if $details.priv eq 0}publique{elseif $details.priv eq 1}privée{else}admin{/if}</td>
+  </tr>
+  <tr>
+    <td class='titre'> Diffusion </td>
+    <td>{if $details.diff}modérée{else}libre{/if}</td>
+  </tr>
+  <tr>
+    <td class='titre'> Inscription </td>
+    <td>{if $details.ins}modérée{else}libre{/if}</td>
+  </tr>
+  <tr>
+    <td colspan='2' class='center'>
+      <a href='trombiliste.php?liste={$smarty.request.liste}'>trombino de la liste</a>
+    </td>
+  </tr>    
+</table>
+
+<div class='rubrique'>
+  modérateurs de la liste
+</div>
+
+<table class='tinybicol' cellpadding='0' cellspacing='0'>
+  {foreach from=$owners item=xs key=promo}
+  <tr>
+    <td class='titre'>{if $promo}{$promo}{else}non-X{/if}</td>
+    <td>
+      {foreach from=$xs item=x}
+      {if $promo}
+      <a href="javascript:x()" onclick="popWin('{"fiche.php"|url}?user={$x.l}')">{$x.n}</a>
+      {else}
+      {$x.l}
+      {/if}
+      {/foreach}
+    </td>
+  </tr>
+  {/foreach}
+</table>
+
+<div class='rubrique'>
+  membres de la liste
+</div>
+
+<table class='bicol' cellpadding='0' cellspacing='0'>
+  {foreach from=$members item=xs key=promo}
+  <tr>
+    <td class='titre'>{if $promo}{$promo}{else}non-X{/if}</td>
+    <td>
+      {foreach from=$xs item=x}
+      {if $promo}
+      <a href="javascript:x()" onclick="popWin('{"fiche.php"|url}?user={$x.l}')">{$x.n}</a>
+      {else}
+      {$x.l}
+      {/if}
+      {/foreach}
+    </td>
+  </tr>
+  {/foreach}
+</table>
+
+{if $details.you > 1 || ($details.priv>1 && $smarty.session.perms eq admin)}
+<div class='rubrique'>
+  Administrer la liste
+</div>
+
+{/if}
+
+{/if}
+
+{/dynamic}
+
+{* vim:set et sw=2 sts=2 sws=2: *}