From 0b3c9d835b2efd2a563a01396df99c8ea8e4d893 Mon Sep 17 00:00:00 2001 From: Jeremy Roman Date: Fri, 26 Aug 2011 03:03:32 -0400 Subject: [PATCH] tell ceod when it is a club rep; club reps don't need the new member email --- ceo/members.py | 18 +++++++++--------- ceo/urwid/newmember.py | 24 ++++++++++++++++++------ etc/spam/new-member.d/announce | 4 ++-- etc/spam/new-member.d/welcome | 2 +- src/ceo.proto | 1 + src/op-adduser.c | 30 ++++++++++++++++++++---------- 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/ceo/members.py b/ceo/members.py index fc3835e..e1bf294 100644 --- a/ceo/members.py +++ b/ceo/members.py @@ -114,7 +114,7 @@ def connected(): ### Members ### -def create_member(username, password, name, program, email): +def create_member(username, password, name, program, email, club_rep=False): """ Creates a UNIX user account with options tailored to CSC members. @@ -123,7 +123,8 @@ def create_member(username, password, name, program, email): password - the desired UNIX password name - the member's real name program - the member's program of study - email - email to place in .forward + club_rep - whether the user is a club rep + email - email to place in .forward Exceptions: InvalidArgument - on bad account attributes provided @@ -143,12 +144,16 @@ def create_member(username, password, name, program, email): try: request = ceo_pb2.AddUser() - request.type = ceo_pb2.AddUser.MEMBER request.username = username request.password = password request.realname = name request.program = program - request.email = email + request.email = email + + if club_rep: + request.type = ceo_pb2.AddUser.CLUB_REP + else: + request.type = ceo_pb2.AddUser.MEMBER out = remote.run_remote('adduser', request.SerializeToString()) @@ -158,11 +163,6 @@ def create_member(username, password, name, program, email): if any(message.status != 0 for message in response.messages): raise MemberException('\n'.join(message.message for message in response.messages)) - # # If the user was created, consider adding them to the mailing list - # if not status: - # listadmin_cfg_file = "/path/to/the/listadmin/config/file" - # mail = subprocess.Popen(["/usr/bin/listadmin", "-f", listadmin_cfg_file, "--add-member", username + "@csclub.uwaterloo.ca"]) - # status2 = mail.wait() # Fuck if I care about errors! except remote.RemoteException, e: raise MemberException(e) except OSError, e: diff --git a/ceo/urwid/newmember.py b/ceo/urwid/newmember.py index ca684a4..b62785b 100644 --- a/ceo/urwid/newmember.py +++ b/ceo/urwid/newmember.py @@ -207,17 +207,29 @@ class EndPage(WizardPanel): problem = None try: 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'] ) + 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'] ) + 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'] ) + members.create_member( + self.state['userid'], + self.state['password'], + self.state['name'], + self.state['program'], + self.state['email'], + club_rep=True) + members.register_nonmember(self.state['userid'], self.state['terms']) elif self.utype == 'club': - members.create_club( self.state['userid'], self.state['name'] ) + members.create_club(self.state['userid'], self.state['name']) else: raise Exception("Internal Error") except members.InvalidArgument, e: diff --git a/etc/spam/new-member.d/announce b/etc/spam/new-member.d/announce index 555649e..aea5cd4 100755 --- a/etc/spam/new-member.d/announce +++ b/etc/spam/new-member.d/announce @@ -19,7 +19,7 @@ h_from="$prog " h_to="Membership and Accounts " h_cc="$authrn <$auth@csclub.uwaterloo.ca>" -if test "$prog" = addmember; then +if [[ "$prog" = addmember || "$prog" == addclubrep ]]; then user="$CEO_USER" name="$CEO_NAME" dept="$CEO_DEPT" status="$CEO_STATUS" subj="New Member: $user" test -z "$dept" && dept="things unknown" @@ -28,7 +28,7 @@ Account: $user Program: $dept Added by: $auth" -elif test "$prog" = addclub; then +elif [[ "$prog" = addclub ]]; then user="$CEO_USER" name="$CEO_NAME" status="$CEO_STATUS" subj="New Club Account: $user" body="Club: $name diff --git a/etc/spam/new-member.d/welcome b/etc/spam/new-member.d/welcome index 908909f..bb97620 100755 --- a/etc/spam/new-member.d/welcome +++ b/etc/spam/new-member.d/welcome @@ -68,7 +68,7 @@ Regards, Computer Science Club Executive " -elif test "$prog" = addclub; then +elif [[ "$prog" = addclubrep || "$prog" = addclub ]]; then exit 0 else exit 1 diff --git a/src/ceo.proto b/src/ceo.proto index 4d803a0..e16f9fe 100644 --- a/src/ceo.proto +++ b/src/ceo.proto @@ -9,6 +9,7 @@ message AddUser { enum Type { MEMBER = 1; CLUB = 2; + CLUB_REP = 3; } required Type type = 1; diff --git a/src/op-adduser.c b/src/op-adduser.c index 9c4d5a5..91d557f 100644 --- a/src/op-adduser.c +++ b/src/op-adduser.c @@ -32,6 +32,7 @@ static const int MAX_MESGSIZE = 512; char *user_types[] = { [CEO__ADD_USER__TYPE__MEMBER] = "member", [CEO__ADD_USER__TYPE__CLUB] = "club", + [CEO__ADD_USER__TYPE__CLUB_REP] = "clubrep", }; Ceo__AddUserResponse *response_create(void) { @@ -94,16 +95,22 @@ static int check_adduser(Ceo__AddUser *in, Ceo__AddUserResponse *out, char *clie if (!in->realname) return response_message(out, EINVAL, "missing required argument: realname"); - if (in->type == CEO__ADD_USER__TYPE__MEMBER) { - if (!in->password) - return response_message(out, EINVAL, "missing required argument: password"); - } else if (in->type == CEO__ADD_USER__TYPE__CLUB) { - if (in->password) - return response_message(out, EINVAL, "club accounts cannot have passwords"); - if (in->program) - return response_message(out, EINVAL, "club accounts cannot have programs"); - } else { - return response_message(out, EINVAL, "invalid user type: %d", in->type); + switch (in->type) { + case CEO__ADD_USER__TYPE__MEMBER: + case CEO__ADD_USER__TYPE__CLUB_REP: + if (!in->password) + return response_message(out, EINVAL, "missing required argument: password"); + break; + + case CEO__ADD_USER__TYPE__CLUB: + if (in->password) + return response_message(out, EINVAL, "club accounts cannot have passwords"); + if (in->program) + return response_message(out, EINVAL, "club accounts cannot have programs"); + break; + + default: + return response_message(out, EINVAL, "invalid user type: %d", in->type); } if (getpwnam(in->username) != NULL) @@ -244,6 +251,9 @@ static int32_t adduser(Ceo__AddUser *in, Ceo__AddUserResponse *out, char *client if (in->type == CEO__ADD_USER__TYPE__MEMBER) { status = addmember(in, out); prog = "addmember"; + } else if (in->type == CEO__ADD_USER__TYPE__CLUB_REP) { + status = addmember(in, out); + prog = "addclubrep"; } else if (in->type == CEO__ADD_USER__TYPE__CLUB) { status = addclub(in, out); prog = "addclub";