Permalink
Browse files

simplify code ... start working on uniform specific groups (e.g. open…

…duino, wg, etc)
  • Loading branch information...
1 parent 722b631 commit 7ca5b9157255fee37cdb49d2f1b3b158daedb6d7 @sim0nx committed Aug 22, 2011
Showing with 47 additions and 52 deletions.
  1. +15 −51 MeMaTool/mematool/controllers/members.py
  2. +14 −0 MeMaTool/mematool/lib/base.py
  3. +17 −1 MeMaTool/mematool/lib/syn2cat/ldapConnector.py
  4. +1 −0 TODO
@@ -78,34 +78,25 @@ def editMember(self):
#member_q = Session.query(Member).filter(Member.dtusername == request.params['member_id'])
try:
- #member = member_q.one()
- member = Member()
- member.uid = request.params['member_id']
+ member = Member(request.params['member_id'])
c.heading = 'Edit member'
c.mode = 'edit'
c.actions = list()
c.actions.append( ('Show all members', 'members', 'showAllMembers') )
+ c.member = member
- try:
- member.loadFromLdap()
-
- c.member = member
-
- if member.fullMember:
- c.member.full_member = 'checked'
- if member.lockedMember:
- c.member.locked_member = 'checked'
-
- return render('/members/editMember.mako')
+ if member.fullMember:
+ c.member.full_member = 'checked'
+ if member.lockedMember:
+ c.member.locked_member = 'checked'
- except LookupError:
- print 'No such ldap user !'
+ return render('/members/editMember.mako')
- except NoResultFound:
- print 'No such sql user !'
+ except LookupError:
+ print 'No such ldap user !'
return 'ERROR 4x0'
@@ -242,37 +233,11 @@ def doEditMember(self):
member.arrivalDate = request.params['arrivalDate']
member.leavingDate = request.params['leavingDate']
- if 'sshPublicKey' in request.params:
- if request.params['sshPublicKey'] == '' and 'sshPublicKey' in vars(member):
- member.sshPublicKey = 'removed'
- else:
- member.sshPublicKey = request.params['sshPublicKey']
- elif 'sshPublicKey' in vars(member) and request.params['mode'] == 'edit':
- member.sshPublicKey = 'removed'
-
- if 'pgpKey' in request.params:
- if request.params['pgpKey'] == '' and 'pgpKey' in vars(member):
- member.pgpKey = 'removed'
- else:
- member.pgpKey = request.params['pgpKey']
- elif 'pgpKey' in vars(member) and request.params['mode'] == 'edit':
- member.pgpKey = 'removed'
-
- if 'conventionSigner' in request.params:
- if request.params['conventionSigner'] == '' and 'conventionSigner' in vars(member):
- member.conventionSigner = 'removed'
- else:
- member.conventionSigner = request.params['conventionSigner']
- elif 'conventionSigner' in vars(member) and request.params['mode'] == 'edit':
- member.conventionSigner = 'removed'
-
- if 'xmppID' in request.params:
- if request.params['xmppID'] == '' and 'xmppID' in vars(member):
- member.xmppID = 'removed'
- else:
- member.xmppID = request.params['xmppID']
- elif 'xmppID' in vars(member) and request.params['mode'] == 'edit':
- member.xmppID = 'removed'
+
+ self.prepareVolatileParameter(member, 'sshPublicKey')
+ self.prepareVolatileParameter(member, 'pgpKey')
+ self.prepareVolatileParameter(member, 'conventionSigner')
+ self.prepareVolatileParameter(member, 'xmppID')
if 'userPassword' in request.params and request.params['userPassword'] != '':
@@ -304,8 +269,7 @@ def doEditMember(self):
def getAllMembers(self):
'''This methods retireves all members from LDAP and returns a list object containing them all'''
- ldapcon = LdapConnector()
- memberlist = ldapcon.getMemberList()
+ memberlist = self.ldapcon.getMemberList()
members = []
for key in memberlist:
@@ -151,3 +151,17 @@ def new_f(self):
self._forbidden()
return new_f
+
+ '''
+ @param m Member object
+ @param p parameter string
+ '''
+ def prepareVolatileParameter(self, m, p):
+ '''check if a parameter has been removed or changed'''
+ if p in request.params:
+ if request.params[p] == '' and p in vars(m):
+ setattr(m, p, 'removed')
+ else:
+ setattr(m, p, request.params[p])
+ elif p in vars(m) and request.params['mode'] == 'edit':
+ setattr(m, p, 'removed')
@@ -84,6 +84,7 @@ def getGroup(self, cn):
return group
+ # @obsolete ... new groups follow a specific schema
def getGroupList(self):
filter = '(cn=*)'
attrs = ['cn', 'gidNumber']
@@ -96,12 +97,27 @@ def getGroupList(self):
return groups
+ # All syn2cat groups have a specific prefix -> s2c_
+ # Working-groups: s2c_wg_
+ # Member status groups: s2c_member_
+ def getGroups(self):
+ filter = '(cn=s2c_*)'
+ attrs = ['cn', 'gidNumber']
+
+ result = self.con.search_s(config.get('ldap.basedn_groups'), ldap.SCOPE_SUBTREE, filter, attrs)
+ groups = []
+
+ for dn, attr in result:
+ groups.append(attr['cn'][0])
+
+ return groups
+
def getGroupMembers(self, group):
filter = '(cn=' + group + ')'
attrs = ['memberUid']
- result = self.con.search_s( config.get('ldap.basedn_groups'), ldap.SCOPE_SUBTREE, filter, attrs )
+ result = self.con.search_s(config.get('ldap.basedn_groups'), ldap.SCOPE_SUBTREE, filter, attrs)
members = []
for dn, attr in result:
View
@@ -2,3 +2,4 @@
http://stackoverflow.com/questions/3033234/handle-mysql-restart-in-sqlalchemy
- handle ldap kill
- Add CSRF token to session and each form ... CSRF mitigation
+- Implement payment start/end periods after committee discussion

0 comments on commit 7ca5b91

Please sign in to comment.