From d0f665cc8b9a18cc869961bd81877785350f77a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 26 Dec 2019 10:28:30 +0100 Subject: [PATCH] first usable site only 2 groups exists: bar and finanzer person can be in more than 1 group site for baruser first try with autocomplete from ldap site for finanzer ; overview; specialview for 1 Person --- geruecht/baruser/routes.py | 12 +++--- geruecht/controller/databaseController.py | 2 +- geruecht/controller/ldapController.py | 51 +++++++++++++++++------ geruecht/finanzer/routes.py | 4 ++ geruecht/model/creditList.py | 1 + geruecht/model/user.py | 1 + 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index dc2579b..4feb597 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -64,6 +64,12 @@ def _baradd(): amount = int(data['amount']) user = db.getUser(userID) + if user is None: + groups = ldap.getGroup(userID) + user_data = ldap.getUserData(userID) + user_data['group'] = groups + db.insertUser(user_data) + user = db.getUser(userID) month = user.addAmount(amount) amount = abs(month[0] - month[1]) @@ -87,11 +93,7 @@ def _getUsers(): retVal = {} if accToken is not None: - users = db.getAllUser() - for user in users: - month = user.getGeruecht().getMonth() - if month == 0: - retVal[user.cn] = {user.toJSON()} + retVal = ldap.getAllUser() return jsonify(retVal) return jsonify({"error": "permission denied"}), 401 diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index 20f5a89..2e239f4 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -106,7 +106,7 @@ class DatabaseController(metaclass=Singleton): self.db.close() raise err if len(data) == 1: - return CreditList(data[0]) + return [CreditList(data[0])] else: return [CreditList(value) for value in data] diff --git a/geruecht/controller/ldapController.py b/geruecht/controller/ldapController.py index 593c4e6..ebb7de8 100644 --- a/geruecht/controller/ldapController.py +++ b/geruecht/controller/ldapController.py @@ -63,33 +63,58 @@ class LDAPController(metaclass=Singleton): def __isUserInList(self, list, username): help_list = [] for user in list: - help_list.append(user[1]['cn'][0].decode('utf-8')) + help_list.append(user['username']) if username in help_list: return True return False + def getAllUser(self): + self.connect() + retVal = [] + data = self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, attrlist=['cn', 'givenName', 'sn']) + for user in data: + if 'cn' in user[1]: + username = user[1]['cn'][0].decode('utf-8') + firstname = user[1]['givenName'][0].decode('utf-8') + lastname = user[1]['sn'][0].decode('utf-8') + retVal.append({'username': username, 'firstname': firstname, 'lastname': lastname}) + return retVal + def searchUser(self, searchString): self.connect() name = searchString.split(" ") + + for i in range(len(name)): + name[i] = "*"+name[i]+"*" + + + print(name) + name_result = [] if len(name) == 1: - name_result[0] = self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'givenName={}'.format(name[0]), ['cn', 'givenName', 'sn']) - name_result[1] = self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'sn={}'.format(name[0]),['cn', 'givenName', 'sn']) + if name[0] == "**": + name_result.append(self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, + attrlist=['cn', 'givenName', 'sn'])) + else: + name_result.append(self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'givenName={}'.format(name[0]), ['cn', 'givenName', 'sn'])) + name_result.append(self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'sn={}'.format(name[0]),['cn', 'givenName', 'sn'])) else: - name_result[2] = self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, - 'givenName={}'.format(name[0]), ['cn', 'givenName', 'sn']) - name_result[3] = self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'sn={}'.format(name[0]), - ['cn', 'givenName', 'sn']) + name_result.append(self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, + 'givenName={}'.format(name[1]), ['cn', 'givenName', 'sn'])) + name_result.append(self.client.search_s('ou=user,{}'.format(self.dn), ldap.SCOPE_SUBTREE, 'sn={}'.format(name[1]), + ['cn', 'givenName', 'sn'])) retVal = [] - for user in name_result: - username = user[1]['cn'][0].decode('utf-8') - if not self.__isUserInList(retVal, username): - firstname = user[1]['givenName'][0].decode('utf-8') - lastname = user[1]['givenName'][0].decode('utf-8') - retVal.append({username: username, firstname: firstname, lastname: lastname}) + for names in name_result: + for user in names: + if 'cn' in user[1]: + username = user[1]['cn'][0].decode('utf-8') + if not self.__isUserInList(retVal, username): + firstname = user[1]['givenName'][0].decode('utf-8') + lastname = user[1]['sn'][0].decode('utf-8') + retVal.append({'username': username, 'firstname': firstname, 'lastname': lastname}) return retVal diff --git a/geruecht/finanzer/routes.py b/geruecht/finanzer/routes.py index f1178cd..57b13a5 100644 --- a/geruecht/finanzer/routes.py +++ b/geruecht/finanzer/routes.py @@ -28,6 +28,8 @@ def _getFinanzer(): for user in users: LOGGER.debug("Add User {} to ReturnValue".format(user)) dic[user.cn] = user.toJSON() + creditList = db.getCreditListFromUser(user) + dic[user.cn]['creditList'] = {credit.year: credit.toJSON() for credit in creditList} LOGGER.debug("ReturnValue is {}".format(dic)) LOGGER.info("Send main for Finanzer") return jsonify(dic) @@ -130,7 +132,9 @@ def _addCredit(): accToken = verifyAccessToken(token, MONEY) if accToken is not None: + data = request.get_json() + print(data) LOGGER.debug("Get data {}".format(data)) userID = data['userId'] credit = int(data['credit']) diff --git a/geruecht/model/creditList.py b/geruecht/model/creditList.py index 70fcaa8..5c30a9c 100644 --- a/geruecht/model/creditList.py +++ b/geruecht/model/creditList.py @@ -321,6 +321,7 @@ class CreditList(): "dez": { "credit": self.dez_guthaben, "depts": self.dez_schulden}, + "last": self.last_schulden } return dic diff --git a/geruecht/model/user.py b/geruecht/model/user.py index cec7dcc..a9e61b2 100644 --- a/geruecht/model/user.py +++ b/geruecht/model/user.py @@ -40,6 +40,7 @@ class User(): self.geruechte = geruechte elif type(geruechte) == CreditList: self.geruechte.append(geruechte) + self.updateGeruecht() #geruechte = db.relationship('CreditList', backref='user', lazy=True) def createGeruecht(self, amount=0, year=datetime.now().year):