new logger implementet -- not ready
logger dont create folder to log model and controller (except userController) not ready
This commit is contained in:
parent
57f0f17a90
commit
ba5f033981
|
@ -4,12 +4,12 @@
|
||||||
Initialize also a singelton for the AccesTokenControler and start the Thread.
|
Initialize also a singelton for the AccesTokenControler and start the Thread.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from .logger import getDebugLogger, getInfoLogger
|
from .logger import getDebugLogger
|
||||||
from geruecht.controller import dbConfig, ldapConfig
|
from geruecht.controller import dbConfig, ldapConfig
|
||||||
from flask_mysqldb import MySQL
|
from flask_mysqldb import MySQL
|
||||||
from flask_ldapconn import LDAPConn
|
from flask_ldapconn import LDAPConn
|
||||||
|
|
||||||
DEBUG = getDebugLogger('INIT', True)
|
DEBUG = getDebugLogger()
|
||||||
DEBUG.info("Initialize App")
|
DEBUG.info("Initialize App")
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
|
@ -4,6 +4,10 @@ import geruecht.controller.userController as uc
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.model import BAR, MONEY, USER, VORSTAND
|
from geruecht.model import BAR, MONEY, USER, VORSTAND
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
|
from geruecht.logger import getDebugLogger, getCreditLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
creditL = getCreditLogger()
|
||||||
|
|
||||||
baruser = Blueprint("baruser", __name__)
|
baruser = Blueprint("baruser", __name__)
|
||||||
|
|
||||||
|
@ -22,28 +26,34 @@ def _bar(**kwargs):
|
||||||
JSON-File with Users, who has amounts in this month
|
JSON-File with Users, who has amounts in this month
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
dic = {}
|
debug.info("/bar")
|
||||||
users = userController.getAllUsersfromDB()
|
try:
|
||||||
for user in users:
|
dic = {}
|
||||||
geruecht = None
|
users = userController.getAllUsersfromDB()
|
||||||
geruecht = user.getGeruecht(datetime.now().year)
|
for user in users:
|
||||||
if geruecht is not None:
|
geruecht = None
|
||||||
month = geruecht.getMonth(datetime.now().month)
|
geruecht = user.getGeruecht(datetime.now().year)
|
||||||
amount = month[0] - month[1]
|
if geruecht is not None:
|
||||||
all = geruecht.getSchulden()
|
month = geruecht.getMonth(datetime.now().month)
|
||||||
if all != 0:
|
amount = month[0] - month[1]
|
||||||
if all >= 0:
|
all = geruecht.getSchulden()
|
||||||
type = 'credit'
|
if all != 0:
|
||||||
else:
|
if all >= 0:
|
||||||
type = 'amount'
|
type = 'credit'
|
||||||
dic[user.uid] = {"username": user.uid,
|
else:
|
||||||
"firstname": user.firstname,
|
type = 'amount'
|
||||||
"lastname": user.lastname,
|
dic[user.uid] = {"username": user.uid,
|
||||||
"amount": all,
|
"firstname": user.firstname,
|
||||||
"locked": user.locked,
|
"lastname": user.lastname,
|
||||||
"type": type
|
"amount": all,
|
||||||
}
|
"locked": user.locked,
|
||||||
return jsonify(dic)
|
"type": type
|
||||||
|
}
|
||||||
|
debug.debug("return {{}}".format(dic))
|
||||||
|
return jsonify(dic)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
||||||
@baruser.route("/baradd", methods=['POST'])
|
@baruser.route("/baradd", methods=['POST'])
|
||||||
|
@ -57,26 +67,32 @@ def _baradd(**kwargs):
|
||||||
JSON-File with userID and the amount
|
JSON-File with userID and the amount
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
debug.info("/baradd")
|
||||||
userID = data['userId']
|
try:
|
||||||
amount = int(data['amount'])
|
data = request.get_json()
|
||||||
|
userID = data['userId']
|
||||||
|
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)
|
||||||
amount = abs(month[0] - month[1])
|
amount = abs(month[0] - month[1])
|
||||||
all = geruecht.getSchulden()
|
all = geruecht.getSchulden()
|
||||||
if all >= 0:
|
if all >= 0:
|
||||||
type = 'credit'
|
type = 'credit'
|
||||||
else:
|
else:
|
||||||
type = 'amount'
|
type = 'amount'
|
||||||
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))
|
||||||
return jsonify(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)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
||||||
@baruser.route("/barGetUsers")
|
@baruser.route("/barGetUsers")
|
||||||
|
@ -90,9 +106,15 @@ def _getUsers(**kwargs):
|
||||||
JSON-File with Users
|
JSON-File with Users
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
retVal = {}
|
debug.info("/barGetUsers")
|
||||||
retVal = ldap.getAllUser()
|
try:
|
||||||
return jsonify(retVal)
|
retVal = {}
|
||||||
|
retVal = ldap.getAllUser()
|
||||||
|
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'])
|
@baruser.route("/bar/storno", methods=['POST'])
|
||||||
@login_required(groups=[BAR])
|
@login_required(groups=[BAR])
|
||||||
|
@ -105,50 +127,68 @@ def _storno(**kwargs):
|
||||||
JSON-File with userID and the amount
|
JSON-File with userID and the amount
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
debug.info("/bar/storno")
|
||||||
userID = data['userId']
|
try:
|
||||||
amount = int(data['amount'])
|
data = request.get_json()
|
||||||
|
userID = data['userId']
|
||||||
|
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)
|
||||||
amount = abs(month[0] - month[1])
|
amount = abs(month[0] - month[1])
|
||||||
all = geruecht.getSchulden()
|
all = geruecht.getSchulden()
|
||||||
if all >= 0:
|
if all >= 0:
|
||||||
type = 'credit'
|
type = 'credit'
|
||||||
else:
|
else:
|
||||||
type = 'amount'
|
type = 'amount'
|
||||||
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))
|
||||||
return jsonify(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'])
|
@baruser.route("/barGetUser", methods=['POST'])
|
||||||
@login_required(groups=[BAR])
|
@login_required(groups=[BAR])
|
||||||
def _getUser(**kwargs):
|
def _getUser(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/barGetUser")
|
||||||
username = data['userId']
|
try:
|
||||||
user = userController.getUser(username)
|
data = request.get_json()
|
||||||
amount = user.getGeruecht(datetime.now().year).getSchulden()
|
username = data['userId']
|
||||||
if amount >= 0:
|
user = userController.getUser(username)
|
||||||
type = 'credit'
|
amount = user.getGeruecht(datetime.now().year).getSchulden()
|
||||||
else:
|
if amount >= 0:
|
||||||
type = 'amount'
|
type = 'credit'
|
||||||
|
else:
|
||||||
|
type = 'amount'
|
||||||
|
|
||||||
retVal = user.toJSON()
|
retVal = user.toJSON()
|
||||||
retVal['amount'] = amount
|
retVal['amount'] = amount
|
||||||
retVal['type'] = type
|
retVal['type'] = type
|
||||||
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
|
||||||
|
|
||||||
@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):
|
||||||
retVal = ldap.getAllUser()
|
debug.info("/search")
|
||||||
for user in retVal:
|
try:
|
||||||
if user['username'] == 'extern':
|
retVal = ldap.getAllUser()
|
||||||
retVal.remove(user)
|
for user in retVal:
|
||||||
break
|
if user['username'] == 'extern':
|
||||||
return jsonify(retVal)
|
retVal.remove(user)
|
||||||
|
break
|
||||||
|
debug.debug("return {{}}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import yaml
|
import yaml
|
||||||
import sys
|
import sys
|
||||||
from .logger import getDebugLogger, getInfoLogger
|
from .logger import getDebugLogger
|
||||||
DEBUG = getDebugLogger("CONFIG", True)
|
DEBUG = getDebugLogger()
|
||||||
|
|
||||||
default = {
|
default = {
|
||||||
'AccessTokenLifeTime': 1800,
|
'AccessTokenLifeTime': 1800,
|
||||||
|
@ -86,7 +86,7 @@ class ConifgParser():
|
||||||
return self.mail
|
return self.mail
|
||||||
|
|
||||||
def __error__(self, msg):
|
def __error__(self, msg):
|
||||||
DEBUG.error(msg)
|
DEBUG.error(msg, exc_info=True)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from geruecht.logger import getLogger
|
from geruecht.logger import getDebugLogger
|
||||||
from geruecht.configparser import ConifgParser
|
from geruecht.configparser import ConifgParser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ print(os.getcwd())
|
||||||
|
|
||||||
config = ConifgParser('geruecht/config.yml')
|
config = ConifgParser('geruecht/config.yml')
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getDebugLogger()
|
||||||
|
|
||||||
class Singleton(type):
|
class Singleton(type):
|
||||||
_instances = {}
|
_instances = {}
|
||||||
|
|
|
@ -3,9 +3,9 @@ from datetime import datetime
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from geruecht.logger import getLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getLogger('E-MailController')
|
LOGGER = getDebugLogger()
|
||||||
|
|
||||||
class EmailController():
|
class EmailController():
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from . import LOGGER, Singleton, ldapConfig, dbConfig, mailConfig
|
from . import Singleton, mailConfig
|
||||||
import geruecht.controller.databaseController as dc
|
import geruecht.controller.databaseController as dc
|
||||||
import geruecht.controller.ldapController as lc
|
import geruecht.controller.ldapController as lc
|
||||||
import geruecht.controller.emailController as ec
|
import geruecht.controller.emailController as ec
|
||||||
|
@ -6,219 +6,359 @@ import calendar
|
||||||
from geruecht.model.user import User
|
from geruecht.model.user import User
|
||||||
from geruecht.exceptions import PermissionDenied
|
from geruecht.exceptions import PermissionDenied
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked, TansactJobIsAnswerdException
|
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion, DayLocked, TansactJobIsAnswerdException
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
db = dc.DatabaseController()
|
db = dc.DatabaseController()
|
||||||
ldap = lc.LDAPController()
|
ldap = lc.LDAPController()
|
||||||
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email'])
|
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email'])
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
class UserController(metaclass=Singleton):
|
class UserController(metaclass=Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
debug.debug("init UserController")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getAllStatus(self):
|
def getAllStatus(self):
|
||||||
return db.getAllStatus()
|
debug.info("get all status for user")
|
||||||
|
retVal = db.getAllStatus()
|
||||||
|
debug.debug("status are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getStatus(self, name):
|
def getStatus(self, name):
|
||||||
return db.getStatus(name)
|
debug.info("get status of user {{}}".format(name))
|
||||||
|
retVal = db.getStatus(name)
|
||||||
|
debug.debug("status of user {{}} is {{}}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def setStatus(self, name):
|
def setStatus(self, name):
|
||||||
return db.setStatus(name)
|
debug.info("set status of user {{}}".format(name))
|
||||||
|
retVal = db.setStatus(name)
|
||||||
|
debug.debug("settet status of user {{}} is {{}}".format(name, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def deleteStatus(self, status):
|
def deleteStatus(self, status):
|
||||||
|
debug.info("delete status {{}}".format(status))
|
||||||
db.deleteStatus(status)
|
db.deleteStatus(status)
|
||||||
|
|
||||||
def updateStatus(self, status):
|
def updateStatus(self, status):
|
||||||
return db.updateStatus(status)
|
debug.info("update status {{}}".format(status))
|
||||||
|
retVal = db.updateStatus(status)
|
||||||
|
debug.debug("updated status is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def updateStatusOfUser(self, username, status):
|
def updateStatusOfUser(self, username, status):
|
||||||
return db.updateStatusOfUser(username, status)
|
debug.info("update status {{}} of user {{}}".format(status, username))
|
||||||
|
retVal = db.updateStatusOfUser(username, status)
|
||||||
|
debug.debug("updatet status of user {{}} is {{}}".format(username, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def updateVotingOfUser(self, username, voting):
|
def updateVotingOfUser(self, username, voting):
|
||||||
return db.updateVotingOfUser(username, voting)
|
debug.info("update voting {{}} of user {{}}".format(voting, username))
|
||||||
|
retVal = db.updateVotingOfUser(username, voting)
|
||||||
|
debug.debug("updatet voting of user {{}} is {{}}".format(username, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def deleteDrinkType(self, type):
|
def deleteDrinkType(self, type):
|
||||||
|
debug.info("delete drink type {{}}".format(type))
|
||||||
db.deleteDrinkType(type)
|
db.deleteDrinkType(type)
|
||||||
|
|
||||||
def updateDrinkType(self, type):
|
def updateDrinkType(self, type):
|
||||||
return db.updateDrinkType(type)
|
debug.info("update drink type {{}}".format(type))
|
||||||
|
retVal = db.updateDrinkType(type)
|
||||||
|
debug.debug("updated drink type is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def setDrinkType(self, type):
|
def setDrinkType(self, type):
|
||||||
return db.setDrinkType(type)
|
debug.info("set drink type {{}}".format(type))
|
||||||
|
retVal = db.setDrinkType(type)
|
||||||
|
debug.debug("seted drink type is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def deletDrinkPrice(self, drink):
|
def deletDrinkPrice(self, drink):
|
||||||
|
debug.info("delete drink {{}}".format(drink))
|
||||||
db.deleteDrink(drink)
|
db.deleteDrink(drink)
|
||||||
|
|
||||||
def setDrinkPrice(self, drink):
|
def setDrinkPrice(self, drink):
|
||||||
|
debug.info("set drink {{}}".format(drink))
|
||||||
retVal = db.setDrinkPrice(drink)
|
retVal = db.setDrinkPrice(drink)
|
||||||
|
debug.debug("seted drink is {{}}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def updateDrinkPrice(self, drink):
|
def updateDrinkPrice(self, drink):
|
||||||
|
debug.info("update drink {{}}".format(drink))
|
||||||
retVal = db.updateDrinkPrice(drink)
|
retVal = db.updateDrinkPrice(drink)
|
||||||
|
debug.debug("updated drink is {{}}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getAllDrinkTypes(self):
|
def getAllDrinkTypes(self):
|
||||||
return db.getAllDrinkTypes()
|
debug.info("get all drink types")
|
||||||
|
retVal = db.getAllDrinkTypes()
|
||||||
|
debug.debug("all drink types are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getPricelist(self):
|
def getPricelist(self):
|
||||||
|
debug.info("get all drinks")
|
||||||
list = db.getPriceList()
|
list = db.getPriceList()
|
||||||
|
debug.debug("all drinks are {{}}".format(list))
|
||||||
return list
|
return list
|
||||||
|
|
||||||
def setTransactJob(self, from_user, to_user, date):
|
def setTransactJob(self, from_user, to_user, date):
|
||||||
|
debug.info("set transact job from {{}} to {{}} on {{}}".format(from_user, to_user, date))
|
||||||
jobtransact = db.setTransactJob(from_user, to_user, date.date())
|
jobtransact = db.setTransactJob(from_user, to_user, date.date())
|
||||||
|
debug.debug("transact job is {{}}".format(jobtransact))
|
||||||
|
debug.info("send mail with transact job to user")
|
||||||
emailController.sendMail(jobtransact['to_user'], 'jobtransact', jobtransact)
|
emailController.sendMail(jobtransact['to_user'], 'jobtransact', jobtransact)
|
||||||
return jobtransact
|
return jobtransact
|
||||||
|
|
||||||
def getTransactJobFromUser(self, user, date):
|
def getTransactJobFromUser(self, user, date):
|
||||||
return db.getTransactJobFromUser(user, date.date())
|
debug.info("get transact job from user {{}} on {{}}".format(user, date))
|
||||||
|
retVal = db.getTransactJobFromUser(user, date.date())
|
||||||
|
debug.debug("transact job from user {{}} is {{}}".format(user, retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getAllTransactJobFromUser(self, user, date):
|
def getAllTransactJobFromUser(self, user, date):
|
||||||
return db.getAllTransactJobFromUser(user, date.date())
|
debug.info("get all transact job from user {{}} start on {{}}".format(user, date))
|
||||||
|
retVal = db.getAllTransactJobFromUser(user, date,date())
|
||||||
|
debug.debug("all transact job are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getAllTransactJobToUser(self, user, date):
|
def getAllTransactJobToUser(self, user, date):
|
||||||
return db.getAllTransactJobToUser(user, date.date())
|
debug.info("get all transact job from to_user {{}} start on {{}}".format(user, date))
|
||||||
|
retVal = db.getAllTransactJobToUser(user, date.date())
|
||||||
|
debug.debug("all transact job are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getTransactJob(self, from_user, to_user, date):
|
def getTransactJob(self, from_user, to_user, date):
|
||||||
return db.getTransactJob(from_user, to_user, date.date())
|
debug.info("get transact job from user {{}} to user {{}} on {{}}".format(from_user, to_user, date))
|
||||||
|
retVal = db.getTransactJob(from_user, to_user, date.date())
|
||||||
|
debug.debug("transact job is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def deleteTransactJob(self, from_user, to_user, date):
|
def deleteTransactJob(self, from_user, to_user, date):
|
||||||
|
debug.info("delete transact job from user {{}} to user {{}} on {{}}".format(from_user, to_user, date))
|
||||||
transactJob = self.getTransactJob(from_user, to_user, date)
|
transactJob = self.getTransactJob(from_user, to_user, date)
|
||||||
|
debug.debug("transact job is {{}}".format(transactJob))
|
||||||
if transactJob['answerd']:
|
if transactJob['answerd']:
|
||||||
|
debug.warning("transactjob {{}} can not delete because is answerd")
|
||||||
raise TansactJobIsAnswerdException("TransactJob is already answerd")
|
raise TansactJobIsAnswerdException("TransactJob is already answerd")
|
||||||
db.deleteTransactJob(from_user, to_user, date.date())
|
db.deleteTransactJob(from_user, to_user, date.date())
|
||||||
|
|
||||||
def answerdTransactJob(self, from_user, to_user, date, answer):
|
def answerdTransactJob(self, from_user, to_user, date, answer):
|
||||||
|
debug.info("answer transact job from user {{}} to user {{}} on {{}} with answer {{}}".format(from_user, to_user, date, answer))
|
||||||
transactJob = db.updateTransactJob(from_user, to_user, date.date(), answer)
|
transactJob = db.updateTransactJob(from_user, to_user, date.date(), answer)
|
||||||
|
debug.debug("transactjob is {{}}".format(transactJob))
|
||||||
if answer:
|
if answer:
|
||||||
|
debug.info("add worker on date {{}}".format(date))
|
||||||
self.addWorker(to_user.uid, date)
|
self.addWorker(to_user.uid, date)
|
||||||
return transactJob
|
return transactJob
|
||||||
|
|
||||||
def setLockedDay(self, date, locked, hard=False):
|
def setLockedDay(self, date, locked, hard=False):
|
||||||
return db.setLockedDay(date.date(), locked, hard)
|
debug.info("set day locked on {{}} with state {{}}".format(date, locked))
|
||||||
|
retVal = db.setLockedDay(date.date(), locked, hard)
|
||||||
|
debug.debug("seted day locked is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getLockedDay(self, date):
|
def getLockedDay(self, date):
|
||||||
|
debug.info("get locked day on {{}}".format(date))
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
debug.debug("now is {{}}".format(now))
|
||||||
oldMonth = False
|
oldMonth = False
|
||||||
|
debug.debug("check if date old month or current month")
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
if datetime(now.year, now.month, i).weekday() == 2:
|
if datetime(now.year, now.month, i).weekday() == 2:
|
||||||
if now.day < i:
|
if now.day < i:
|
||||||
oldMonth = True
|
oldMonth = True
|
||||||
break
|
break
|
||||||
|
debug.debug("oldMonth is {{}}".format(oldMonth))
|
||||||
lockedYear = date.year
|
lockedYear = date.year
|
||||||
lockedMonth = date.month if date.month < now.month else now.month - 1 if oldMonth else now.month
|
lockedMonth = date.month if date.month < now.month else now.month - 1 if oldMonth else now.month
|
||||||
daysInMonth = calendar.monthrange(lockedYear, lockedMonth)[1]
|
daysInMonth = calendar.monthrange(lockedYear, lockedMonth)[1]
|
||||||
startDay = 1
|
startDay = 1
|
||||||
|
debug.debug("calculate start day of month")
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
if datetime(lockedYear, lockedMonth, i).weekday() == 2:
|
if datetime(lockedYear, lockedMonth, i).weekday() == 2:
|
||||||
startDay = i
|
startDay = i
|
||||||
break
|
break
|
||||||
|
debug.debug("start day of month is {{}}".format(startDay))
|
||||||
|
debug.debug("check if date should be locked")
|
||||||
if lockedYear <= now.year and lockedMonth <= now.month:
|
if lockedYear <= now.year and lockedMonth <= now.month:
|
||||||
for i in range(startDay, daysInMonth + 1):
|
for i in range(startDay, daysInMonth + 1):
|
||||||
|
debug.debug("lock day {{}}".format(datetime(lockedYear, lockedMonth, i)))
|
||||||
self.setLockedDay(datetime(lockedYear, lockedMonth, i), True)
|
self.setLockedDay(datetime(lockedYear, lockedMonth, i), True)
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
nextMonth = datetime(lockedYear, lockedMonth + 1, i)
|
nextMonth = datetime(lockedYear, lockedMonth + 1, i)
|
||||||
if nextMonth.weekday() == 2:
|
if nextMonth.weekday() == 2:
|
||||||
break
|
break
|
||||||
|
debug.debug("lock day {{}}".format(datetime(lockedYear, lockedMonth, i)))
|
||||||
self.setLockedDay(nextMonth, True)
|
self.setLockedDay(nextMonth, True)
|
||||||
return db.getLockedDay(date.date())
|
retVal = db.getLockedDay(date.date())
|
||||||
|
debug.debug("locked day is {{}}".format(retVal))
|
||||||
|
return
|
||||||
|
|
||||||
def getWorker(self, date, username=None):
|
def getWorker(self, date, username=None):
|
||||||
|
debug.info("get worker on {{}}".format(username, date))
|
||||||
if (username):
|
if (username):
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
return [db.getWorker(user, date)]
|
debug.debug("user is {{}}".format(user))
|
||||||
return db.getWorkers(date)
|
retVal = [db.getWorker(user, date)]
|
||||||
|
debug.debug("worker is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
retVal = db.getWorkers(date)
|
||||||
|
debug.debug("workers are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def addWorker(self, username, date, userExc=False):
|
def addWorker(self, username, date, userExc=False):
|
||||||
|
debug.info("add job user {{}} on {{}}".format(username, date))
|
||||||
if (userExc):
|
if (userExc):
|
||||||
|
debug.debug("this is a user execution, check if day is locked")
|
||||||
lockedDay = self.getLockedDay(date)
|
lockedDay = self.getLockedDay(date)
|
||||||
if lockedDay:
|
if lockedDay:
|
||||||
if lockedDay['locked']:
|
if lockedDay['locked']:
|
||||||
|
debug.debug("day is lockey. user cant get job")
|
||||||
raise DayLocked("Day is locked. You can't get the Job")
|
raise DayLocked("Day is locked. You can't get the Job")
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
|
debug.debug("check if user has job on date")
|
||||||
if (not db.getWorker(user, date)):
|
if (not db.getWorker(user, date)):
|
||||||
|
debug.debug("set job to user")
|
||||||
db.setWorker(user, date)
|
db.setWorker(user, date)
|
||||||
return self.getWorker(date, username=username)
|
retVal = self.getWorker(date, username=username)
|
||||||
|
debug.debug("worker on date is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def deleteWorker(self, username, date, userExc=False):
|
def deleteWorker(self, username, date, userExc=False):
|
||||||
|
debug.info("delete worker {{}} on date {{}}".format(username, date))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
if userExc:
|
if userExc:
|
||||||
|
debug.debug("is user execution, check if day locked")
|
||||||
lockedDay = self.getLockedDay(date)
|
lockedDay = self.getLockedDay(date)
|
||||||
if lockedDay:
|
if lockedDay:
|
||||||
if lockedDay['locked']:
|
if lockedDay['locked']:
|
||||||
|
debug.debug("day is locked, check if accepted transact job exists")
|
||||||
transactJobs = self.getTransactJobFromUser(user, date)
|
transactJobs = self.getTransactJobFromUser(user, date)
|
||||||
|
debug.debug("transact job is {{}}".format(transactJobs))
|
||||||
found = False
|
found = False
|
||||||
for job in transactJobs:
|
for job in transactJobs:
|
||||||
if job['accepted'] and job['answerd']:
|
if job['accepted'] and job['answerd']:
|
||||||
|
debug.debug("accepted transact job exists")
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
|
debug.debug("no accepted transact job found")
|
||||||
raise DayLocked("Day is locked. You can't delete the Job")
|
raise DayLocked("Day is locked. You can't delete the Job")
|
||||||
db.deleteWorker(user, date)
|
db.deleteWorker(user, date)
|
||||||
|
|
||||||
def lockUser(self, username, locked):
|
def lockUser(self, username, locked):
|
||||||
|
debug.info("lock user {{}} for credit with status {{}}".format(username, locked))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
user.updateData({'locked': locked})
|
user.updateData({'locked': locked})
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
return self.getUser(username)
|
retVal = self.getUser(username)
|
||||||
|
debug.debug("locked user is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def updateConfig(self, username, data):
|
def updateConfig(self, username, data):
|
||||||
|
debug.info("update config of user {{}} with config {{}}".format(username, data))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
user.updateData(data)
|
user.updateData(data)
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
return self.getUser(username)
|
retVal = self.getUser(username)
|
||||||
|
debug.debug("updated config of user is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def __updateDataFromLDAP(self, user):
|
def __updateDataFromLDAP(self, user):
|
||||||
|
debug.info("update data from ldap for user {{}}".format(user))
|
||||||
groups = ldap.getGroup(user.uid)
|
groups = ldap.getGroup(user.uid)
|
||||||
|
debug.debug("ldap gorups are {{}}".format(groups))
|
||||||
user_data = ldap.getUserData(user.uid)
|
user_data = ldap.getUserData(user.uid)
|
||||||
|
debug.debug("ldap data is {{}}".format(user_data))
|
||||||
user_data['gruppe'] = groups
|
user_data['gruppe'] = groups
|
||||||
user_data['group'] = groups
|
user_data['group'] = groups
|
||||||
user.updateData(user_data)
|
user.updateData(user_data)
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
|
|
||||||
def autoLock(self, user):
|
def autoLock(self, user):
|
||||||
|
debug.info("start autolock of user {{}}".format(user))
|
||||||
if user.autoLock:
|
if user.autoLock:
|
||||||
if user.getGeruecht(year=datetime.now().year).getSchulden() <= (-1*user.limit):
|
debug.debug("autolock is active")
|
||||||
|
credit = user.getGeruecht(year=datetime.now().year).getSchulden()
|
||||||
|
limit = -1*user.limit
|
||||||
|
if credit <= limit:
|
||||||
|
debug.debug("credit {{}} is more than user limit {{}}".format(credit, limit))
|
||||||
|
debug.debug("lock user")
|
||||||
user.updateData({'locked': True})
|
user.updateData({'locked': True})
|
||||||
|
debug.debug("send mail to user")
|
||||||
emailController.sendMail(user)
|
emailController.sendMail(user)
|
||||||
else:
|
else:
|
||||||
|
debug.debug("cretid {{}} is less than user limit {{}}".format(credit, limit))
|
||||||
|
debug.debug("unlock user")
|
||||||
user.updateData({'locked': False})
|
user.updateData({'locked': False})
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
|
|
||||||
def addAmount(self, username, amount, year, month, finanzer=False):
|
def addAmount(self, username, amount, year, month, finanzer=False):
|
||||||
|
debug.info("add amount {{}} to user {{}} no month {{}}, year {{}}".format(amount, username, month, year))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
if user.uid == 'extern':
|
if user.uid == 'extern':
|
||||||
|
debug.debug("user is extern user, so exit add amount")
|
||||||
return
|
return
|
||||||
if not user.locked or finanzer:
|
if not user.locked or finanzer:
|
||||||
|
debug.debug("user is not locked {{}} or is finanzer execution {{}}".format(user.locked, finanzer))
|
||||||
user.addAmount(amount, year=year, month=month)
|
user.addAmount(amount, year=year, month=month)
|
||||||
creditLists = user.updateGeruecht()
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditList is {{}}".format(creditLists))
|
||||||
for creditList in creditLists:
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{}}".format(creditList))
|
||||||
db.updateCreditList(creditList)
|
db.updateCreditList(creditList)
|
||||||
|
debug.debug("do autolock")
|
||||||
self.autoLock(user)
|
self.autoLock(user)
|
||||||
return user.getGeruecht(year)
|
retVal = user.getGeruecht(year)
|
||||||
|
debug.debug("updated creditlists is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def addCredit(self, username, credit, year, month):
|
def addCredit(self, username, credit, year, month):
|
||||||
|
debug.info("add credit {{}} to user {{}} on month {{}}, year {{}}".format(credit, username, month, year))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
if user.uid == 'extern':
|
if user.uid == 'extern':
|
||||||
|
debug.debug("user is extern user, so exit add credit")
|
||||||
return
|
return
|
||||||
user.addCredit(credit, year=year, month=month)
|
user.addCredit(credit, year=year, month=month)
|
||||||
creditLists = user.updateGeruecht()
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditlists are {{}}".format(creditLists))
|
||||||
for creditList in creditLists:
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{}}".format(creditList))
|
||||||
db.updateCreditList(creditList)
|
db.updateCreditList(creditList)
|
||||||
|
debug.debug("do autolock")
|
||||||
self.autoLock(user)
|
self.autoLock(user)
|
||||||
return user.getGeruecht(year)
|
retVal = user.getGeruecht(year)
|
||||||
|
debug.debug("updated creditlists are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def getAllUsersfromDB(self):
|
def getAllUsersfromDB(self):
|
||||||
|
debug.info("get all users from database")
|
||||||
users = db.getAllUser()
|
users = db.getAllUser()
|
||||||
|
debug.debug("users are {{}}".format(users))
|
||||||
for user in users:
|
for user in users:
|
||||||
try:
|
try:
|
||||||
|
debug.debug("update data from ldap")
|
||||||
self.__updateDataFromLDAP(user)
|
self.__updateDataFromLDAP(user)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
debug.debug("update creditlists")
|
||||||
self.__updateGeruechte(user)
|
self.__updateGeruechte(user)
|
||||||
return db.getAllUser(extern=True)
|
retVal = db.getAllUser(extern=True)
|
||||||
|
debug.debug("all users are {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def checkBarUser(self, user):
|
def checkBarUser(self, user):
|
||||||
|
debug.info("check if user {{}} is baruser")
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
zero = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
zero = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
end = zero + timedelta(hours=12)
|
end = zero + timedelta(hours=12)
|
||||||
|
@ -226,59 +366,84 @@ class UserController(metaclass=Singleton):
|
||||||
if date > zero and end > date:
|
if date > zero and end > date:
|
||||||
startdatetime = startdatetime - timedelta(days=1)
|
startdatetime = startdatetime - timedelta(days=1)
|
||||||
enddatetime = startdatetime + timedelta(days=1)
|
enddatetime = startdatetime + timedelta(days=1)
|
||||||
|
debug.debug("startdatetime is {{}} and enddatetime is {{}}".format(startdatetime, end))
|
||||||
result = False
|
result = False
|
||||||
if date >= startdatetime and date < enddatetime:
|
if date >= startdatetime and date < enddatetime:
|
||||||
result = db.getWorker(user, startdatetime)
|
result = db.getWorker(user, startdatetime)
|
||||||
|
debug.debug("worker is {{}}".format(result))
|
||||||
return True if result else False
|
return True if result else False
|
||||||
|
|
||||||
|
|
||||||
def getUser(self, username):
|
def getUser(self, username):
|
||||||
|
debug.info("get user {{}}".format(username))
|
||||||
user = db.getUser(username)
|
user = db.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
groups = ldap.getGroup(username)
|
groups = ldap.getGroup(username)
|
||||||
|
debug.debug("groups are {{}}".format(groups))
|
||||||
user_data = ldap.getUserData(username)
|
user_data = ldap.getUserData(username)
|
||||||
|
debug.debug("user data from ldap is {{}}".format(user_data))
|
||||||
user_data['gruppe'] = groups
|
user_data['gruppe'] = groups
|
||||||
user_data['group'] = groups
|
user_data['group'] = groups
|
||||||
if user is None:
|
if user is None:
|
||||||
|
debug.debug("user not exists in database -> insert into database")
|
||||||
user = User(user_data)
|
user = User(user_data)
|
||||||
db.insertUser(user)
|
db.insertUser(user)
|
||||||
else:
|
else:
|
||||||
|
debug.debug("update database with user")
|
||||||
user.updateData(user_data)
|
user.updateData(user_data)
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
user = db.getUser(username)
|
user = db.getUser(username)
|
||||||
self.__updateGeruechte(user)
|
self.__updateGeruechte(user)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def __updateGeruechte(self, user):
|
def __updateGeruechte(self, user):
|
||||||
|
debug.debug("update creditlists")
|
||||||
user.getGeruecht(datetime.now().year)
|
user.getGeruecht(datetime.now().year)
|
||||||
creditLists = user.updateGeruecht()
|
creditLists = user.updateGeruecht()
|
||||||
|
debug.debug("creditlists are {{}}".format(creditLists))
|
||||||
if user.getGeruecht(datetime.now().year).getSchulden() != 0:
|
if user.getGeruecht(datetime.now().year).getSchulden() != 0:
|
||||||
for creditList in creditLists:
|
for creditList in creditLists:
|
||||||
|
debug.debug("update creditlist {{}}".format(creditList))
|
||||||
db.updateCreditList(creditList)
|
db.updateCreditList(creditList)
|
||||||
|
|
||||||
def sendMail(self, username):
|
def sendMail(self, username):
|
||||||
|
debug.info("send mail to user {{}}".format(username))
|
||||||
if type(username) == User:
|
if type(username) == User:
|
||||||
user = username
|
user = username
|
||||||
if type(username) == str:
|
if type(username) == str:
|
||||||
user = db.getUser(username)
|
user = db.getUser(username)
|
||||||
return emailController.sendMail(user)
|
retVal = emailController.sendMail(user)
|
||||||
|
debug.debug("send mail is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
def sendAllMail(self):
|
def sendAllMail(self):
|
||||||
|
debug.info("send mail to all user")
|
||||||
retVal = []
|
retVal = []
|
||||||
users = db.getAllUser()
|
users = db.getAllUser()
|
||||||
|
debug.debug("users are {{}}".format(users))
|
||||||
for user in users:
|
for user in users:
|
||||||
retVal.append(self.sendMail(user))
|
retVal.append(self.sendMail(user))
|
||||||
|
debug.debug("send mails are {{}}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def modifyUser(self, user, ldap_conn, attributes):
|
def modifyUser(self, user, ldap_conn, attributes):
|
||||||
|
debug.info("modify user {{}} with attributes {{}} with ldap_conn {{}}".format(user, attributes, ldap_conn))
|
||||||
try:
|
try:
|
||||||
if 'username' in attributes:
|
if 'username' in attributes:
|
||||||
|
debug.debug("change username, so change first in database")
|
||||||
db.changeUsername(user, attributes['username'])
|
db.changeUsername(user, attributes['username'])
|
||||||
ldap.modifyUser(user, ldap_conn, attributes)
|
ldap.modifyUser(user, ldap_conn, attributes)
|
||||||
if 'username' in attributes:
|
if 'username' in attributes:
|
||||||
return self.getUser(attributes['username'])
|
retVal = self.getUser(attributes['username'])
|
||||||
|
debug.debug("user is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
else:
|
else:
|
||||||
return self.getUser(user.uid)
|
retVal = self.getUser(user.uid)
|
||||||
|
debug.debug("user is {{}}".format(retVal))
|
||||||
|
return retVal
|
||||||
except UsernameExistLDAP as err:
|
except UsernameExistLDAP as err:
|
||||||
|
debug.debug("username exists on ldap, rechange username on database", exc_info=True)
|
||||||
db.changeUsername(user, user.uid)
|
db.changeUsername(user, user.uid)
|
||||||
raise Exception(err)
|
raise Exception(err)
|
||||||
except LDAPExcetpion as err:
|
except LDAPExcetpion as err:
|
||||||
|
@ -289,11 +454,14 @@ class UserController(metaclass=Singleton):
|
||||||
raise Exception(err)
|
raise Exception(err)
|
||||||
|
|
||||||
def loginUser(self, username, password):
|
def loginUser(self, username, password):
|
||||||
|
debug.info("login user {{}}".format(username))
|
||||||
try:
|
try:
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
|
debug.debug("user is {{}}".format(user))
|
||||||
user.password = password
|
user.password = password
|
||||||
ldap.login(username, password)
|
ldap.login(username, password)
|
||||||
ldap_conn = ldap.bind(user, password)
|
ldap_conn = ldap.bind(user, password)
|
||||||
return user, ldap_conn
|
return user, ldap_conn
|
||||||
except PermissionDenied as err:
|
except PermissionDenied as err:
|
||||||
|
debug.debug("permission is denied", exc_info=True)
|
||||||
raise err
|
raise err
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from .logger import getInfoLogger, getDebugLogger
|
from .logger import getDebugLogger
|
||||||
DEBUG = getDebugLogger("login-decorator", True)
|
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,15 +9,17 @@ 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))
|
||||||
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.info("get token {{}}".format(token))
|
DEBUG.debug("token is {{}}".format(token))
|
||||||
accToken = accessController.validateAccessToken(token, groups)
|
accToken = accessController.validateAccessToken(token, groups)
|
||||||
|
DEBUG.debug("accToken is {{}}".format(accToken))
|
||||||
kwargs['accToken'] = accToken
|
kwargs['accToken'] = accToken
|
||||||
if accToken:
|
if accToken:
|
||||||
DEBUG.info("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))
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
from geruecht.logger import getLogger
|
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
from geruecht.finanzer import LOGGER
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.userController as uc
|
||||||
from geruecht.model import MONEY
|
from geruecht.model import MONEY
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
import time
|
from geruecht.logger import getDebugLogger, getCreditLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
creditL = getCreditLogger()
|
||||||
|
|
||||||
finanzer = Blueprint("finanzer", __name__)
|
finanzer = Blueprint("finanzer", __name__)
|
||||||
|
|
||||||
|
@ -22,16 +24,18 @@ def _getFinanzer(**kwargs):
|
||||||
A JSON-File with Users
|
A JSON-File with Users
|
||||||
or ERROR 401 Permission Denied.
|
or ERROR 401 Permission Denied.
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Get all Useres")
|
debug.info("/getFinanzerMain")
|
||||||
users = userController.getAllUsersfromDB()
|
try:
|
||||||
dic = {}
|
users = userController.getAllUsersfromDB()
|
||||||
for user in users:
|
dic = {}
|
||||||
LOGGER.debug("Add User {} to ReturnValue".format(user))
|
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'] = {credit.year: credit.toJSON() for credit in user.geruechte}
|
||||||
LOGGER.debug("ReturnValue is {}".format(dic))
|
debug.debug("return {{}}".format(dic))
|
||||||
LOGGER.info("Send main for Finanzer")
|
return jsonify(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'])
|
@finanzer.route("/finanzerAddAmount", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
|
@ -46,28 +50,29 @@ def _addAmount(**kwargs):
|
||||||
JSON-File with geruecht of year
|
JSON-File with geruecht of year
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
debug.info("/finanzerAddAmount")
|
||||||
LOGGER.debug("Get data {}".format(data))
|
|
||||||
userID = data['userId']
|
|
||||||
amount = int(data['amount'])
|
|
||||||
LOGGER.debug("UserID is {} and amount is {}".format(userID, amount))
|
|
||||||
try:
|
try:
|
||||||
year = int(data['year'])
|
data = request.get_json()
|
||||||
except KeyError as er:
|
userID = data['userId']
|
||||||
LOGGER.error("KeyError in year. Year is set to default.")
|
amount = int(data['amount'])
|
||||||
year = datetime.now().year
|
try:
|
||||||
try:
|
year = int(data['year'])
|
||||||
month = int(data['month'])
|
except KeyError as er:
|
||||||
except KeyError as er:
|
year = datetime.now().year
|
||||||
LOGGER.error("KeyError in month. Month is set to default.")
|
try:
|
||||||
month = datetime.now().month
|
month = int(data['month'])
|
||||||
LOGGER.debug("Year is {} and Month is {}".format(year, month))
|
except KeyError as er:
|
||||||
userController.addAmount(userID, amount, year=year, month=month, finanzer=True)
|
month = datetime.now().month
|
||||||
user = userController.getUser(userID)
|
userController.addAmount(userID, amount, year=year, month=month, finanzer=True)
|
||||||
retVal = {str(geruecht.year): geruecht.toJSON() for geruecht in user.geruechte}
|
user = userController.getUser(userID)
|
||||||
retVal['locked'] = user.locked
|
retVal = {str(geruecht.year): geruecht.toJSON() for geruecht in user.geruechte}
|
||||||
LOGGER.info("Send updated Geruecht")
|
retVal['locked'] = user.locked
|
||||||
return jsonify(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))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
@finanzer.route("/finanzerAddCredit", methods=['POST'])
|
@finanzer.route("/finanzerAddCredit", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
|
@ -82,79 +87,109 @@ def _addCredit(**kwargs):
|
||||||
JSON-File with geruecht of year
|
JSON-File with geruecht of year
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
data = request.get_json()
|
debug.info("/finanzerAddCredit")
|
||||||
print(data)
|
|
||||||
LOGGER.debug("Get data {}".format(data))
|
|
||||||
userID = data['userId']
|
|
||||||
credit = int(data['credit'])
|
|
||||||
LOGGER.debug("UserID is {} and credit is {}".format(userID, credit))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
year = int(data['year'])
|
data = request.get_json()
|
||||||
except KeyError as er:
|
userID = data['userId']
|
||||||
LOGGER.error("KeyError in year. Year is set to default.")
|
credit = int(data['credit'])
|
||||||
year = datetime.now().year
|
|
||||||
try:
|
|
||||||
month = int(data['month'])
|
|
||||||
except KeyError as er:
|
|
||||||
LOGGER.error("KeyError in month. Month is set to default.")
|
|
||||||
month = datetime.now().month
|
|
||||||
|
|
||||||
LOGGER.debug("Year is {} and Month is {}".format(year, month))
|
try:
|
||||||
userController.addCredit(userID, credit, year=year, month=month).toJSON()
|
year = int(data['year'])
|
||||||
user = userController.getUser(userID)
|
except KeyError as er:
|
||||||
retVal = {str(geruecht.year): geruecht.toJSON() for geruecht in user.geruechte}
|
year = datetime.now().year
|
||||||
retVal['locked'] = user.locked
|
try:
|
||||||
LOGGER.info("Send updated Geruecht")
|
month = int(data['month'])
|
||||||
return jsonify(retVal)
|
except KeyError as er:
|
||||||
|
month = datetime.now().month
|
||||||
|
|
||||||
|
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['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))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
||||||
@finanzer.route("/finanzerLock", methods=['POST'])
|
@finanzer.route("/finanzerLock", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
def _finanzerLock(**kwargs):
|
def _finanzerLock(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/finanzerLock")
|
||||||
username = data['userId']
|
try:
|
||||||
locked = bool(data['locked'])
|
data = request.get_json()
|
||||||
retVal = userController.lockUser(username, locked).toJSON()
|
username = data['userId']
|
||||||
return jsonify(retVal)
|
locked = bool(data['locked'])
|
||||||
|
retVal = userController.lockUser(username, locked).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("/finanzerSetConfig", methods=['POST'])
|
@finanzer.route("/finanzerSetConfig", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
def _finanzerSetConfig(**kwargs):
|
def _finanzerSetConfig(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/finanzerSetConfig")
|
||||||
username = data['userId']
|
try:
|
||||||
autoLock = bool(data['autoLock'])
|
data = request.get_json()
|
||||||
limit = int(data['limit'])
|
username = data['userId']
|
||||||
retVal = userController.updateConfig(username, {'lockLimit': limit, 'autoLock': autoLock}).toJSON()
|
autoLock = bool(data['autoLock'])
|
||||||
return jsonify(retVal)
|
limit = int(data['limit'])
|
||||||
|
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'])
|
@finanzer.route("/finanzerAddUser", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
def _finanzerAddUser(**kwargs):
|
def _finanzerAddUser(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/finanzerAddUser")
|
||||||
username = data['userId']
|
try:
|
||||||
userController.getUser(username)
|
data = request.get_json()
|
||||||
LOGGER.debug("Get all Useres")
|
username = data['userId']
|
||||||
users = userController.getAllUsersfromDB()
|
userController.getUser(username)
|
||||||
dic = {}
|
users = userController.getAllUsersfromDB()
|
||||||
for user in users:
|
dic = {}
|
||||||
LOGGER.debug("Add User {} to ReturnValue".format(user))
|
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'] = {credit.year: credit.toJSON() for credit in user.geruechte}
|
||||||
LOGGER.debug("ReturnValue is {}".format(dic))
|
debug.debug("return {{}}".format(dic))
|
||||||
return jsonify(dic), 200
|
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'])
|
@finanzer.route("/finanzerSendOneMail", methods=['POST'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
def _finanzerSendOneMail(**kwargs):
|
def _finanzerSendOneMail(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/finanzerSendOneMail")
|
||||||
username = data['userId']
|
try:
|
||||||
retVal = userController.sendMail(username)
|
data = request.get_json()
|
||||||
return jsonify(retVal)
|
username = data['userId']
|
||||||
|
retVal = userController.sendMail(username)
|
||||||
|
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'])
|
@finanzer.route("/finanzerSendAllMail", methods=['GET'])
|
||||||
@login_required(groups=[MONEY])
|
@login_required(groups=[MONEY])
|
||||||
def _finanzerSendAllMail(**kwargs):
|
def _finanzerSendAllMail(**kwargs):
|
||||||
retVal = userController.sendAllMail()
|
debug.info("/finanzerSendAllMail")
|
||||||
return jsonify(retVal)
|
try:
|
||||||
|
retVal = userController.sendAllMail()
|
||||||
|
debug.debug("return {{}}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
|
@ -2,6 +2,9 @@ from flask import request, jsonify, Blueprint
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.userController as uc
|
||||||
from geruecht.model import GASTRO
|
from geruecht.model import GASTRO
|
||||||
|
from geruecht.logger import getCreditLogger, getDebugLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
gastrouser = Blueprint('gastrouser', __name__)
|
gastrouser = Blueprint('gastrouser', __name__)
|
||||||
|
|
||||||
|
@ -10,62 +13,80 @@ 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):
|
||||||
|
debug.info("/gastro/setDrink")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.setDrinkPrice(data)
|
retVal = userController.setDrinkPrice(data)
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/gastro/updateDrink")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateDrinkPrice(data)
|
retVal = userController.updateDrinkPrice(data)
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/gastro/dleteDrink")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
id = data['id']
|
id = data['id']
|
||||||
retVal = userController.deletDrinkPrice({"id": id})
|
retVal = userController.deletDrinkPrice({"id": id})
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/gastro/setDrinkType")
|
||||||
try:
|
try:
|
||||||
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))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
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):
|
||||||
|
debug.info("/gastro/updateDrinkType")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateDrinkType(data)
|
retVal = userController.updateDrinkType(data)
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/gastro/deleteDrinkType")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userController.deleteDrinkType(data)
|
userController.deleteDrinkType(data)
|
||||||
|
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)
|
||||||
return jsonify({"error": str(err)}), 500
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,24 @@
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import WatchedFileHandler
|
import logging.config
|
||||||
import sys
|
import yaml
|
||||||
|
from os import path
|
||||||
|
|
||||||
FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(levelname)s — %(message)s")
|
if not path.exists("geruecht/log/debug"):
|
||||||
|
a = path.join(path.curdir ,"geruecht", "log", "debug")
|
||||||
|
|
||||||
logFileHandler = WatchedFileHandler("geruecht/log/debug.log")
|
if not path.exists("geruecht/log/info"):
|
||||||
logFileHandler.setFormatter(FORMATTER)
|
b = path.join(path.curdir, "geruecht", "log", "info")
|
||||||
|
|
||||||
logStreamHandler = logging.StreamHandler(stream=sys.stdout)
|
|
||||||
logStreamHandler.setFormatter(FORMATTER)
|
|
||||||
|
|
||||||
def getLogger(logger_name):
|
with open("geruecht/logging.yml", 'rt') as file:
|
||||||
return getDebugLogger(logger_name)
|
config = yaml.safe_load(file.read())
|
||||||
|
logging.config.dictConfig(config)
|
||||||
|
|
||||||
def getInfoLogger(logger_name):
|
def getDebugLogger():
|
||||||
logger = logging.getLogger(logger_name)
|
return logging.getLogger("debug_logger")
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
logger.addHandler(logStreamHandler)
|
|
||||||
logFileHandler = WatchedFileHandler("geruecht/log/info/{}.log".format(logger_name))
|
|
||||||
logFileHandler.setFormatter(FORMATTER)
|
|
||||||
logger.addHandler(logFileHandler)
|
|
||||||
return logger
|
|
||||||
|
|
||||||
def getDebugLogger(logger_name, path=False):
|
def getCreditLogger():
|
||||||
|
return logging.getLogger("credit_logger")
|
||||||
|
|
||||||
logger = logging.getLogger(logger_name)
|
def getJobsLogger():
|
||||||
if path:
|
return logging.getLogger("jobs_logger")
|
||||||
logSecondFileHandler = WatchedFileHandler("geruecht/log/debug/{}.log".format(logger_name))
|
|
||||||
logSecondFileHandler.setFormatter(FORMATTER)
|
|
||||||
logger.addHandler(logSecondFileHandler)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
logger.addHandler(logFileHandler)
|
|
||||||
logger.propagate = False
|
|
||||||
return logger
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
version: 1
|
||||||
|
disable_existing_loggers: True
|
||||||
|
|
||||||
|
formatters:
|
||||||
|
debug:
|
||||||
|
format: "%(asctime)s — %(filename)s - %(funcName)s - %(lineno)d - %(threadName)s - %(name)s — %(levelname)s — %(message)s"
|
||||||
|
|
||||||
|
simple:
|
||||||
|
format: "%(asctime)s - %(name)s - %(message)s"
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
console:
|
||||||
|
class: logging.StreamHandler
|
||||||
|
level: DEBUG
|
||||||
|
formatter: debug
|
||||||
|
stream: ext://sys.stdout
|
||||||
|
|
||||||
|
debug:
|
||||||
|
class: logging.handlers.WatchedFileHandler
|
||||||
|
level: DEBUG
|
||||||
|
formatter: debug
|
||||||
|
filename: geruecht/log/debug/debug.log
|
||||||
|
encoding: utf8
|
||||||
|
|
||||||
|
credit:
|
||||||
|
class: logging.handlers.WatchedFileHandler
|
||||||
|
level: INFO
|
||||||
|
formatter: simple
|
||||||
|
filename: geruecht/log/info/geruecht.log
|
||||||
|
encoding: utf8
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
class: logging.handlers.WatchedFileHandler
|
||||||
|
level: INFO
|
||||||
|
formatter: simple
|
||||||
|
filename: geruecht/log/info/jobs.log
|
||||||
|
encoding: utf8
|
||||||
|
|
||||||
|
loggers:
|
||||||
|
debug_logger:
|
||||||
|
level: DEBUG
|
||||||
|
handlers: [console, debug]
|
||||||
|
propagate: no
|
||||||
|
|
||||||
|
credit_logger:
|
||||||
|
level: INFO
|
||||||
|
handlers: [credit]
|
||||||
|
propagate: no
|
||||||
|
|
||||||
|
jobs_logger:
|
||||||
|
level: INFO
|
||||||
|
handlers: [jobs]
|
||||||
|
propagate: no
|
||||||
|
|
||||||
|
root:
|
||||||
|
level: INFO
|
||||||
|
handlers: [console, debug]
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.logger import getLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getDebugLogger()
|
||||||
|
|
||||||
class AccessToken():
|
class AccessToken():
|
||||||
""" Model for an AccessToken
|
""" Model for an AccessToken
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.logger import getLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getDebugLogger()
|
||||||
def create_empty_data():
|
def create_empty_data():
|
||||||
empty_data = {'id': 0,
|
empty_data = {'id': 0,
|
||||||
'jan_guthaben': 0,
|
'jan_guthaben': 0,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from geruecht.logger import getLogger
|
from geruecht.logger import getDebugLogger
|
||||||
from geruecht.model.creditList import CreditList, create_empty_data
|
from geruecht.model.creditList import CreditList, create_empty_data
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getDebugLogger()
|
||||||
|
|
||||||
|
|
||||||
class User():
|
class User():
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from geruecht import app
|
from geruecht import app
|
||||||
from geruecht.logger import getDebugLogger, getInfoLogger
|
from geruecht.logger import getDebugLogger
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
from geruecht.exceptions import PermissionDenied
|
from geruecht.exceptions import PermissionDenied
|
||||||
import geruecht.controller.accesTokenController as ac
|
import geruecht.controller.accesTokenController as ac
|
||||||
|
@ -10,29 +10,7 @@ from flask import request, jsonify
|
||||||
accesTokenController = ac.AccesTokenController()
|
accesTokenController = ac.AccesTokenController()
|
||||||
userController = uc.UserController()
|
userController = uc.UserController()
|
||||||
|
|
||||||
debug = getDebugLogger("MAIN-ROUTE", True)
|
debug = getDebugLogger()
|
||||||
info = getInfoLogger("MAIN-ROUTE")
|
|
||||||
|
|
||||||
def login(user, password):
|
|
||||||
return user.login(password)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/valid")
|
|
||||||
def _valid():
|
|
||||||
token = request.headers.get("Token")
|
|
||||||
accToken = accesTokenController.validateAccessToken(token, [MONEY])
|
|
||||||
if accToken:
|
|
||||||
return jsonify(accToken.user.toJSON())
|
|
||||||
accToken = accesTokenController.validateAccessToken(token, [BAR])
|
|
||||||
if accToken:
|
|
||||||
return jsonify(accToken.user.toJSON())
|
|
||||||
accToken = accesTokenController.validateAccessToken(token, [GASTRO])
|
|
||||||
if accToken:
|
|
||||||
return jsonify(accToken.user.toJSON())
|
|
||||||
accToken = accesTokenController.validateAccessToken(token, [USER])
|
|
||||||
if accToken:
|
|
||||||
return jsonify(accToken.user.toJSON())
|
|
||||||
return jsonify({"error": "permission denied"}), 401
|
|
||||||
|
|
||||||
@app.route("/pricelist", methods=['GET'])
|
@app.route("/pricelist", methods=['GET'])
|
||||||
def _getPricelist():
|
def _getPricelist():
|
||||||
|
@ -162,9 +140,9 @@ def _login():
|
||||||
"""
|
"""
|
||||||
debug.info("Start log in.")
|
debug.info("Start log in.")
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
debug.debug("JSON from request: {}".format(data))
|
|
||||||
username = data['username']
|
username = data['username']
|
||||||
password = data['password']
|
password = data['password']
|
||||||
|
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)
|
||||||
|
|
|
@ -4,41 +4,57 @@ import geruecht.controller.userController as uc
|
||||||
from geruecht.model import USER
|
from geruecht.model import USER
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.exceptions import DayLocked
|
from geruecht.exceptions import DayLocked
|
||||||
|
from geruecht.logger import getDebugLogger, getCreditLogger, getJobsLogger
|
||||||
|
|
||||||
user = Blueprint("user", __name__)
|
user = Blueprint("user", __name__)
|
||||||
|
|
||||||
userController = uc.UserController()
|
userController = uc.UserController()
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
creditL = getCreditLogger()
|
||||||
|
jobL = getJobsLogger()
|
||||||
|
|
||||||
@user.route("/user/main")
|
@user.route("/user/main")
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _main(**kwargs):
|
def _main(**kwargs):
|
||||||
if 'accToken' in kwargs:
|
debug.info("/user/main")
|
||||||
accToken = kwargs['accToken']
|
try:
|
||||||
accToken.user = userController.getUser(accToken.user.uid)
|
if 'accToken' in kwargs:
|
||||||
retVal = accToken.user.toJSON()
|
accToken = kwargs['accToken']
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
accToken.user = userController.getUser(accToken.user.uid)
|
||||||
return jsonify(retVal)
|
retVal = accToken.user.toJSON()
|
||||||
return jsonify("error", "something went wrong"), 500
|
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
||||||
|
debug.debug("return {{}}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify("error", "something went wrong"), 500
|
||||||
|
|
||||||
@user.route("/user/addAmount", methods=['POST'])
|
@user.route("/user/addAmount", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _addAmount(**kwargs):
|
def _addAmount(**kwargs):
|
||||||
if 'accToken' in kwargs:
|
debug.info("/user/addAmount")
|
||||||
accToken = kwargs['accToken']
|
try:
|
||||||
data = request.get_json()
|
if 'accToken' in kwargs:
|
||||||
amount = int(data['amount'])
|
accToken = kwargs['accToken']
|
||||||
date = datetime.now()
|
data = request.get_json()
|
||||||
userController.addAmount(accToken.user.uid, amount, year=date.year, month=date.month)
|
amount = int(data['amount'])
|
||||||
accToken.user = userController.getUser(accToken.user.uid)
|
date = datetime.now()
|
||||||
retVal = accToken.user.toJSON()
|
userController.addAmount(accToken.user.uid, amount, year=date.year, month=date.month)
|
||||||
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
accToken.user = userController.getUser(accToken.user.uid)
|
||||||
return jsonify(retVal)
|
retVal = accToken.user.toJSON()
|
||||||
return jsonify({"error": "something went wrong"}), 500
|
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
||||||
|
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:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": "something went wrong"}), 500
|
||||||
|
|
||||||
@user.route("/user/saveConfig", methods=['POST'])
|
@user.route("/user/saveConfig", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _saveConfig(**kwargs):
|
def _saveConfig(**kwargs):
|
||||||
|
debug.info("/user/saveConfig")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -46,47 +62,55 @@ 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))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/job", methods=['POST'])
|
@user.route("/user/job", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _getUser(**kwargs):
|
def _getUser(**kwargs):
|
||||||
data = request.get_json()
|
debug.info("/user/job")
|
||||||
day = data['day']
|
try:
|
||||||
month = data['month']
|
data = request.get_json()
|
||||||
year = data['year']
|
day = data['day']
|
||||||
date = datetime(year, month, day, 12)
|
month = data['month']
|
||||||
lockedDay = userController.getLockedDay(date)
|
year = data['year']
|
||||||
if not lockedDay:
|
date = datetime(year, month, day, 12)
|
||||||
lockedDay = {
|
lockedDay = userController.getLockedDay(date)
|
||||||
'date': {
|
if not lockedDay:
|
||||||
'year': year,
|
lockedDay = {
|
||||||
'month': month,
|
'date': {
|
||||||
'day': day
|
'year': year,
|
||||||
},
|
'month': month,
|
||||||
'locked': False
|
'day': day
|
||||||
|
},
|
||||||
|
'locked': False
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
lockedDay = {
|
||||||
|
'date': {
|
||||||
|
'year': year,
|
||||||
|
'month': month,
|
||||||
|
'day': day
|
||||||
|
},
|
||||||
|
'locked': lockedDay['locked']
|
||||||
|
}
|
||||||
|
retVal = {
|
||||||
|
'worker': userController.getWorker(date),
|
||||||
|
'day': lockedDay
|
||||||
}
|
}
|
||||||
else:
|
debug.debug("retrun {{}}".format(retVal))
|
||||||
lockedDay = {
|
return jsonify(retVal)
|
||||||
'date': {
|
except Exception as err:
|
||||||
'year': year,
|
debug.debug("exception", exc_info=True)
|
||||||
'month': month,
|
return jsonify({"error": str(err)}), 500
|
||||||
'day': day
|
|
||||||
},
|
|
||||||
'locked': lockedDay['locked']
|
|
||||||
}
|
|
||||||
retVal = {
|
|
||||||
'worker': userController.getWorker(date),
|
|
||||||
'day': lockedDay
|
|
||||||
}
|
|
||||||
print(retVal)
|
|
||||||
return jsonify(retVal)
|
|
||||||
|
|
||||||
@user.route("/user/addJob", methods=['POST'])
|
@user.route("/user/addJob", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _addUser(**kwargs):
|
def _addUser(**kwargs):
|
||||||
|
debug.info("/user/addJob")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -97,16 +121,20 @@ 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)
|
||||||
print(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)
|
return jsonify(retVal)
|
||||||
except DayLocked as err:
|
except DayLocked as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({'error': str(err)}), 403
|
return jsonify({'error': str(err)}), 403
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({'error': str(err)}), 409
|
return jsonify({'error': str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/deleteJob", methods=['POST'])
|
@user.route("/user/deleteJob", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _deletJob(**kwargs):
|
def _deletJob(**kwargs):
|
||||||
|
debug.info("/user/deleteJob")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -117,15 +145,20 @@ def _deletJob(**kwargs):
|
||||||
year = data['year']
|
year = data['year']
|
||||||
date = datetime(year,month,day,12)
|
date = datetime(year,month,day,12)
|
||||||
userController.deleteWorker(user.uid, date, True)
|
userController.deleteWorker(user.uid, date, True)
|
||||||
|
debug.debug("return ok")
|
||||||
|
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(user.firstname, user.lastname, date.date()))
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
except DayLocked as err:
|
except DayLocked as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 403
|
return jsonify({"error": str(err)}), 403
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/transactJob", methods=['POST'])
|
@user.route("/user/transactJob", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _transactJob(**kwargs):
|
def _transactJob(**kwargs):
|
||||||
|
debug.info("/user/transactJob")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -138,17 +171,22 @@ def _transactJob(**kwargs):
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
to_user = userController.getUser(username)
|
to_user = userController.getUser(username)
|
||||||
retVal = userController.setTransactJob(user, to_user, date)
|
retVal = userController.setTransactJob(user, to_user, date)
|
||||||
|
from_userl = retVal['from_user']
|
||||||
|
to_userl = retVal['to_user']
|
||||||
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}
|
||||||
print(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)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/answerTransactJob", methods=['POST'])
|
@user.route("/user/answerTransactJob", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _answer(**kwargs):
|
def _answer(**kwargs):
|
||||||
|
debug.info("/user/answerTransactJob")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -162,17 +200,22 @@ def _answer(**kwargs):
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
from_user = userController.getUser(username)
|
from_user = userController.getUser(username)
|
||||||
retVal = userController.answerdTransactJob(from_user, user, date, answer)
|
retVal = userController.answerdTransactJob(from_user, user, date, answer)
|
||||||
|
from_userl = retVal['from_user']
|
||||||
|
to_userl = retVal['to_user']
|
||||||
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}
|
||||||
print(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)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/jobRequests", methods=['POST'])
|
@user.route("/user/jobRequests", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _requests(**kwargs):
|
def _requests(**kwargs):
|
||||||
|
debug.info("/user/jobRequests")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -188,14 +231,16 @@ 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}
|
||||||
print(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)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/getTransactJobs", methods=['POST'])
|
@user.route("/user/getTransactJobs", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _getTransactJobs(**kwargs):
|
def _getTransactJobs(**kwargs):
|
||||||
|
debug.info("/user/getTransactJobs")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -211,14 +256,16 @@ 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}
|
||||||
print(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)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/deleteTransactJob", methods=['POST'])
|
@user.route("/user/deleteTransactJob", methods=['POST'])
|
||||||
@login_required(groups=[USER])
|
@login_required(groups=[USER])
|
||||||
def _deleteTransactJob(**kwargs):
|
def _deleteTransactJob(**kwargs):
|
||||||
|
debug.info("/user/deleteTransactJob")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -231,8 +278,11 @@ def _deleteTransactJob(**kwargs):
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
to_user = userController.getUser(username)
|
to_user = userController.getUser(username)
|
||||||
userController.deleteTransactJob(from_user, to_user, date)
|
userController.deleteTransactJob(from_user, to_user, date)
|
||||||
|
debug.debug("return ok")
|
||||||
|
jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(from_user.firstname, from_user.lastname, to_user.firstname, to_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)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
||||||
@user.route("/user/storno", methods=['POST'])
|
@user.route("/user/storno", methods=['POST'])
|
||||||
|
@ -246,6 +296,8 @@ def _storno(**kwargs):
|
||||||
JSON-File with userID and the amount
|
JSON-File with userID and the amount
|
||||||
or ERROR 401 Permission Denied
|
or ERROR 401 Permission Denied
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
debug.info("/user/storno")
|
||||||
try:
|
try:
|
||||||
if 'accToken' in kwargs:
|
if 'accToken' in kwargs:
|
||||||
accToken = kwargs['accToken']
|
accToken = kwargs['accToken']
|
||||||
|
@ -258,6 +310,9 @@ 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))
|
||||||
|
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:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 409
|
return jsonify({"error": str(err)}), 409
|
||||||
|
|
|
@ -4,7 +4,10 @@ import geruecht.controller.userController as uc
|
||||||
import geruecht.controller.ldapController as lc
|
import geruecht.controller.ldapController as lc
|
||||||
from geruecht.decorator import login_required
|
from geruecht.decorator import login_required
|
||||||
from geruecht.model import MONEY, GASTRO, VORSTAND
|
from geruecht.model import MONEY, GASTRO, VORSTAND
|
||||||
import time
|
from geruecht.logger import getDebugLogger, getJobsLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
jobL = getJobsLogger()
|
||||||
|
|
||||||
vorstand = Blueprint("vorstand", __name__)
|
vorstand = Blueprint("vorstand", __name__)
|
||||||
userController = uc.UserController()
|
userController = uc.UserController()
|
||||||
|
@ -13,124 +16,156 @@ 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])
|
||||||
def _setStatus(**kwargs):
|
def _setStatus(**kwargs):
|
||||||
|
debug.info("/um/setStatus")
|
||||||
try:
|
try:
|
||||||
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))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
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):
|
||||||
|
debug.info("/um/updateStatus")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
retVal = userController.updateStatus(data)
|
retVal = userController.updateStatus(data)
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/um/deleteStatus")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userController.deleteStatus(data)
|
userController.deleteStatus(data)
|
||||||
|
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)
|
||||||
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):
|
||||||
|
debug.info("/um/updateStatusUser")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
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))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
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):
|
||||||
|
debug.info("/um/updateVoting")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
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))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
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):
|
||||||
|
debug.info("/sm/addUser")
|
||||||
if request.method == 'GET':
|
try:
|
||||||
return "<h1>HEllo World</h1>"
|
data = request.get_json()
|
||||||
|
user = data['user']
|
||||||
data = request.get_json()
|
day = data['day']
|
||||||
user = data['user']
|
month = data['month']
|
||||||
day = data['day']
|
year = data['year']
|
||||||
month = data['month']
|
date = datetime(year,month,day,12)
|
||||||
year = data['year']
|
retVal = userController.addWorker(user['username'], date)
|
||||||
date = datetime(year,month,day,12)
|
debug.debug("retrun {{}}".format(retVal))
|
||||||
retVal = userController.addWorker(user['username'], date)
|
userl = userController.getUser(user)
|
||||||
print(retVal)
|
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:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
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):
|
||||||
data = request.get_json()
|
debug.info("/sm/getUser")
|
||||||
day = data['day']
|
try:
|
||||||
month = data['month']
|
data = request.get_json()
|
||||||
year = data['year']
|
day = data['day']
|
||||||
date = datetime(year, month, day, 12)
|
month = data['month']
|
||||||
lockedDay = userController.getLockedDay(date)
|
year = data['year']
|
||||||
if not lockedDay:
|
date = datetime(year, month, day, 12)
|
||||||
lockedDay = {
|
lockedDay = userController.getLockedDay(date)
|
||||||
'date': {
|
if not lockedDay:
|
||||||
'year': year,
|
lockedDay = {
|
||||||
'month': month,
|
'date': {
|
||||||
'day': day
|
'year': year,
|
||||||
},
|
'month': month,
|
||||||
'locked': False
|
'day': day
|
||||||
|
},
|
||||||
|
'locked': False
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
lockedDay = {
|
||||||
|
'date': {
|
||||||
|
'year': year,
|
||||||
|
'month': month,
|
||||||
|
'day': day
|
||||||
|
},
|
||||||
|
'locked': lockedDay['locked']
|
||||||
|
}
|
||||||
|
retVal = {
|
||||||
|
'worker': userController.getWorker(date),
|
||||||
|
'day': lockedDay
|
||||||
}
|
}
|
||||||
else:
|
debug.debug("return {{}}".format(retVal))
|
||||||
lockedDay = {
|
return jsonify(retVal)
|
||||||
'date': {
|
except Exception as err:
|
||||||
'year': year,
|
debug.debug("exception", exc_info=True)
|
||||||
'month': month,
|
return jsonify({"error": str(err)}), 500
|
||||||
'day': day
|
|
||||||
},
|
|
||||||
'locked': lockedDay['locked']
|
|
||||||
}
|
|
||||||
retVal = {
|
|
||||||
'worker': userController.getWorker(date),
|
|
||||||
'day': lockedDay
|
|
||||||
}
|
|
||||||
print(retVal)
|
|
||||||
return jsonify(retVal)
|
|
||||||
|
|
||||||
@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):
|
||||||
data = request.get_json()
|
debug.info("/sm/deletUser")
|
||||||
user = data['user']
|
try:
|
||||||
day = data['day']
|
data = request.get_json()
|
||||||
month = data['month']
|
user = data['user']
|
||||||
year = data['year']
|
day = data['day']
|
||||||
date = datetime(year, month, day, 12)
|
month = data['month']
|
||||||
userController.deleteWorker(user['username'], date)
|
year = data['year']
|
||||||
return jsonify({"ok": "ok"})
|
date = datetime(year, month, day, 12)
|
||||||
|
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()))
|
||||||
|
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'])
|
@vorstand.route("/sm/lockDay", methods=['POST'])
|
||||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||||
def _lockDay(**kwargs):
|
def _lockDay(**kwargs):
|
||||||
|
debug.info("/sm/lockDay")
|
||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
year = data['year']
|
year = data['year']
|
||||||
|
@ -157,13 +192,20 @@ def _lockDay(**kwargs):
|
||||||
},
|
},
|
||||||
'locked': lockedDay['locked']
|
'locked': lockedDay['locked']
|
||||||
}
|
}
|
||||||
print(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)
|
||||||
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):
|
||||||
retVal = ldap.getAllUser()
|
debug.info("/sm/searchWithExtern")
|
||||||
return jsonify(retVal)
|
try:
|
||||||
|
retVal = ldap.getAllUser()
|
||||||
|
debug.debug("return {{}}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
Loading…
Reference in New Issue