adding users to csc-general jbroman/mailing-list
authorJeremy Roman <jbroman@csclub.uwaterloo.ca>
Sat, 25 Sep 2010 05:00:27 +0000 (01:00 -0400)
committerJeremy Roman <jbroman@csclub.uwaterloo.ca>
Sat, 25 Sep 2010 05:00:27 +0000 (01:00 -0400)
ceo/members.py
ceo/urwid/newmember.py
etc/ops/mailman [new file with mode: 0644]
setupd.py
src/op-mailman [new file with mode: 0755]

index be212f6..fc3835e 100644 (file)
@@ -595,3 +595,10 @@ def expired_accounts():
 def send_account_expired_email(name, email):
     args = [ cfg['expire_hook'], name, email ]
     os.spawnv(os.P_WAIT, cfg['expire_hook'], args)
+
+def subscribe_to_mailing_list(name):
+    member = get(name)
+    if member is not None:
+        return remote.run_remote('mailman', name)
+    else:
+        return 'Error: member does not exist'
index 5007bfe..ca684a4 100644 (file)
@@ -1,5 +1,5 @@
 import ldap, urwid #, re
-from ceo import members, terms, uwldap
+from ceo import members, terms, remote, uwldap
 from ceo.urwid.widgets import *
 from ceo.urwid.window import *
 
@@ -209,6 +209,10 @@ class EndPage(WizardPanel):
             if self.utype == 'member':
                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
                 members.register( self.state['userid'], self.state['terms'] )
+
+                mailman_result = members.subscribe_to_mailing_list( self.state['userid'] )
+                if mailman_result.split(': ',1)[0] not in ('Subscribed', 'Already a member'):
+                    problem = mailman_result
             elif self.utype == 'clubuser':
                 members.create_member( self.state['userid'], self.state['password'], self.state['name'], self.state['program'], self.state['email'] )
                 members.register_nonmember( self.state['userid'], self.state['terms'] )
@@ -222,6 +226,8 @@ class EndPage(WizardPanel):
             problem = str(e)
         except members.MemberException, e:
             problem = str(e)
+        except remote.RemoteException, e:
+            problem = str(e)
 
         clear_status()
 
diff --git a/etc/ops/mailman b/etc/ops/mailman
new file mode 100644 (file)
index 0000000..ec3bc23
--- /dev/null
@@ -0,0 +1 @@
+caffeine mailman list 0x04
index 0ccfee8..f120e46 100755 (executable)
--- a/setupd.py
+++ b/setupd.py
@@ -5,6 +5,6 @@ from distutils.core import setup
 setup(
     name='ceod',
     description='CSC Electronic Office Daemon',
-    scripts=['src/op-mysql'],
+    scripts=['src/op-mysql','src/op-mailman'],
 )
 
diff --git a/src/op-mailman b/src/op-mailman
new file mode 100755 (executable)
index 0000000..c3af81c
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import os, syslog
+from subprocess import Popen, PIPE, STDOUT
+from ceo.ops import get_ceo_user, check_group
+
+def main():
+    remote_user = get_ceo_user()
+    user_to_add = raw_input()
+    
+    if remote_user == user_to_add or check_group(remote_user, 'office') or check_group(remote_user, 'syscom'):
+        mailman = Popen(["/var/lib/vmailman/csclub/bin/add_members", "-r", "-", "csc-general"],
+                        stdin=PIPE, stdout=PIPE, stderr=STDOUT)
+        out, err = mailman.communicate("%s@csclub.uwaterloo.ca\n" % user_to_add)
+        syslog.syslog(syslog.LOG_INFO, out)
+        print out
+    else:
+        message = "Access denied: user '%s' cannot subscribe users to csc-general" % remote_user
+        syslog.syslog(syslog.LOG_NOTICE, message)
+        print message
+
+if __name__ == '__main__':
+    syslog.openlog('op-mailman', syslog.LOG_PID, syslog.LOG_DAEMON)
+    main()