def addGroup(self, gid): '''Add a new group''' if super(LdapModelFactory, self).addGroup(gid): gl = self.getGroupList() if not gid in gl: g = Group() g.gid = gid g.gidNumber = self.getHighestGidNumber() mod_attrs = [] mod_attrs.append(('objectClass', ['top', 'posixGroup'])) mod_attrs.append(self.prepareVolatileAttribute(g, None, 'cn')) mod_attrs.append( self.prepareVolatileAttribute(g, None, 'gidNumber')) while None in mod_attrs: mod_attrs.remove(None) dn = 'cn=' + gid + ',' + Config.get('ldap', 'basedn_groups') dn = dn.encode('ascii', 'ignore') result = self.ldapcon.add_s(dn, mod_attrs) if result is None: return False return True return False
def getGroup(self, gid): ''' Get a specific group''' filter = '(cn=' + gid + ')' attrs = ['*'] result = self.ldapcon.search_s(Config.get('ldap', 'basedn_groups'), ldap.SCOPE_SUBTREE, filter, attrs) if not result: raise LookupError('No such group !') g = Group() g.users = [] for dn, attr in result: for k, v in attr.iteritems(): if 'cn' in k: k = 'gid' if 'memberUid' in k: for m in v: g.users.append(m) else: v = v[0] setattr(g, k, v) return g
def addGroup(self, gid): '''Add a new group''' if super(LdapModelFactory, self).addGroup(gid): gl = self.getGroupList() if not gid in gl: g = Group() g.gid = gid g.gidNumber = self.getHighestGidNumber() mod_attrs = [] mod_attrs.append(('objectClass', ['top', 'posixGroup'])) mod_attrs.append(self.prepareVolatileAttribute(g, None, 'cn')) mod_attrs.append(self.prepareVolatileAttribute(g, None, 'gidNumber')) while None in mod_attrs: mod_attrs.remove(None) dn = 'cn=' + gid + ',' + Config.get('ldap', 'basedn_groups') dn = dn.encode('ascii', 'ignore') result = self.ldapcon.add_s(dn, mod_attrs) if result is None: return False return True return False
def addGroup(self, gid): try: sql_group = self.db.query(Group).filter(Group.gid == gid).one() return True except LookupError: print 'Fatal error...' return False except NoResultFound: '''SQL entry does not exist, create it''' try: g = Group() g.gid = gid cherrypy.request.db.add(g) cherrypy.request.db.commit() return True except: return False
def editGroup(self, gid=None): c = TemplateContext() # vary form depending on mode (do that over ajax) if gid is None: c.group = Group() action = 'Adding' c.gid = '' else: try: ParamChecker.checkUsername('gid', param=True) except: msg = _('Invalid format!') return self.index(msg=msg) action = 'Editing' c.gid = gid try: c.group = self.mf.getGroup(gid) print 'poll' users = '' for u in c.group.users: if not users == '': users += '\n' users += u c.group.users = users except LookupError: # @TODO implement better handler msg = _('No such group!') return self.index(msg=msg) c.heading = '{0} group'.format(action) return self.render('/groups/editGroup.mako', template_context=c)