replace string with '{{}}' to '{{ {} }}' for logging

fixed missing values (bugs that crash)
This commit is contained in:
Gröger 2020-03-10 11:08:24 +01:00
parent ba5f033981
commit f029aa6096
9 changed files with 185 additions and 120 deletions

View File

@ -11,7 +11,7 @@ creditL = getCreditLogger()
baruser = Blueprint("baruser", __name__) baruser = Blueprint("baruser", __name__)
ldap= lc.LDAPController() ldap = lc.LDAPController()
userController = uc.UserController() userController = uc.UserController()
@ -34,8 +34,6 @@ def _bar(**kwargs):
geruecht = None geruecht = None
geruecht = user.getGeruecht(datetime.now().year) geruecht = user.getGeruecht(datetime.now().year)
if geruecht is not None: if geruecht is not None:
month = geruecht.getMonth(datetime.now().month)
amount = month[0] - month[1]
all = geruecht.getSchulden() all = geruecht.getSchulden()
if all != 0: if all != 0:
if all >= 0: if all >= 0:
@ -43,13 +41,13 @@ def _bar(**kwargs):
else: else:
type = 'amount' type = 'amount'
dic[user.uid] = {"username": user.uid, dic[user.uid] = {"username": user.uid,
"firstname": user.firstname, "firstname": user.firstname,
"lastname": user.lastname, "lastname": user.lastname,
"amount": all, "amount": all,
"locked": user.locked, "locked": user.locked,
"type": type "type": type
} }
debug.debug("return {{}}".format(dic)) debug.debug("return {{ {} }}".format(dic))
return jsonify(dic) return jsonify(dic)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -74,7 +72,8 @@ def _baradd(**kwargs):
amount = int(data['amount']) amount = int(data['amount'])
date = datetime.now() 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) user = userController.getUser(userID)
geruecht = user.getGeruecht(year=date.year) geruecht = user.getGeruecht(year=date.year)
month = geruecht.getMonth(month=date.month) month = geruecht.getMonth(month=date.month)
@ -87,8 +86,9 @@ def _baradd(**kwargs):
dic = user.toJSON() dic = user.toJSON()
dic['amount'] = abs(all) dic['amount'] = abs(all)
dic['type'] = type dic['type'] = type
debug.debug("return {{}}".format(dic)) 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)) 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) return jsonify(dic)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -110,12 +110,13 @@ def _getUsers(**kwargs):
try: try:
retVal = {} retVal = {}
retVal = ldap.getAllUser() retVal = ldap.getAllUser()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@baruser.route("/bar/storno", methods=['POST']) @baruser.route("/bar/storno", methods=['POST'])
@login_required(groups=[BAR]) @login_required(groups=[BAR])
def _storno(**kwargs): def _storno(**kwargs):
@ -134,7 +135,8 @@ def _storno(**kwargs):
amount = int(data['amount']) amount = int(data['amount'])
date = datetime.now() 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) user = userController.getUser(userID)
geruecht = user.getGeruecht(year=date.year) geruecht = user.getGeruecht(year=date.year)
month = geruecht.getMonth(month=date.month) month = geruecht.getMonth(month=date.month)
@ -147,13 +149,15 @@ def _storno(**kwargs):
dic = user.toJSON() dic = user.toJSON()
dic['amount'] = abs(all) dic['amount'] = abs(all)
dic['type'] = type dic['type'] = type
debug.debug("return {{}}".format(dic)) 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)) creditL.info("{} Baruser {} {} storniert {} € von {} {}".format(
date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amount/100, user.firstname, user.lastname))
return jsonify(dic) return jsonify(dic)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@baruser.route("/barGetUser", methods=['POST']) @baruser.route("/barGetUser", methods=['POST'])
@login_required(groups=[BAR]) @login_required(groups=[BAR])
def _getUser(**kwargs): def _getUser(**kwargs):
@ -171,14 +175,15 @@ def _getUser(**kwargs):
retVal = user.toJSON() retVal = user.toJSON()
retVal['amount'] = amount retVal['amount'] = amount
retVal['type'] = type retVal['type'] = type
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@baruser.route("/search", methods=['GET']) @baruser.route("/search", methods=['GET'])
@login_required(groups=[BAR, MONEY, USER,VORSTAND]) @login_required(groups=[BAR, MONEY, USER, VORSTAND])
def _search(**kwargs): def _search(**kwargs):
debug.info("/search") debug.info("/search")
try: try:
@ -187,7 +192,7 @@ def _search(**kwargs):
if user['username'] == 'extern': if user['username'] == 'extern':
retVal.remove(user) retVal.remove(user)
break break
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)

View File

@ -15,6 +15,7 @@ default = {
} }
} }
class ConifgParser(): class ConifgParser():
def __init__(self, file='config.yml'): def __init__(self, file='config.yml'):
self.file = file self.file = file
@ -22,32 +23,40 @@ class ConifgParser():
self.config = yaml.safe_load(f) self.config = yaml.safe_load(f)
if 'Database' not in self.config: 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']: 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'] self.db = self.config['Database']
DEBUG.debug("Set Databaseconfig: {}".format(self.db)) DEBUG.debug("Set Databaseconfig: {}".format(self.db))
if 'LDAP' not in self.config: 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']: 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']: 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.config['LDAP']['port'] = 389
self.ldap = self.config['LDAP'] self.ldap = self.config['LDAP']
DEBUG.info("Set LDAPconfig: {}".format(self.ldap)) DEBUG.info("Set LDAPconfig: {}".format(self.ldap))
if 'AccessTokenLifeTime' in self.config: if 'AccessTokenLifeTime' in self.config:
self.accessTokenLifeTime = int(self.config['AccessTokenLifeTime']) self.accessTokenLifeTime = int(self.config['AccessTokenLifeTime'])
DEBUG.info("Set AccessTokenLifeTime: {}".format(self.accessTokenLifeTime)) DEBUG.info("Set AccessTokenLifeTime: {}".format(
self.accessTokenLifeTime))
else: else:
self.accessTokenLifeTime = default['AccessTokenLifeTime'] 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: if 'Mail' not in self.config:
self.config['Mail'] = default['Mail'] 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']: if 'URL' not in self.config['Mail']:
self.config['Mail']['URL'] = default['Mail']['URL'] self.config['Mail']['URL'] = default['Mail']['URL']
DEBUG.info("No Config for URL in Mail found. Set it to default") DEBUG.info("No Config for URL in Mail found. Set it to default")
@ -72,7 +81,6 @@ class ConifgParser():
self.mail = self.config['Mail'] self.mail = self.config['Mail']
DEBUG.info('Set Mailconfig: {}'.format(self.mail)) DEBUG.info('Set Mailconfig: {}'.format(self.mail))
def getLDAP(self): def getLDAP(self):
return self.ldap return self.ldap
@ -89,5 +97,6 @@ class ConifgParser():
DEBUG.error(msg, exc_info=True) DEBUG.error(msg, exc_info=True)
sys.exit(-1) sys.exit(-1)
if __name__ == '__main__': if __name__ == '__main__':
ConifgParser() ConifgParser()

View File

@ -1,6 +1,8 @@
from functools import wraps from functools import wraps
from .logger import getDebugLogger from .logger import getDebugLogger
DEBUG = getDebugLogger() DEBUG = getDebugLogger()
def login_required(**kwargs): def login_required(**kwargs):
import geruecht.controller.accesTokenController as ac import geruecht.controller.accesTokenController as ac
from geruecht.model import BAR, USER, MONEY, GASTRO from geruecht.model import BAR, USER, MONEY, GASTRO
@ -9,20 +11,22 @@ def login_required(**kwargs):
groups = [USER, BAR, GASTRO, MONEY] groups = [USER, BAR, GASTRO, MONEY]
if "groups" in kwargs: if "groups" in kwargs:
groups = kwargs["groups"] groups = kwargs["groups"]
DEBUG.debug("groups are {{}}".format(groups)) DEBUG.debug("groups are {{ {} }}".format(groups))
def real_decorator(func): def real_decorator(func):
@wraps(func) @wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
token = request.headers.get('Token') token = request.headers.get('Token')
DEBUG.debug("token is {{}}".format(token)) DEBUG.debug("token is {{ {} }}".format(token))
accToken = accessController.validateAccessToken(token, groups) accToken = accessController.validateAccessToken(token, groups)
DEBUG.debug("accToken is {{}}".format(accToken)) DEBUG.debug("accToken is {{ {} }}".format(accToken))
kwargs['accToken'] = accToken kwargs['accToken'] = accToken
if accToken: if accToken:
DEBUG.debug("token {{}} is valid".format(token)) DEBUG.debug("token {{ {} }} is valid".format(token))
return func(*args, **kwargs) return func(*args, **kwargs)
else: else:
DEBUG.warning("token {{}} is not valid".format(token)) DEBUG.warning("token {{ {} }} is not valid".format(token))
return jsonify({"error": "error", "message": "permission denied"}), 401 return jsonify({"error": "error",
"message": "permission denied"}), 401
return wrapper return wrapper
return real_decorator return real_decorator

View File

@ -30,13 +30,15 @@ def _getFinanzer(**kwargs):
dic = {} dic = {}
for user in users: for user in users:
dic[user.uid] = user.toJSON() dic[user.uid] = user.toJSON()
dic[user.uid]['creditList'] = {credit.year: credit.toJSON() for credit in user.geruechte} dic[user.uid]['creditList'] = {
debug.debug("return {{}}".format(dic)) credit.year: credit.toJSON() for credit in user.geruechte}
debug.debug("return {{ {} }}".format(dic))
return jsonify(dic) return jsonify(dic)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@finanzer.route("/finanzerAddAmount", methods=['POST']) @finanzer.route("/finanzerAddAmount", methods=['POST'])
@login_required(groups=[MONEY]) @login_required(groups=[MONEY])
def _addAmount(**kwargs): def _addAmount(**kwargs):
@ -57,23 +59,27 @@ def _addAmount(**kwargs):
amount = int(data['amount']) amount = int(data['amount'])
try: try:
year = int(data['year']) year = int(data['year'])
except KeyError as er: except KeyError:
year = datetime.now().year year = datetime.now().year
try: try:
month = int(data['month']) month = int(data['month'])
except KeyError as er: except KeyError:
month = datetime.now().month 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) 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 retVal['locked'] = user.locked
debug.debug("return {{}}".format(retVal)) 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)) 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@finanzer.route("/finanzerAddCredit", methods=['POST']) @finanzer.route("/finanzerAddCredit", methods=['POST'])
@login_required(groups=[MONEY]) @login_required(groups=[MONEY])
def _addCredit(**kwargs): def _addCredit(**kwargs):
@ -95,22 +101,22 @@ def _addCredit(**kwargs):
try: try:
year = int(data['year']) year = int(data['year'])
except KeyError as er: except KeyError:
year = datetime.now().year year = datetime.now().year
try: try:
month = int(data['month']) month = int(data['month'])
except KeyError as er: except KeyError:
month = datetime.now().month 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) 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 retVal['locked'] = user.locked
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
creditL.info("{} Finanzer {} {} fügt {} {} {} € Guthaben hinzu.".format(datetime(year, month).date(), creditL.info("{} Finanzer {} {} fügt {} {} {} € Guthaben hinzu.".format(datetime(year, month, 1).date(
kwargs['accToken'].user.firstname, ), kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, credit / 100))
kwargs['accToken'].user.lastname,
credit / 100))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -126,7 +132,7 @@ def _finanzerLock(**kwargs):
username = data['userId'] username = data['userId']
locked = bool(data['locked']) locked = bool(data['locked'])
retVal = userController.lockUser(username, locked).toJSON() retVal = userController.lockUser(username, locked).toJSON()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -142,13 +148,15 @@ def _finanzerSetConfig(**kwargs):
username = data['userId'] username = data['userId']
autoLock = bool(data['autoLock']) autoLock = bool(data['autoLock'])
limit = int(data['limit']) limit = int(data['limit'])
retVal = userController.updateConfig(username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON() retVal = userController.updateConfig(
debug.debug("return {{}}".format(retVal)) username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON()
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@finanzer.route("/finanzerAddUser", methods=['POST']) @finanzer.route("/finanzerAddUser", methods=['POST'])
@login_required(groups=[MONEY]) @login_required(groups=[MONEY])
def _finanzerAddUser(**kwargs): def _finanzerAddUser(**kwargs):
@ -161,13 +169,15 @@ def _finanzerAddUser(**kwargs):
dic = {} dic = {}
for user in users: for user in users:
dic[user.uid] = user.toJSON() dic[user.uid] = user.toJSON()
dic[user.uid]['creditList'] = {credit.year: credit.toJSON() for credit in user.geruechte} dic[user.uid]['creditList'] = {
debug.debug("return {{}}".format(dic)) credit.year: credit.toJSON() for credit in user.geruechte}
debug.debug("return {{ {} }}".format(dic))
return jsonify(dic), 200 return jsonify(dic), 200
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@finanzer.route("/finanzerSendOneMail", methods=['POST']) @finanzer.route("/finanzerSendOneMail", methods=['POST'])
@login_required(groups=[MONEY]) @login_required(groups=[MONEY])
def _finanzerSendOneMail(**kwargs): def _finanzerSendOneMail(**kwargs):
@ -176,20 +186,21 @@ def _finanzerSendOneMail(**kwargs):
data = request.get_json() data = request.get_json()
username = data['userId'] username = data['userId']
retVal = userController.sendMail(username) retVal = userController.sendMail(username)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@finanzer.route("/finanzerSendAllMail", methods=['GET']) @finanzer.route("/finanzerSendAllMail", methods=['GET'])
@login_required(groups=[MONEY]) @login_required(groups=[MONEY])
def _finanzerSendAllMail(**kwargs): def _finanzerSendAllMail(**kwargs):
debug.info("/finanzerSendAllMail") debug.info("/finanzerSendAllMail")
try: try:
retVal = userController.sendAllMail() retVal = userController.sendAllMail()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500

View File

@ -10,6 +10,7 @@ gastrouser = Blueprint('gastrouser', __name__)
userController = uc.UserController() userController = uc.UserController()
@gastrouser.route('/gastro/setDrink', methods=['POST']) @gastrouser.route('/gastro/setDrink', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def setDrink(**kwargs): def setDrink(**kwargs):
@ -17,12 +18,13 @@ def setDrink(**kwargs):
try: try:
data = request.get_json() data = request.get_json()
retVal = userController.setDrinkPrice(data) retVal = userController.setDrinkPrice(data)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/updateDrink', methods=['POST']) @gastrouser.route('/gastro/updateDrink', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def updateDrink(**kwargs): def updateDrink(**kwargs):
@ -30,12 +32,13 @@ def updateDrink(**kwargs):
try: try:
data = request.get_json() data = request.get_json()
retVal = userController.updateDrinkPrice(data) retVal = userController.updateDrinkPrice(data)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/deleteDrink', methods=['POST']) @gastrouser.route('/gastro/deleteDrink', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def deleteDrink(**kwargs): def deleteDrink(**kwargs):
@ -43,13 +46,14 @@ def deleteDrink(**kwargs):
try: try:
data = request.get_json() data = request.get_json()
id = data['id'] id = data['id']
retVal = userController.deletDrinkPrice({"id": id}) userController.deletDrinkPrice({"id": id})
debug.debug("return ok") debug.debug("return ok")
return jsonify({"ok": "ok"}) return jsonify({"ok": "ok"})
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/setDrinkType', methods=['POST']) @gastrouser.route('/gastro/setDrinkType', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def setType(**kwark): def setType(**kwark):
@ -58,12 +62,13 @@ def setType(**kwark):
data = request.get_json() data = request.get_json()
name = data['name'] name = data['name']
retVal = userController.setDrinkType(name) retVal = userController.setDrinkType(name)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/updateDrinkType', methods=['POST']) @gastrouser.route('/gastro/updateDrinkType', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def updateType(**kwargs): def updateType(**kwargs):
@ -71,12 +76,13 @@ def updateType(**kwargs):
try: try:
data = request.get_json() data = request.get_json()
retVal = userController.updateDrinkType(data) retVal = userController.updateDrinkType(data)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/deleteDrinkType', methods=['POST']) @gastrouser.route('/gastro/deleteDrinkType', methods=['POST'])
@login_required(groups=[GASTRO]) @login_required(groups=[GASTRO])
def deleteType(**kwargs): def deleteType(**kwargs):
@ -89,4 +95,3 @@ def deleteType(**kwargs):
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500

View File

@ -4,7 +4,7 @@ import yaml
from os import path from os import path
if not path.exists("geruecht/log/debug"): 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"): if not path.exists("geruecht/log/info"):
b = path.join(path.curdir, "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()) config = yaml.safe_load(file.read())
logging.config.dictConfig(config) logging.config.dictConfig(config)
def getDebugLogger(): def getDebugLogger():
return logging.getLogger("debug_logger") return logging.getLogger("debug_logger")
def getCreditLogger(): def getCreditLogger():
return logging.getLogger("credit_logger") return logging.getLogger("credit_logger")
def getJobsLogger(): def getJobsLogger():
return logging.getLogger("jobs_logger") return logging.getLogger("jobs_logger")

View File

@ -12,40 +12,44 @@ userController = uc.UserController()
debug = getDebugLogger() debug = getDebugLogger()
@app.route("/pricelist", methods=['GET']) @app.route("/pricelist", methods=['GET'])
def _getPricelist(): def _getPricelist():
try: try:
debug.info("get pricelist") debug.info("get pricelist")
retVal = userController.getPricelist() retVal = userController.getPricelist()
debug.info("return pricelist {{}}".format(retVal)) debug.info("return pricelist {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.warning("exception in get pricelist.", exc_info=True) debug.warning("exception in get pricelist.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/drinkTypes', methods=['GET']) @app.route('/drinkTypes', methods=['GET'])
def getTypes(): def getTypes():
try: try:
debug.info("get drinktypes") debug.info("get drinktypes")
retVal = userController.getAllDrinkTypes() retVal = userController.getAllDrinkTypes()
debug.info("return drinktypes {{}}".format(retVal)) debug.info("return drinktypes {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.warning("exception in get drinktypes.", exc_info=True) debug.warning("exception in get drinktypes.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/getAllStatus', methods=['GET']) @app.route('/getAllStatus', methods=['GET'])
@login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND]) @login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND])
def _getAllStatus(**kwargs): def _getAllStatus(**kwargs):
try: try:
debug.info("get all status for users") debug.info("get all status for users")
retVal = userController.getAllStatus() retVal = userController.getAllStatus()
debug.info("return all status for users {{}}".format(retVal)) debug.info("return all status for users {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.warning("exception in get all status for users.", exc_info=True) debug.warning("exception in get all status for users.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/getStatus', methods=['POST']) @app.route('/getStatus', methods=['POST'])
@login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND]) @login_required(groups=[USER, MONEY, GASTRO, BAR, VORSTAND])
def _getStatus(**kwargs): def _getStatus(**kwargs):
@ -53,28 +57,32 @@ def _getStatus(**kwargs):
debug.info("get status from user") debug.info("get status from user")
data = request.get_json() data = request.get_json()
name = data['name'] name = data['name']
debug.info("get status from user {{}}".format(name)) debug.info("get status from user {{ {} }}".format(name))
retVal = userController.getStatus(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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.warning("exception in get status from user.", exc_info=True) debug.warning("exception in get status from user.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/getUsers', methods=['GET']) @app.route('/getUsers', methods=['GET'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _getUsers(**kwargs): def _getUsers(**kwargs):
try: try:
debug.info("get all users from database") debug.info("get all users from database")
users = userController.getAllUsersfromDB() users = userController.getAllUsersfromDB()
debug.debug("users are {{}}".format(users)) debug.debug("users are {{ {} }}".format(users))
retVal = [user.toJSON() for user in 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) return jsonify(retVal)
except Exception as err: 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 return jsonify({"error": str(err)}), 500
@app.route("/getLifeTime", methods=['GET']) @app.route("/getLifeTime", methods=['GET'])
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
def _getLifeTime(**kwargs): def _getLifeTime(**kwargs):
@ -82,14 +90,16 @@ def _getLifeTime(**kwargs):
debug.info("get lifetime of accesstoken") debug.info("get lifetime of accesstoken")
if 'accToken' in kwargs: if 'accToken' in kwargs:
accToken = kwargs['accToken'] accToken = kwargs['accToken']
debug.debug("accessToken is {{}}".format(accToken)) debug.debug("accessToken is {{ {} }}".format(accToken))
retVal = {"value": accToken.lifetime} 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.info("exception in get lifetime of accesstoken.", exc_info=True) debug.info("exception in get lifetime of accesstoken.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/saveLifeTime", methods=['POST']) @app.route("/saveLifeTime", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
def _saveLifeTime(**kwargs): def _saveLifeTime(**kwargs):
@ -97,21 +107,25 @@ def _saveLifeTime(**kwargs):
debug.info("save lifetime for accessToken") debug.info("save lifetime for accessToken")
if 'accToken' in kwargs: if 'accToken' in kwargs:
accToken = kwargs['accToken'] accToken = kwargs['accToken']
debug.debug("accessToken is {{}}".format(accToken)) debug.debug("accessToken is {{ {} }}".format(accToken))
data = request.get_json() data = request.get_json()
lifetime = data['value'] lifetime = data['value']
debug.debug("lifetime is {{}}".format(lifetime)) debug.debug("lifetime is {{ {} }}".format(lifetime))
debug.info("set lifetime {{}} to accesstoken {{}}".format(lifetime, accToken)) debug.info("set lifetime {{ {} }} to accesstoken {{ {} }}".format(
lifetime, accToken))
accToken.lifetime = lifetime accToken.lifetime = lifetime
debug.info("update accesstoken timestamp") debug.info("update accesstoken timestamp")
accToken.updateTimestamp() accToken.updateTimestamp()
retVal = {"value": accToken.lifetime} 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) return jsonify(retVal)
except Exception as err: 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 return jsonify({"error": str(err)}), 500
@app.route("/logout", methods=['GET']) @app.route("/logout", methods=['GET'])
@login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER]) @login_required(groups=[MONEY, GASTRO, VORSTAND, EXTERN, USER])
def _logout(**kwargs): def _logout(**kwargs):
@ -119,7 +133,7 @@ def _logout(**kwargs):
debug.info("logout user") debug.info("logout user")
if 'accToken' in kwargs: if 'accToken' in kwargs:
accToken = kwargs['accToken'] accToken = kwargs['accToken']
debug.debug("accesstoken is {{}}".format(accToken)) debug.debug("accesstoken is {{ {} }}".format(accToken))
debug.info("delete accesstoken") debug.info("delete accesstoken")
accesTokenController.deleteAccessToken(accToken) accesTokenController.deleteAccessToken(accToken)
debug.info("return ok logout user") debug.info("return ok logout user")
@ -128,6 +142,7 @@ def _logout(**kwargs):
debug.warning("exception in logout user.", exc_info=True) debug.warning("exception in logout user.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/login", methods=['POST']) @app.route("/login", methods=['POST'])
def _login(): def _login():
""" Login User """ Login User
@ -142,24 +157,25 @@ def _login():
data = request.get_json() data = request.get_json()
username = data['username'] username = data['username']
password = data['password'] password = data['password']
debug.debug("username is {{}}".format(username)) debug.debug("username is {{ {} }}".format(username))
try: try:
debug.info("search {{}} in database".format(username)) debug.info("search {{ {} }} in database".format(username))
user, ldap_conn = userController.loginUser(username, password) user, ldap_conn = userController.loginUser(username, password)
debug.debug("user is {{}}".format(user)) debug.debug("user is {{ {} }}".format(user))
user.password = password user.password = password
token = accesTokenController.createAccesToken(user, ldap_conn) token = accesTokenController.createAccesToken(user, ldap_conn)
debug.debug("accesstoken is {{}}".format(token)) debug.debug("accesstoken is {{ {} }}".format(token))
debug.info("validate accesstoken") debug.info("validate accesstoken")
dic = accesTokenController.validateAccessToken(token, [USER, EXTERN]).user.toJSON() dic = accesTokenController.validateAccessToken(
token, [USER, EXTERN]).user.toJSON()
dic["token"] = token dic["token"] = token
dic["accessToken"] = token dic["accessToken"] = token
debug.info("User {{}} success login.".format(username)) debug.info("User {{ {} }} success login.".format(username))
debug.info("return login {{}}".format(dic)) debug.info("return login {{ {} }}".format(dic))
return jsonify(dic) return jsonify(dic)
except PermissionDenied as err: except PermissionDenied as err:
debug.warning("permission denied exception in logout", exc_info=True) debug.warning("permission denied exception in logout", exc_info=True)
return jsonify({"error": str(err)}), 401 return jsonify({"error": str(err)}), 401
except Exception as err: except Exception:
debug.warning("exception in logout.", exc_info=True) debug.warning("exception in logout.", exc_info=True)
return jsonify({"error": "permission denied"}), 401 return jsonify({"error": "permission denied"}), 401

View File

@ -24,9 +24,9 @@ def _main(**kwargs):
accToken.user = userController.getUser(accToken.user.uid) accToken.user = userController.getUser(accToken.user.uid)
retVal = accToken.user.toJSON() retVal = accToken.user.toJSON()
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} 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) return jsonify(retVal)
except Exception as err: except Exception:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify("error", "something went wrong"), 500 return jsonify("error", "something went wrong"), 500
@ -44,10 +44,10 @@ def _addAmount(**kwargs):
accToken.user = userController.getUser(accToken.user.uid) accToken.user = userController.getUser(accToken.user.uid)
retVal = accToken.user.toJSON() retVal = accToken.user.toJSON()
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} 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)) creditL.info("{} {} {} fügt sich selbst {} € Schulden hinzu".format(date, accToken.user.firstname, accToken.user.lastname, amount/100))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": "something went wrong"}), 500 return jsonify({"error": "something went wrong"}), 500
@ -62,7 +62,7 @@ def _saveConfig(**kwargs):
accToken.user = userController.modifyUser(accToken.user, accToken.ldap_conn, data) accToken.user = userController.modifyUser(accToken.user, accToken.ldap_conn, data)
retVal = accToken.user.toJSON() retVal = accToken.user.toJSON()
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -101,7 +101,7 @@ def _getUser(**kwargs):
'worker': userController.getWorker(date), 'worker': userController.getWorker(date),
'day': lockedDay 'day': lockedDay
} }
debug.debug("retrun {{}}".format(retVal)) debug.debug("retrun {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -121,7 +121,7 @@ def _addUser(**kwargs):
year = data['year'] year = data['year']
date = datetime(year,month,day,12) date = datetime(year,month,day,12)
retVal = userController.addWorker(user.uid, date, userExc=True) 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())) jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(user.firstname, user.lastname, date.date()))
return jsonify(retVal) return jsonify(retVal)
except DayLocked as err: except DayLocked as err:
@ -176,7 +176,7 @@ def _transactJob(**kwargs):
retVal['from_user'] = retVal['from_user'].toJSON() retVal['from_user'] = retVal['from_user'].toJSON()
retVal['to_user'] = retVal['to_user'].toJSON() retVal['to_user'] = retVal['to_user'].toJSON()
retVal['date'] = {'year': year, 'month': month, 'day': day} 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())) 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) return jsonify(retVal)
except Exception as err: except Exception as err:
@ -205,7 +205,7 @@ def _answer(**kwargs):
retVal['from_user'] = retVal['from_user'].toJSON() retVal['from_user'] = retVal['from_user'].toJSON()
retVal['to_user'] = retVal['to_user'].toJSON() retVal['to_user'] = retVal['to_user'].toJSON()
retVal['date'] = {'year': year, 'month': month, 'day': day} 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')) 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) return jsonify(retVal)
except Exception as err: except Exception as err:
@ -231,7 +231,7 @@ def _requests(**kwargs):
data['to_user'] = data['to_user'].toJSON() data['to_user'] = data['to_user'].toJSON()
data_date = data['date'] data_date = data['date']
data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -256,7 +256,7 @@ def _getTransactJobs(**kwargs):
data['to_user'] = data['to_user'].toJSON() data['to_user'] = data['to_user'].toJSON()
data_date = data['date'] data_date = data['date']
data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
@ -310,7 +310,7 @@ def _storno(**kwargs):
accToken.user = userController.getUser(accToken.user.uid) accToken.user = userController.getUser(accToken.user.uid)
retVal = accToken.user.toJSON() retVal = accToken.user.toJSON()
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} 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)) creditL.info("{} {} {} storniert {}".format(date, user.firstname, user.lastname, amount/100))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:

View File

@ -11,7 +11,8 @@ jobL = getJobsLogger()
vorstand = Blueprint("vorstand", __name__) vorstand = Blueprint("vorstand", __name__)
userController = uc.UserController() userController = uc.UserController()
ldap= lc.LDAPController() ldap = lc.LDAPController()
@vorstand.route('/um/setStatus', methods=['POST']) @vorstand.route('/um/setStatus', methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
@ -21,12 +22,13 @@ def _setStatus(**kwargs):
data = request.get_json() data = request.get_json()
name = data['name'] name = data['name']
retVal = userController.setStatus(name) retVal = userController.setStatus(name)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route('/um/updateStatus', methods=['POST']) @vorstand.route('/um/updateStatus', methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _updateStatus(**kwargs): def _updateStatus(**kwargs):
@ -34,12 +36,13 @@ def _updateStatus(**kwargs):
try: try:
data = request.get_json() data = request.get_json()
retVal = userController.updateStatus(data) retVal = userController.updateStatus(data)
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route('/um/deleteStatus', methods=['POST']) @vorstand.route('/um/deleteStatus', methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _deleteStatus(**kwargs): def _deleteStatus(**kwargs):
@ -53,6 +56,7 @@ def _deleteStatus(**kwargs):
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 409 return jsonify({"error": str(err)}), 409
@vorstand.route('/um/updateStatusUser', methods=['POST']) @vorstand.route('/um/updateStatusUser', methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _updateStatusUser(**kwargs): def _updateStatusUser(**kwargs):
@ -62,12 +66,13 @@ def _updateStatusUser(**kwargs):
username = data['username'] username = data['username']
status = data['status'] status = data['status']
retVal = userController.updateStatusOfUser(username, status).toJSON() retVal = userController.updateStatusOfUser(username, status).toJSON()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route('/um/updateVoting', methods=['POST']) @vorstand.route('/um/updateVoting', methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _updateVoting(**kwargs): def _updateVoting(**kwargs):
@ -77,12 +82,13 @@ def _updateVoting(**kwargs):
username = data['username'] username = data['username']
voting = data['voting'] voting = data['voting']
retVal = userController.updateVotingOfUser(username, voting).toJSON() retVal = userController.updateVotingOfUser(username, voting).toJSON()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/addUser", methods=['POST', 'GET']) @vorstand.route("/sm/addUser", methods=['POST', 'GET'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _addUser(**kwargs): def _addUser(**kwargs):
@ -93,16 +99,18 @@ def _addUser(**kwargs):
day = data['day'] day = data['day']
month = data['month'] month = data['month']
year = data['year'] year = data['year']
date = datetime(year,month,day,12) date = datetime(year, month, day, 12)
retVal = userController.addWorker(user['username'], date) retVal = userController.addWorker(user['username'], date)
debug.debug("retrun {{}}".format(retVal)) debug.debug("retrun {{ {} }}".format(retVal))
userl = userController.getUser(user) 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) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/getUser", methods=['POST']) @vorstand.route("/sm/getUser", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _getUser(**kwargs): def _getUser(**kwargs):
@ -136,12 +144,13 @@ def _getUser(**kwargs):
'worker': userController.getWorker(date), 'worker': userController.getWorker(date),
'day': lockedDay 'day': lockedDay
} }
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/deleteUser", methods=['POST']) @vorstand.route("/sm/deleteUser", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _deletUser(**kwargs): def _deletUser(**kwargs):
@ -156,12 +165,14 @@ def _deletUser(**kwargs):
userController.deleteWorker(user['username'], date) userController.deleteWorker(user['username'], date)
debug.debug("return ok") debug.debug("return ok")
user = userController.getUser(user) 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"}) return jsonify({"ok": "ok"})
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/lockDay", methods=['POST']) @vorstand.route("/sm/lockDay", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND]) @login_required(groups=[MONEY, GASTRO, VORSTAND])
def _lockDay(**kwargs): def _lockDay(**kwargs):
@ -192,20 +203,21 @@ def _lockDay(**kwargs):
}, },
'locked': lockedDay['locked'] 'locked': lockedDay['locked']
} }
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({'error': err}), 409 return jsonify({'error': err}), 409
@vorstand.route("/sm/searchWithExtern", methods=['GET']) @vorstand.route("/sm/searchWithExtern", methods=['GET'])
@login_required(groups=[VORSTAND]) @login_required(groups=[VORSTAND])
def _search(**kwargs): def _search(**kwargs):
debug.info("/sm/searchWithExtern") debug.info("/sm/searchWithExtern")
try: try:
retVal = ldap.getAllUser() retVal = ldap.getAllUser()
debug.debug("return {{}}".format(retVal)) debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.debug("exception", exc_info=True) debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500