Exemplo n.º 1
0
 def addUserToGroup(self, session, username, groupName):
     dbUserInfo = self.findUserInfoByUsername(session, username)
     userGroupHandler = UserGroupHandler()
     dbUserGroup = userGroupHandler.findUserGroupByName(session, groupName)
     dbUserGroups = session.query(UserGroup).join(UserUserGroup).filter(
         and_(UserUserGroup.user_id == dbUserInfo.id,
              UserUserGroup.user_group_id == UserGroup.id)).all()
     for g in dbUserGroups:
         if g.id == dbUserGroup.id:
             raise ObjectAlreadyExists(
                 'User %s is already a member of group %s.' %
                 (username, groupName))
     dbUserUserGroup = UserUserGroup(user_id=dbUserInfo.id,
                                     user_group_id=dbUserGroup.id)
     session.add(dbUserUserGroup)
     session.flush()
     self.logger.debug('Added user %s to group %s' % (username, groupName))
     return dbUserUserGroup
Exemplo n.º 2
0
 def __init__(self):
     CdbDbApi.__init__(self)
     self.userInfoHandler = UserInfoHandler()
     self.userGroupHandler = UserGroupHandler()