From f029aa6096c54e27ecb22916698ad6094d150f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=B6ger?= Date: Tue, 10 Mar 2020 11:08:24 +0100 Subject: [PATCH] replace string with '{{}}' to '{{ {} }}' for logging fixed missing values (bugs that crash) --- geruecht/baruser/routes.py | 45 ++++++++++++++------------ geruecht/configparser.py | 29 +++++++++++------ geruecht/decorator.py | 18 +++++++---- geruecht/finanzer/routes.py | 61 ++++++++++++++++++++--------------- geruecht/gastro/routes.py | 17 ++++++---- geruecht/logger.py | 7 ++-- geruecht/routes.py | 64 +++++++++++++++++++++++-------------- geruecht/user/routes.py | 24 +++++++------- geruecht/vorstand/routes.py | 40 +++++++++++++++-------- 9 files changed, 185 insertions(+), 120 deletions(-) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index 3d756db..d22d87c 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -11,7 +11,7 @@ creditL = getCreditLogger() baruser = Blueprint("baruser", __name__) -ldap= lc.LDAPController() +ldap = lc.LDAPController() userController = uc.UserController() @@ -34,8 +34,6 @@ def _bar(**kwargs): geruecht = None geruecht = user.getGeruecht(datetime.now().year) if geruecht is not None: - month = geruecht.getMonth(datetime.now().month) - amount = month[0] - month[1] all = geruecht.getSchulden() if all != 0: if all >= 0: @@ -43,13 +41,13 @@ def _bar(**kwargs): else: type = 'amount' dic[user.uid] = {"username": user.uid, - "firstname": user.firstname, - "lastname": user.lastname, - "amount": all, - "locked": user.locked, - "type": type - } - debug.debug("return {{}}".format(dic)) + "firstname": user.firstname, + "lastname": user.lastname, + "amount": all, + "locked": user.locked, + "type": type + } + debug.debug("return {{ {} }}".format(dic)) return jsonify(dic) except Exception as err: debug.debug("exception", exc_info=True) @@ -74,7 +72,8 @@ def _baradd(**kwargs): amount = int(data['amount']) date = datetime.now() - userController.addAmount(userID, amount, year=date.year, month=date.month) + userController.addAmount( + userID, amount, year=date.year, month=date.month) user = userController.getUser(userID) geruecht = user.getGeruecht(year=date.year) month = geruecht.getMonth(month=date.month) @@ -87,8 +86,9 @@ def _baradd(**kwargs): dic = user.toJSON() dic['amount'] = abs(all) dic['type'] = type - debug.debug("return {{}}".format(dic)) - creditL.info("{} Baruser {} {} fügt {} {} {} € Schulden hinzu.".format(date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amount/100)) + debug.debug("return {{ {} }}".format(dic)) + creditL.info("{} Baruser {} {} fügt {} {} {} € Schulden hinzu.".format( + date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amount/100)) return jsonify(dic) except Exception as err: debug.debug("exception", exc_info=True) @@ -110,12 +110,13 @@ def _getUsers(**kwargs): try: retVal = {} retVal = ldap.getAllUser() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @baruser.route("/bar/storno", methods=['POST']) @login_required(groups=[BAR]) def _storno(**kwargs): @@ -134,7 +135,8 @@ def _storno(**kwargs): amount = int(data['amount']) date = datetime.now() - userController.addCredit(userID, amount, year=date.year, month=date.month) + userController.addCredit( + userID, amount, year=date.year, month=date.month) user = userController.getUser(userID) geruecht = user.getGeruecht(year=date.year) month = geruecht.getMonth(month=date.month) @@ -147,13 +149,15 @@ def _storno(**kwargs): dic = user.toJSON() dic['amount'] = abs(all) dic['type'] = type - debug.debug("return {{}}".format(dic)) - creditL.info("{} Baruser {} {} storniert {} € von {} {}".format(date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amount/100, user.firstname, user.lastname)) + debug.debug("return {{ {} }}".format(dic)) + creditL.info("{} Baruser {} {} storniert {} € von {} {}".format( + date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amount/100, user.firstname, user.lastname)) return jsonify(dic) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @baruser.route("/barGetUser", methods=['POST']) @login_required(groups=[BAR]) def _getUser(**kwargs): @@ -171,14 +175,15 @@ def _getUser(**kwargs): retVal = user.toJSON() retVal['amount'] = amount retVal['type'] = type - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @baruser.route("/search", methods=['GET']) -@login_required(groups=[BAR, MONEY, USER,VORSTAND]) +@login_required(groups=[BAR, MONEY, USER, VORSTAND]) def _search(**kwargs): debug.info("/search") try: @@ -187,7 +192,7 @@ def _search(**kwargs): if user['username'] == 'extern': retVal.remove(user) break - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) diff --git a/geruecht/configparser.py b/geruecht/configparser.py index 96dfadd..2106e93 100644 --- a/geruecht/configparser.py +++ b/geruecht/configparser.py @@ -15,6 +15,7 @@ default = { } } + class ConifgParser(): def __init__(self, file='config.yml'): self.file = file @@ -22,32 +23,40 @@ class ConifgParser(): self.config = yaml.safe_load(f) if 'Database' not in self.config: - self.__error__('Wrong Configuration for Database. You should configure databaseconfig with "URL", "user", "passwd", "database"') + self.__error__( + 'Wrong Configuration for Database. You should configure databaseconfig with "URL", "user", "passwd", "database"') if 'URL' not in self.config['Database'] or 'user' not in self.config['Database'] or 'passwd' not in self.config['Database'] or 'database' not in self.config['Database']: - self.__error__('Wrong Configuration for Database. You should configure databaseconfig with "URL", "user", "passwd", "database"') + self.__error__( + 'Wrong Configuration for Database. You should configure databaseconfig with "URL", "user", "passwd", "database"') self.db = self.config['Database'] DEBUG.debug("Set Databaseconfig: {}".format(self.db)) if 'LDAP' not in self.config: - self.__error__('Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"') + self.__error__( + 'Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"') if 'URL' not in self.config['LDAP'] or 'dn' not in self.config['LDAP']: - self.__error__('Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"') + self.__error__( + 'Wrong Configuration for LDAP. You should configure ldapconfig with "URL" and "dn"') if 'port' not in self.config['LDAP']: - DEBUG.info('No Config for port in LDAP found. Set it to default: {}'.format(389)) + DEBUG.info( + 'No Config for port in LDAP found. Set it to default: {}'.format(389)) self.config['LDAP']['port'] = 389 self.ldap = self.config['LDAP'] DEBUG.info("Set LDAPconfig: {}".format(self.ldap)) if 'AccessTokenLifeTime' in self.config: self.accessTokenLifeTime = int(self.config['AccessTokenLifeTime']) - DEBUG.info("Set AccessTokenLifeTime: {}".format(self.accessTokenLifeTime)) + DEBUG.info("Set AccessTokenLifeTime: {}".format( + self.accessTokenLifeTime)) else: self.accessTokenLifeTime = default['AccessTokenLifeTime'] - DEBUG.info("No Config for AccessTokenLifetime found. Set it to default: {}".format(self.accessTokenLifeTime)) + DEBUG.info("No Config for AccessTokenLifetime found. Set it to default: {}".format( + self.accessTokenLifeTime)) if 'Mail' not in self.config: self.config['Mail'] = default['Mail'] - DEBUG.info('No Conifg for Mail found. Set it to defaul: {}'.format(self.config['Mail'])) + DEBUG.info('No Conifg for Mail found. Set it to defaul: {}'.format( + self.config['Mail'])) if 'URL' not in self.config['Mail']: self.config['Mail']['URL'] = default['Mail']['URL'] DEBUG.info("No Config for URL in Mail found. Set it to default") @@ -72,7 +81,6 @@ class ConifgParser(): self.mail = self.config['Mail'] DEBUG.info('Set Mailconfig: {}'.format(self.mail)) - def getLDAP(self): return self.ldap @@ -89,5 +97,6 @@ class ConifgParser(): DEBUG.error(msg, exc_info=True) sys.exit(-1) + if __name__ == '__main__': - ConifgParser() \ No newline at end of file + ConifgParser() diff --git a/geruecht/decorator.py b/geruecht/decorator.py index 582eb08..c01bd77 100644 --- a/geruecht/decorator.py +++ b/geruecht/decorator.py @@ -1,6 +1,8 @@ from functools import wraps from .logger import getDebugLogger DEBUG = getDebugLogger() + + def login_required(**kwargs): import geruecht.controller.accesTokenController as ac from geruecht.model import BAR, USER, MONEY, GASTRO @@ -9,20 +11,22 @@ def login_required(**kwargs): groups = [USER, BAR, GASTRO, MONEY] if "groups" in kwargs: groups = kwargs["groups"] - DEBUG.debug("groups are {{}}".format(groups)) + DEBUG.debug("groups are {{ {} }}".format(groups)) + def real_decorator(func): @wraps(func) def wrapper(*args, **kwargs): token = request.headers.get('Token') - DEBUG.debug("token is {{}}".format(token)) + DEBUG.debug("token is {{ {} }}".format(token)) accToken = accessController.validateAccessToken(token, groups) - DEBUG.debug("accToken is {{}}".format(accToken)) + DEBUG.debug("accToken is {{ {} }}".format(accToken)) kwargs['accToken'] = accToken if accToken: - DEBUG.debug("token {{}} is valid".format(token)) + DEBUG.debug("token {{ {} }} is valid".format(token)) return func(*args, **kwargs) else: - DEBUG.warning("token {{}} is not valid".format(token)) - return jsonify({"error": "error", "message": "permission denied"}), 401 + DEBUG.warning("token {{ {} }} is not valid".format(token)) + return jsonify({"error": "error", + "message": "permission denied"}), 401 return wrapper - return real_decorator \ No newline at end of file + return real_decorator diff --git a/geruecht/finanzer/routes.py b/geruecht/finanzer/routes.py index 93c7969..96b72d1 100644 --- a/geruecht/finanzer/routes.py +++ b/geruecht/finanzer/routes.py @@ -30,13 +30,15 @@ def _getFinanzer(**kwargs): dic = {} for user in users: dic[user.uid] = user.toJSON() - dic[user.uid]['creditList'] = {credit.year: credit.toJSON() for credit in user.geruechte} - debug.debug("return {{}}".format(dic)) + dic[user.uid]['creditList'] = { + credit.year: credit.toJSON() for credit in user.geruechte} + debug.debug("return {{ {} }}".format(dic)) return jsonify(dic) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @finanzer.route("/finanzerAddAmount", methods=['POST']) @login_required(groups=[MONEY]) def _addAmount(**kwargs): @@ -57,23 +59,27 @@ def _addAmount(**kwargs): amount = int(data['amount']) try: year = int(data['year']) - except KeyError as er: + except KeyError: year = datetime.now().year try: month = int(data['month']) - except KeyError as er: + except KeyError: month = datetime.now().month - userController.addAmount(userID, amount, year=year, month=month, finanzer=True) + userController.addAmount( + userID, amount, year=year, month=month, finanzer=True) user = userController.getUser(userID) - retVal = {str(geruecht.year): geruecht.toJSON() for geruecht in user.geruechte} + retVal = {str(geruecht.year): geruecht.toJSON() + for geruecht in user.geruechte} retVal['locked'] = user.locked - debug.debug("return {{}}".format(retVal)) - creditL.info("{} Finanzer {} {} fügt {} {} {} € Schulden hinzu.".format(datetime(year,month).date(), kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amount/100)) + debug.debug("return {{ {} }}".format(retVal)) + creditL.info("{} Finanzer {} {} fügt {} {} {} € Schulden hinzu.".format(datetime(year, month, 1).date( + ), kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amount/100)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @finanzer.route("/finanzerAddCredit", methods=['POST']) @login_required(groups=[MONEY]) def _addCredit(**kwargs): @@ -95,22 +101,22 @@ def _addCredit(**kwargs): try: year = int(data['year']) - except KeyError as er: + except KeyError: year = datetime.now().year try: month = int(data['month']) - except KeyError as er: + except KeyError: month = datetime.now().month - userController.addCredit(userID, credit, year=year, month=month).toJSON() + userController.addCredit( + userID, credit, year=year, month=month).toJSON() user = userController.getUser(userID) - retVal = {str(geruecht.year): geruecht.toJSON() for geruecht in user.geruechte} + retVal = {str(geruecht.year): geruecht.toJSON() + for geruecht in user.geruechte} retVal['locked'] = user.locked - debug.debug("return {{}}".format(retVal)) - creditL.info("{} Finanzer {} {} fügt {} {} {} € Guthaben hinzu.".format(datetime(year, month).date(), - kwargs['accToken'].user.firstname, - kwargs['accToken'].user.lastname, - credit / 100)) + debug.debug("return {{ {} }}".format(retVal)) + creditL.info("{} Finanzer {} {} fügt {} {} {} € Guthaben hinzu.".format(datetime(year, month, 1).date( + ), kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, credit / 100)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -126,7 +132,7 @@ def _finanzerLock(**kwargs): username = data['userId'] locked = bool(data['locked']) retVal = userController.lockUser(username, locked).toJSON() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -142,13 +148,15 @@ def _finanzerSetConfig(**kwargs): username = data['userId'] autoLock = bool(data['autoLock']) limit = int(data['limit']) - retVal = userController.updateConfig(username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON() - debug.debug("return {{}}".format(retVal)) + retVal = userController.updateConfig( + username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON() + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @finanzer.route("/finanzerAddUser", methods=['POST']) @login_required(groups=[MONEY]) def _finanzerAddUser(**kwargs): @@ -161,13 +169,15 @@ def _finanzerAddUser(**kwargs): dic = {} for user in users: dic[user.uid] = user.toJSON() - dic[user.uid]['creditList'] = {credit.year: credit.toJSON() for credit in user.geruechte} - debug.debug("return {{}}".format(dic)) + dic[user.uid]['creditList'] = { + credit.year: credit.toJSON() for credit in user.geruechte} + debug.debug("return {{ {} }}".format(dic)) return jsonify(dic), 200 except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @finanzer.route("/finanzerSendOneMail", methods=['POST']) @login_required(groups=[MONEY]) def _finanzerSendOneMail(**kwargs): @@ -176,20 +186,21 @@ def _finanzerSendOneMail(**kwargs): data = request.get_json() username = data['userId'] retVal = userController.sendMail(username) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @finanzer.route("/finanzerSendAllMail", methods=['GET']) @login_required(groups=[MONEY]) def _finanzerSendAllMail(**kwargs): debug.info("/finanzerSendAllMail") try: retVal = userController.sendAllMail() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) - return jsonify({"error": str(err)}), 500 \ No newline at end of file + return jsonify({"error": str(err)}), 500 diff --git a/geruecht/gastro/routes.py b/geruecht/gastro/routes.py index 787faf8..5ddb3c1 100644 --- a/geruecht/gastro/routes.py +++ b/geruecht/gastro/routes.py @@ -10,6 +10,7 @@ gastrouser = Blueprint('gastrouser', __name__) userController = uc.UserController() + @gastrouser.route('/gastro/setDrink', methods=['POST']) @login_required(groups=[GASTRO]) def setDrink(**kwargs): @@ -17,12 +18,13 @@ def setDrink(**kwargs): try: data = request.get_json() retVal = userController.setDrinkPrice(data) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @gastrouser.route('/gastro/updateDrink', methods=['POST']) @login_required(groups=[GASTRO]) def updateDrink(**kwargs): @@ -30,12 +32,13 @@ def updateDrink(**kwargs): try: data = request.get_json() retVal = userController.updateDrinkPrice(data) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @gastrouser.route('/gastro/deleteDrink', methods=['POST']) @login_required(groups=[GASTRO]) def deleteDrink(**kwargs): @@ -43,13 +46,14 @@ def deleteDrink(**kwargs): try: data = request.get_json() id = data['id'] - retVal = userController.deletDrinkPrice({"id": id}) + userController.deletDrinkPrice({"id": id}) debug.debug("return ok") return jsonify({"ok": "ok"}) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @gastrouser.route('/gastro/setDrinkType', methods=['POST']) @login_required(groups=[GASTRO]) def setType(**kwark): @@ -58,12 +62,13 @@ def setType(**kwark): data = request.get_json() name = data['name'] retVal = userController.setDrinkType(name) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @gastrouser.route('/gastro/updateDrinkType', methods=['POST']) @login_required(groups=[GASTRO]) def updateType(**kwargs): @@ -71,12 +76,13 @@ def updateType(**kwargs): try: data = request.get_json() retVal = userController.updateDrinkType(data) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @gastrouser.route('/gastro/deleteDrinkType', methods=['POST']) @login_required(groups=[GASTRO]) def deleteType(**kwargs): @@ -89,4 +95,3 @@ def deleteType(**kwargs): except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 - diff --git a/geruecht/logger.py b/geruecht/logger.py index 1d9b9a8..f63ef04 100644 --- a/geruecht/logger.py +++ b/geruecht/logger.py @@ -4,7 +4,7 @@ import yaml from os import path if not path.exists("geruecht/log/debug"): - a = path.join(path.curdir ,"geruecht", "log", "debug") + a = path.join(path.curdir, "geruecht", "log", "debug") if not path.exists("geruecht/log/info"): b = path.join(path.curdir, "geruecht", "log", "info") @@ -14,11 +14,14 @@ with open("geruecht/logging.yml", 'rt') as file: config = yaml.safe_load(file.read()) logging.config.dictConfig(config) + def getDebugLogger(): return logging.getLogger("debug_logger") + def getCreditLogger(): return logging.getLogger("credit_logger") + def getJobsLogger(): - return logging.getLogger("jobs_logger") \ No newline at end of file + return logging.getLogger("jobs_logger") diff --git a/geruecht/routes.py b/geruecht/routes.py index cd5792f..ce92b09 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -12,40 +12,44 @@ userController = uc.UserController() debug = getDebugLogger() + @app.route("/pricelist", methods=['GET']) def _getPricelist(): try: debug.info("get pricelist") retVal = userController.getPricelist() - debug.info("return pricelist {{}}".format(retVal)) + debug.info("return pricelist {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.warning("exception in get pricelist.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route('/drinkTypes', methods=['GET']) def getTypes(): try: debug.info("get drinktypes") retVal = userController.getAllDrinkTypes() - debug.info("return drinktypes {{}}".format(retVal)) + debug.info("return drinktypes {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.warning("exception in get drinktypes.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route('/getAllStatus', methods=['GET']) @login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND]) def _getAllStatus(**kwargs): try: debug.info("get all status for users") retVal = userController.getAllStatus() - debug.info("return all status for users {{}}".format(retVal)) + debug.info("return all status for users {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.warning("exception in get all status for users.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route('/getStatus', methods=['POST']) @login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND]) def _getStatus(**kwargs): @@ -53,28 +57,32 @@ def _getStatus(**kwargs): debug.info("get status from user") data = request.get_json() name = data['name'] - debug.info("get status from user {{}}".format(name)) + debug.info("get status from user {{ {} }}".format(name)) retVal = userController.getStatus(name) - debug.info("return status from user {{}} : {{}}".format(name, retVal)) + debug.info( + "return status from user {{ {} }} : {{ {} }}".format(name, retVal)) return jsonify(retVal) except Exception as err: debug.warning("exception in get status from user.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route('/getUsers', methods=['GET']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _getUsers(**kwargs): try: debug.info("get all users from database") users = userController.getAllUsersfromDB() - debug.debug("users are {{}}".format(users)) + debug.debug("users are {{ {} }}".format(users)) retVal = [user.toJSON() for user in users] - debug.info("return all users from database {{}}".format(retVal)) + debug.info("return all users from database {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: - debug.warning("exception in get all users from database.", exc_info=True) + debug.warning( + "exception in get all users from database.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route("/getLifeTime", methods=['GET']) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) def _getLifeTime(**kwargs): @@ -82,14 +90,16 @@ def _getLifeTime(**kwargs): debug.info("get lifetime of accesstoken") if 'accToken' in kwargs: accToken = kwargs['accToken'] - debug.debug("accessToken is {{}}".format(accToken)) + debug.debug("accessToken is {{ {} }}".format(accToken)) retVal = {"value": accToken.lifetime} - debug.info("return get lifetime from accesstoken {{}}".format(retVal)) + debug.info( + "return get lifetime from accesstoken {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.info("exception in get lifetime of accesstoken.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route("/saveLifeTime", methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) def _saveLifeTime(**kwargs): @@ -97,21 +107,25 @@ def _saveLifeTime(**kwargs): debug.info("save lifetime for accessToken") if 'accToken' in kwargs: accToken = kwargs['accToken'] - debug.debug("accessToken is {{}}".format(accToken)) + debug.debug("accessToken is {{ {} }}".format(accToken)) data = request.get_json() lifetime = data['value'] - debug.debug("lifetime is {{}}".format(lifetime)) - debug.info("set lifetime {{}} to accesstoken {{}}".format(lifetime, accToken)) + debug.debug("lifetime is {{ {} }}".format(lifetime)) + debug.info("set lifetime {{ {} }} to accesstoken {{ {} }}".format( + lifetime, accToken)) accToken.lifetime = lifetime debug.info("update accesstoken timestamp") accToken.updateTimestamp() retVal = {"value": accToken.lifetime} - debug.info("return save lifetime for accessToken {{}}".format(retVal)) + debug.info( + "return save lifetime for accessToken {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: - debug.warning("exception in save lifetime for accesstoken.", exc_info=True) + debug.warning( + "exception in save lifetime for accesstoken.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route("/logout", methods=['GET']) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) def _logout(**kwargs): @@ -119,7 +133,7 @@ def _logout(**kwargs): debug.info("logout user") if 'accToken' in kwargs: accToken = kwargs['accToken'] - debug.debug("accesstoken is {{}}".format(accToken)) + debug.debug("accesstoken is {{ {} }}".format(accToken)) debug.info("delete accesstoken") accesTokenController.deleteAccessToken(accToken) debug.info("return ok logout user") @@ -128,6 +142,7 @@ def _logout(**kwargs): debug.warning("exception in logout user.", exc_info=True) return jsonify({"error": str(err)}), 500 + @app.route("/login", methods=['POST']) def _login(): """ Login User @@ -142,24 +157,25 @@ def _login(): data = request.get_json() username = data['username'] password = data['password'] - debug.debug("username is {{}}".format(username)) + debug.debug("username is {{ {} }}".format(username)) try: - debug.info("search {{}} in database".format(username)) + debug.info("search {{ {} }} in database".format(username)) user, ldap_conn = userController.loginUser(username, password) - debug.debug("user is {{}}".format(user)) + debug.debug("user is {{ {} }}".format(user)) user.password = password token = accesTokenController.createAccesToken(user, ldap_conn) - debug.debug("accesstoken is {{}}".format(token)) + debug.debug("accesstoken is {{ {} }}".format(token)) debug.info("validate accesstoken") - dic = accesTokenController.validateAccessToken(token, [USER, EXTERN]).user.toJSON() + dic = accesTokenController.validateAccessToken( + token, [USER, EXTERN]).user.toJSON() dic["token"] = token dic["accessToken"] = token - debug.info("User {{}} success login.".format(username)) - debug.info("return login {{}}".format(dic)) + debug.info("User {{ {} }} success login.".format(username)) + debug.info("return login {{ {} }}".format(dic)) return jsonify(dic) except PermissionDenied as err: debug.warning("permission denied exception in logout", exc_info=True) return jsonify({"error": str(err)}), 401 - except Exception as err: + except Exception: debug.warning("exception in logout.", exc_info=True) return jsonify({"error": "permission denied"}), 401 diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 9e0f225..357e784 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -24,9 +24,9 @@ def _main(**kwargs): accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) - except Exception as err: + except Exception: debug.debug("exception", exc_info=True) return jsonify("error", "something went wrong"), 500 @@ -44,10 +44,10 @@ def _addAmount(**kwargs): accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) creditL.info("{} {} {} fügt sich selbst {} € Schulden hinzu".format(date, accToken.user.firstname, accToken.user.lastname, amount/100)) return jsonify(retVal) - except Exception as err: + except Exception: debug.debug("exception", exc_info=True) return jsonify({"error": "something went wrong"}), 500 @@ -62,7 +62,7 @@ def _saveConfig(**kwargs): accToken.user = userController.modifyUser(accToken.user, accToken.ldap_conn, data) retVal = accToken.user.toJSON() retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -101,7 +101,7 @@ def _getUser(**kwargs): 'worker': userController.getWorker(date), 'day': lockedDay } - debug.debug("retrun {{}}".format(retVal)) + debug.debug("retrun {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -121,7 +121,7 @@ def _addUser(**kwargs): year = data['year'] date = datetime(year,month,day,12) retVal = userController.addWorker(user.uid, date, userExc=True) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(user.firstname, user.lastname, date.date())) return jsonify(retVal) except DayLocked as err: @@ -176,7 +176,7 @@ def _transactJob(**kwargs): retVal['from_user'] = retVal['from_user'].toJSON() retVal['to_user'] = retVal['to_user'].toJSON() retVal['date'] = {'year': year, 'month': month, 'day': day} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) jobL.info("Mitglied {} {} sendet Dienstanfrage an Mitglied {} {} am {}".format(from_userl.firstname, from_userl.lastname, to_userl.firstname, to_userl.lastname, date.date())) return jsonify(retVal) except Exception as err: @@ -205,7 +205,7 @@ def _answer(**kwargs): retVal['from_user'] = retVal['from_user'].toJSON() retVal['to_user'] = retVal['to_user'].toJSON() retVal['date'] = {'year': year, 'month': month, 'day': day} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) jobL.info("Mitglied {} {} beantwortet Dienstanfrage von {} {} am {} mit {}".format(to_userl.firstname, to_userl.lastname, from_userl.firstname, from_userl.lastname, date.date(), 'JA' if answer else 'NEIN')) return jsonify(retVal) except Exception as err: @@ -231,7 +231,7 @@ def _requests(**kwargs): data['to_user'] = data['to_user'].toJSON() data_date = data['date'] data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -256,7 +256,7 @@ def _getTransactJobs(**kwargs): data['to_user'] = data['to_user'].toJSON() data_date = data['date'] data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) @@ -310,7 +310,7 @@ def _storno(**kwargs): accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) creditL.info("{} {} {} storniert {} €".format(date, user.firstname, user.lastname, amount/100)) return jsonify(retVal) except Exception as err: diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index dd0d81c..60070d5 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -11,7 +11,8 @@ jobL = getJobsLogger() vorstand = Blueprint("vorstand", __name__) userController = uc.UserController() -ldap= lc.LDAPController() +ldap = lc.LDAPController() + @vorstand.route('/um/setStatus', methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) @@ -21,12 +22,13 @@ def _setStatus(**kwargs): data = request.get_json() name = data['name'] retVal = userController.setStatus(name) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route('/um/updateStatus', methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _updateStatus(**kwargs): @@ -34,12 +36,13 @@ def _updateStatus(**kwargs): try: data = request.get_json() retVal = userController.updateStatus(data) - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route('/um/deleteStatus', methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _deleteStatus(**kwargs): @@ -53,6 +56,7 @@ def _deleteStatus(**kwargs): debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @vorstand.route('/um/updateStatusUser', methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _updateStatusUser(**kwargs): @@ -62,12 +66,13 @@ def _updateStatusUser(**kwargs): username = data['username'] status = data['status'] retVal = userController.updateStatusOfUser(username, status).toJSON() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route('/um/updateVoting', methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _updateVoting(**kwargs): @@ -77,12 +82,13 @@ def _updateVoting(**kwargs): username = data['username'] voting = data['voting'] retVal = userController.updateVotingOfUser(username, voting).toJSON() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route("/sm/addUser", methods=['POST', 'GET']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _addUser(**kwargs): @@ -93,16 +99,18 @@ def _addUser(**kwargs): day = data['day'] month = data['month'] year = data['year'] - date = datetime(year,month,day,12) + date = datetime(year, month, day, 12) retVal = userController.addWorker(user['username'], date) - debug.debug("retrun {{}}".format(retVal)) + debug.debug("retrun {{ {} }}".format(retVal)) userl = userController.getUser(user) - jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date())) + jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format( + kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date())) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route("/sm/getUser", methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _getUser(**kwargs): @@ -136,12 +144,13 @@ def _getUser(**kwargs): 'worker': userController.getWorker(date), 'day': lockedDay } - debug.debug("return {{}}".format(retVal)) - return jsonify(retVal) + debug.debug("return {{ {} }}".format(retVal)) + return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route("/sm/deleteUser", methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _deletUser(**kwargs): @@ -156,12 +165,14 @@ def _deletUser(**kwargs): userController.deleteWorker(user['username'], date) debug.debug("return ok") user = userController.getUser(user) - jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date())) + jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format( + kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date())) return jsonify({"ok": "ok"}) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @vorstand.route("/sm/lockDay", methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _lockDay(**kwargs): @@ -192,20 +203,21 @@ def _lockDay(**kwargs): }, 'locked': lockedDay['locked'] } - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({'error': err}), 409 + @vorstand.route("/sm/searchWithExtern", methods=['GET']) @login_required(groups=[VORSTAND]) def _search(**kwargs): debug.info("/sm/searchWithExtern") try: retVal = ldap.getAllUser() - debug.debug("return {{}}".format(retVal)) + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) - return jsonify({"error": str(err)}), 500 \ No newline at end of file + return jsonify({"error": str(err)}), 500