finished ##215
only database controlle is left for debugging
This commit is contained in:
parent
f029aa6096
commit
804eba1abd
|
@ -70,7 +70,7 @@ def _baradd(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userID = data['userId']
|
userID = data['userId']
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
|
amountl = amount
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addAmount(
|
userController.addAmount(
|
||||||
userID, amount, year=date.year, month=date.month)
|
userID, amount, year=date.year, month=date.month)
|
||||||
|
@ -88,7 +88,7 @@ def _baradd(**kwargs):
|
||||||
dic['type'] = type
|
dic['type'] = type
|
||||||
debug.debug("return {{ {} }}".format(dic))
|
debug.debug("return {{ {} }}".format(dic))
|
||||||
creditL.info("{} Baruser {} {} fügt {} {} {} € Schulden hinzu.".format(
|
creditL.info("{} Baruser {} {} fügt {} {} {} € Schulden hinzu.".format(
|
||||||
date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amount/100))
|
date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amountl/100))
|
||||||
return jsonify(dic)
|
return jsonify(dic)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
debug.debug("exception", exc_info=True)
|
debug.debug("exception", exc_info=True)
|
||||||
|
@ -133,7 +133,7 @@ def _storno(**kwargs):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
userID = data['userId']
|
userID = data['userId']
|
||||||
amount = int(data['amount'])
|
amount = int(data['amount'])
|
||||||
|
amountl = amount
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
userController.addCredit(
|
userController.addCredit(
|
||||||
userID, amount, year=date.year, month=date.month)
|
userID, amount, year=date.year, month=date.month)
|
||||||
|
@ -151,7 +151,7 @@ def _storno(**kwargs):
|
||||||
dic['type'] = type
|
dic['type'] = type
|
||||||
debug.debug("return {{ {} }}".format(dic))
|
debug.debug("return {{ {} }}".format(dic))
|
||||||
creditL.info("{} Baruser {} {} storniert {} € von {} {}".format(
|
creditL.info("{} Baruser {} {} storniert {} € von {} {}".format(
|
||||||
date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amount/100, user.firstname, user.lastname))
|
date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, amountl/100, user.firstname, user.lastname))
|
||||||
return jsonify(dic)
|
return jsonify(dic)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
debug.debug("exception", exc_info=True)
|
debug.debug("exception", exc_info=True)
|
||||||
|
|
|
@ -2,10 +2,12 @@ from geruecht.model.accessToken import AccessToken
|
||||||
import geruecht.controller as gc
|
import geruecht.controller as gc
|
||||||
import geruecht.controller.userController as uc
|
import geruecht.controller.userController as uc
|
||||||
from geruecht.model import BAR
|
from geruecht.model import BAR
|
||||||
from geruecht.controller import LOGGER
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import hashlib
|
import hashlib
|
||||||
from . import Singleton
|
from . import Singleton
|
||||||
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
userController = uc.UserController()
|
userController = uc.UserController()
|
||||||
|
|
||||||
|
@ -26,18 +28,21 @@ class AccesTokenController(metaclass=Singleton):
|
||||||
|
|
||||||
Initialize Thread and set tokenList empty.
|
Initialize Thread and set tokenList empty.
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Initialize AccessTokenController")
|
debug.info("init accesstoken controller")
|
||||||
self.lifetime = gc.accConfig
|
self.lifetime = gc.accConfig
|
||||||
|
|
||||||
self.tokenList = []
|
self.tokenList = []
|
||||||
|
|
||||||
def checkBar(self, user):
|
def checkBar(self, user):
|
||||||
|
debug.info("check if user {{ {} }} is baruser".format(user))
|
||||||
if (userController.checkBarUser(user)):
|
if (userController.checkBarUser(user)):
|
||||||
if BAR not in user.group:
|
if BAR not in user.group:
|
||||||
|
debug.debug("append bar to user {{ {} }}".format(user))
|
||||||
user.group.append(BAR)
|
user.group.append(BAR)
|
||||||
else:
|
else:
|
||||||
while BAR in user.group:
|
while BAR in user.group:
|
||||||
|
debug.debug("delete bar from user {{ {} }}".format(user))
|
||||||
user.group.remove(BAR)
|
user.group.remove(BAR)
|
||||||
|
debug.debug("user {{ {} }} groups are {{ {} }}".format(user, user.group))
|
||||||
|
|
||||||
def validateAccessToken(self, token, group):
|
def validateAccessToken(self, token, group):
|
||||||
""" Verify Accestoken
|
""" Verify Accestoken
|
||||||
|
@ -51,28 +56,29 @@ class AccesTokenController(metaclass=Singleton):
|
||||||
Returns:
|
Returns:
|
||||||
An the AccesToken for this given Token or False.
|
An the AccesToken for this given Token or False.
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Verify AccessToken with token: {} and group: {}".format(token, group))
|
debug.info("check token {{ {} }} is valid")
|
||||||
for accToken in self.tokenList:
|
for accToken in self.tokenList:
|
||||||
LOGGER.debug("AccessToken is {}".format(accToken))
|
debug.debug("accesstoken is {}".format(accToken))
|
||||||
endTime = accToken.timestamp + timedelta(seconds=accToken.lifetime)
|
endTime = accToken.timestamp + timedelta(seconds=accToken.lifetime)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
LOGGER.debug("Check if AccessToken's Endtime {} is bigger then now {}".format(endTime, now))
|
debug.debug("now is {{ {} }}, endtime is {{ {} }}".format(now, endTime))
|
||||||
if now <= endTime:
|
if now <= endTime:
|
||||||
LOGGER.debug("Check is token {} same as in AccessToken {}".format(token, accToken))
|
debug.debug("check if token {{ {} }} is same as {{ {} }}".format(token, accToken))
|
||||||
if accToken == token:
|
if accToken == token:
|
||||||
self.checkBar(accToken.user)
|
self.checkBar(accToken.user)
|
||||||
LOGGER.debug("Check if AccesToken {} has same group {}".format(accToken, group))
|
debug.debug("check if accestoken {{ {} }} has group {{ {} }}".format(accToken, group))
|
||||||
if self.isSameGroup(accToken, group):
|
if self.isSameGroup(accToken, group):
|
||||||
accToken.updateTimestamp()
|
accToken.updateTimestamp()
|
||||||
LOGGER.info("Found AccessToken {} with token: {} and group: {}".format(accToken, token, group))
|
debug.debug("found accesstoken {{ {} }} with token: {{ {} }} and group: {{ {} }}".format(accToken, token, group))
|
||||||
return accToken
|
return accToken
|
||||||
else:
|
else:
|
||||||
|
debug.debug("accesstoken is {{ {} }} out of date".format(accToken))
|
||||||
self.deleteAccessToken(accToken)
|
self.deleteAccessToken(accToken)
|
||||||
LOGGER.info("Found no valid AccessToken with token: {} and group: {}".format(token, group))
|
debug.debug("no valid accesstoken with token: {{ {} }} and group: {{ {} }}".format(token, group))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def deleteAccessToken(self, accToken):
|
def deleteAccessToken(self, accToken):
|
||||||
LOGGER.debug("AccessToken {} is no longer valid and will removed".format(accToken))
|
debug.info("delete accesstoken {{ {} }}".format(accToken))
|
||||||
self.tokenList.remove(accToken)
|
self.tokenList.remove(accToken)
|
||||||
|
|
||||||
def createAccesToken(self, user, ldap_conn):
|
def createAccesToken(self, user, ldap_conn):
|
||||||
|
@ -86,14 +92,13 @@ class AccesTokenController(metaclass=Singleton):
|
||||||
Returns:
|
Returns:
|
||||||
A created Token for User
|
A created Token for User
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Create AccessToken")
|
debug.info("creat accesstoken")
|
||||||
now = datetime.ctime(datetime.now())
|
now = datetime.ctime(datetime.now())
|
||||||
token = hashlib.md5((now + user.dn).encode('utf-8')).hexdigest()
|
token = hashlib.md5((now + user.dn).encode('utf-8')).hexdigest()
|
||||||
self.checkBar(user)
|
self.checkBar(user)
|
||||||
accToken = AccessToken(user, token, ldap_conn, self.lifetime, datetime.now())
|
accToken = AccessToken(user, token, ldap_conn, self.lifetime, datetime.now())
|
||||||
LOGGER.debug("Add AccessToken {} to current Tokens".format(accToken))
|
debug.debug("accesstoken is {{ {} }}".format(accToken))
|
||||||
self.tokenList.append(accToken)
|
self.tokenList.append(accToken)
|
||||||
LOGGER.info("Finished create AccessToken {} with Token {}".format(accToken, token))
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def isSameGroup(self, accToken, groups):
|
def isSameGroup(self, accToken, groups):
|
||||||
|
@ -108,8 +113,7 @@ class AccesTokenController(metaclass=Singleton):
|
||||||
Returns:
|
Returns:
|
||||||
A Bool. If the same then True else False
|
A Bool. If the same then True else False
|
||||||
"""
|
"""
|
||||||
print("controll if", accToken, "hase groups", groups)
|
debug.info("check accesstoken {{ {} }} has group {{ {} }}".format(accToken, groups))
|
||||||
LOGGER.debug("Check if AccessToken {} has group {}".format(accToken, groups))
|
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group in accToken.user.group: return True
|
if group in accToken.user.group: return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -5,11 +5,12 @@ from email.mime.text import MIMEText
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
from geruecht.logger import getDebugLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
class EmailController():
|
class EmailController():
|
||||||
|
|
||||||
def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""):
|
def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""):
|
||||||
|
debug.info("init email controller")
|
||||||
self.smtpServer = smtpServer
|
self.smtpServer = smtpServer
|
||||||
self.port = port
|
self.port = port
|
||||||
self.user = user
|
self.user = user
|
||||||
|
@ -19,33 +20,36 @@ class EmailController():
|
||||||
self.email = email
|
self.email = email
|
||||||
else:
|
else:
|
||||||
self.email = user
|
self.email = user
|
||||||
LOGGER.debug('Init EmailController with smtpServer={}, port={}, user={}, crypt={}, email={}'.format(smtpServer, port, user, crypt, self.email))
|
debug.debug("smtpServer is {{ {} }}, port is {{ {} }}, user is {{ {} }}, crypt is {{ {} }}, email is {{ {} }}".format(smtpServer, port, user, crypt, self.email))
|
||||||
|
|
||||||
def __connect__(self):
|
def __connect__(self):
|
||||||
LOGGER.info('Connect to E-Mail-Server')
|
debug.info('connect to email server')
|
||||||
if self.crypt == 'SSL':
|
if self.crypt == 'SSL':
|
||||||
self.smtp = smtplib.SMTP_SSL(self.smtpServer, self.port)
|
self.smtp = smtplib.SMTP_SSL(self.smtpServer, self.port)
|
||||||
log = self.smtp.ehlo()
|
log = self.smtp.ehlo()
|
||||||
LOGGER.debug(log)
|
debug.debug("ehlo is {{ {} }}".format(log))
|
||||||
if self.crypt == 'STARTTLS':
|
if self.crypt == 'STARTTLS':
|
||||||
self.smtp = smtplib.SMTP(self.smtpServer, self.port)
|
self.smtp = smtplib.SMTP(self.smtpServer, self.port)
|
||||||
log = self.smtp.ehlo()
|
log = self.smtp.ehlo()
|
||||||
LOGGER.debug(log)
|
debug.debug("ehlo is {{ {} }}".format(log))
|
||||||
log = self.smtp.starttls()
|
log = self.smtp.starttls()
|
||||||
LOGGER.debug(log)
|
debug.debug("starttles is {{ {} }}".format(log))
|
||||||
log = self.smtp.login(self.user, self.passwd)
|
log = self.smtp.login(self.user, self.passwd)
|
||||||
LOGGER.debug(log)
|
debug.debug("login is {{ {} }}".format(log))
|
||||||
|
|
||||||
def jobTransact(self, user, jobtransact):
|
def jobTransact(self, user, jobtransact):
|
||||||
|
debug.info("create email jobtransact {{ {} }}for user {{ {} }}".format(jobtransact, user))
|
||||||
date = '{}.{}.{}'.format(jobtransact['date'].day, jobtransact['date'].month, jobtransact['date'].year)
|
date = '{}.{}.{}'.format(jobtransact['date'].day, jobtransact['date'].month, jobtransact['date'].year)
|
||||||
from_user = '{} {}'.format(jobtransact['from_user'].firstname, jobtransact['from_user'].lastname)
|
from_user = '{} {}'.format(jobtransact['from_user'].firstname, jobtransact['from_user'].lastname)
|
||||||
subject = 'Bardienstanfrage am {}'.format(date)
|
subject = 'Bardienstanfrage am {}'.format(date)
|
||||||
text = MIMEText(
|
text = MIMEText(
|
||||||
"Hallo {} {},\n"
|
"Hallo {} {},\n"
|
||||||
"{} fragt, ob du am {} zum Bardienst teilnehmen willst. Beantworte die Anfrage im Userportal von Flaschengeist.".format(user.firstname, user.lastname, from_user, date), 'utf-8')
|
"{} fragt, ob du am {} zum Bardienst teilnehmen willst. Beantworte die Anfrage im Userportal von Flaschengeist.".format(user.firstname, user.lastname, from_user, date), 'utf-8')
|
||||||
|
debug.debug("subject is {{ {} }}, text is {{ {} }}".format(subject, text.as_string()))
|
||||||
return (subject, text)
|
return (subject, text)
|
||||||
|
|
||||||
def credit(self, user):
|
def credit(self, user):
|
||||||
|
debug.info("create email credit for user {{ {} }}".format(user))
|
||||||
subject = Header('Gerücht, bezahle deine Schulden!', 'utf-8')
|
subject = Header('Gerücht, bezahle deine Schulden!', 'utf-8')
|
||||||
sum = user.getGeruecht(datetime.now().year).getSchulden()
|
sum = user.getGeruecht(datetime.now().year).getSchulden()
|
||||||
if sum < 0:
|
if sum < 0:
|
||||||
|
@ -57,12 +61,14 @@ class EmailController():
|
||||||
text = MIMEText(
|
text = MIMEText(
|
||||||
"Hallo {} {},\nDu hast {} im Wert von {:.2f} €. {}\n\nDiese Nachricht wurde automatisch erstellt.".format(
|
"Hallo {} {},\nDu hast {} im Wert von {:.2f} €. {}\n\nDiese Nachricht wurde automatisch erstellt.".format(
|
||||||
user.firstname, user.lastname, type, abs(sum) / 100, add), 'plain', 'utf-8')
|
user.firstname, user.lastname, type, abs(sum) / 100, add), 'plain', 'utf-8')
|
||||||
|
debug.debug("subject is {{ {} }}, text is {{ {} }}".format(subject, text.as_string()))
|
||||||
return (subject, text)
|
return (subject, text)
|
||||||
|
|
||||||
def sendMail(self, user, type='credit', jobtransact=None):
|
def sendMail(self, user, type='credit', jobtransact=None):
|
||||||
|
debug.info("send email to user {{ {} }}".format(user))
|
||||||
try:
|
try:
|
||||||
if user.mail == 'None' or not user.mail:
|
if user.mail == 'None' or not user.mail:
|
||||||
LOGGER.debug("cant send email to {}. Has no email-address. {}".format(user.uid, {'error': True, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}))
|
debug.warning("user {{ {} }} has no email-address".format(user))
|
||||||
raise Exception("no valid Email")
|
raise Exception("no valid Email")
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['From'] = self.email
|
msg['From'] = self.email
|
||||||
|
@ -78,10 +84,10 @@ class EmailController():
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
msg.attach(text)
|
msg.attach(text)
|
||||||
|
|
||||||
LOGGER.debug("Send email to {}: '{}'".format(user.uid, msg.as_string()))
|
debug.debug("send email {{ {} }} to user {{ {} }}".format(msg.as_string(), user))
|
||||||
self.__connect__()
|
self.__connect__()
|
||||||
self.smtp.sendmail(self.email, user.mail, msg.as_string())
|
self.smtp.sendmail(self.email, user.mail, msg.as_string())
|
||||||
LOGGER.debug("Sended email to {}. {}".format(user.uid, {'error': False, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}))
|
|
||||||
return {'error': False, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}
|
return {'error': False, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}
|
||||||
except Exception:
|
except Exception:
|
||||||
|
debug.warning("exception in send email", exc_info=True)
|
||||||
return {'error': True, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}
|
return {'error': True, 'user': {'userId': user.uid, 'firstname': user.firstname, 'lastname': user.lastname}}
|
||||||
|
|
|
@ -6,7 +6,9 @@ from geruecht.exceptions import PermissionDenied
|
||||||
from . import Singleton
|
from . import Singleton
|
||||||
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion
|
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion
|
||||||
from geruecht import ldapConfig
|
from geruecht import ldapConfig
|
||||||
import traceback
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
class LDAPController(metaclass=Singleton):
|
class LDAPController(metaclass=Singleton):
|
||||||
'''
|
'''
|
||||||
|
@ -14,27 +16,38 @@ class LDAPController(metaclass=Singleton):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
debug.info("init ldap controller")
|
||||||
self.dn = ldapConfig['dn']
|
self.dn = ldapConfig['dn']
|
||||||
self.ldap = ldap
|
self.ldap = ldap
|
||||||
|
debug.debug("base dn is {{ {} }}".format(self.dn))
|
||||||
|
debug.debug("ldap is {{ {} }}".format(self.ldap))
|
||||||
|
|
||||||
|
|
||||||
def login(self, username, password):
|
def login(self, username, password):
|
||||||
|
debug.info("login user {{ {} }} in ldap")
|
||||||
try:
|
try:
|
||||||
retVal = self.ldap.authenticate(username, password, 'uid', self.dn)
|
retVal = self.ldap.authenticate(username, password, 'uid', self.dn)
|
||||||
|
debug.debug("authentification to ldap is {{ {} }}".format(retVal))
|
||||||
if not retVal:
|
if not retVal:
|
||||||
|
debug.debug("authenification is incorrect")
|
||||||
raise PermissionDenied("Invalid Password or Username")
|
raise PermissionDenied("Invalid Password or Username")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
traceback.print_exception(err)
|
debug.warning("exception while login into ldap", exc_info=True)
|
||||||
raise PermissionDenied("Wrong username or password.")
|
raise PermissionDenied("Invalid Password or Username. {}".format(err))
|
||||||
|
|
||||||
def bind(self, user, password):
|
def bind(self, user, password):
|
||||||
|
debug.info("bind user {{ {} }} to ldap")
|
||||||
ldap_conn = self.ldap.connect(user.dn, password)
|
ldap_conn = self.ldap.connect(user.dn, password)
|
||||||
|
debug.debug("ldap_conn is {{ {} }}".format(ldap_conn))
|
||||||
return ldap_conn
|
return ldap_conn
|
||||||
|
|
||||||
def getUserData(self, username):
|
def getUserData(self, username):
|
||||||
|
debug.info("get user data from ldap of user {{ {} }}".format(username))
|
||||||
try:
|
try:
|
||||||
|
debug.debug("search user in ldap")
|
||||||
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid={})'.format(username), SUBTREE, attributes=['uid', 'givenName', 'sn', 'mail'])
|
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid={})'.format(username), SUBTREE, attributes=['uid', 'givenName', 'sn', 'mail'])
|
||||||
user = self.ldap.connection.response[0]['attributes']
|
user = self.ldap.connection.response[0]['attributes']
|
||||||
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
retVal = {
|
retVal = {
|
||||||
'dn': self.ldap.connection.response[0]['dn'],
|
'dn': self.ldap.connection.response[0]['dn'],
|
||||||
'firstname': user['givenName'][0],
|
'firstname': user['givenName'][0],
|
||||||
|
@ -43,20 +56,25 @@ class LDAPController(metaclass=Singleton):
|
||||||
}
|
}
|
||||||
if user['mail']:
|
if user['mail']:
|
||||||
retVal['mail'] = user['mail'][0]
|
retVal['mail'] = user['mail'][0]
|
||||||
|
debug.debug("user is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
except:
|
except:
|
||||||
|
debug.warning("exception in get user data from ldap", exc_info=True)
|
||||||
raise PermissionDenied("No User exists with this uid.")
|
raise PermissionDenied("No User exists with this uid.")
|
||||||
|
|
||||||
|
|
||||||
def getGroup(self, username):
|
def getGroup(self, username):
|
||||||
|
debug.info("get group from user {{ {} }}".format(username))
|
||||||
try:
|
try:
|
||||||
retVal = []
|
retVal = []
|
||||||
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid={})'.format(username), SUBTREE, attributes=['gidNumber'])
|
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid={})'.format(username), SUBTREE, attributes=['gidNumber'])
|
||||||
response = self.ldap.connection.response
|
response = self.ldap.connection.response
|
||||||
main_group_number = self.ldap.connection.response[0]['attributes']['gidNumber']
|
main_group_number = self.ldap.connection.response[0]['attributes']['gidNumber']
|
||||||
|
debug.debug("main group number is {{ {} }}".format(main_group_number))
|
||||||
if main_group_number:
|
if main_group_number:
|
||||||
group_data = self.ldap.connection.search('ou=group,{}'.format(self.dn), '(gidNumber={})'.format(main_group_number), attributes=['cn'])
|
group_data = self.ldap.connection.search('ou=group,{}'.format(self.dn), '(gidNumber={})'.format(main_group_number), attributes=['cn'])
|
||||||
group_name = self.ldap.connection.response[0]['attributes']['cn'][0]
|
group_name = self.ldap.connection.response[0]['attributes']['cn'][0]
|
||||||
|
debug.debug("group name is {{ {} }}".format(group_name))
|
||||||
if group_name == 'ldap-user':
|
if group_name == 'ldap-user':
|
||||||
retVal.append(USER)
|
retVal.append(USER)
|
||||||
if group_name == 'extern':
|
if group_name == 'extern':
|
||||||
|
@ -64,8 +82,10 @@ class LDAPController(metaclass=Singleton):
|
||||||
|
|
||||||
self.ldap.connection.search('ou=group,{}'.format(self.dn), '(memberUID={})'.format(username), SUBTREE, attributes=['cn'])
|
self.ldap.connection.search('ou=group,{}'.format(self.dn), '(memberUID={})'.format(username), SUBTREE, attributes=['cn'])
|
||||||
groups_data = self.ldap.connection.response
|
groups_data = self.ldap.connection.response
|
||||||
|
debug.debug("groups number is {{ {} }}".format(groups_data))
|
||||||
for data in groups_data:
|
for data in groups_data:
|
||||||
group_name = data['attributes']['cn'][0]
|
group_name = data['attributes']['cn'][0]
|
||||||
|
debug.debug("group name is {{ {} }}".format(group_name))
|
||||||
if group_name == 'finanzer':
|
if group_name == 'finanzer':
|
||||||
retVal.append(MONEY)
|
retVal.append(MONEY)
|
||||||
elif group_name == 'gastro':
|
elif group_name == 'gastro':
|
||||||
|
@ -74,9 +94,11 @@ class LDAPController(metaclass=Singleton):
|
||||||
retVal.append(BAR)
|
retVal.append(BAR)
|
||||||
elif group_name == 'vorstand':
|
elif group_name == 'vorstand':
|
||||||
retVal.append(VORSTAND)
|
retVal.append(VORSTAND)
|
||||||
|
debug.debug("groups are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
traceback.print_exc()
|
debug.warning("exception in get groups from ldap", exc_info=True)
|
||||||
|
raise LDAPExcetpion(str(err))
|
||||||
|
|
||||||
def __isUserInList(self, list, username):
|
def __isUserInList(self, list, username):
|
||||||
help_list = []
|
help_list = []
|
||||||
|
@ -87,15 +109,18 @@ class LDAPController(metaclass=Singleton):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getAllUser(self):
|
def getAllUser(self):
|
||||||
|
debug.info("get all users from ldap")
|
||||||
retVal = []
|
retVal = []
|
||||||
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid=*)', SUBTREE, attributes=['uid', 'givenName', 'sn', 'mail'])
|
self.ldap.connection.search('ou=user,{}'.format(self.dn), '(uid=*)', SUBTREE, attributes=['uid', 'givenName', 'sn', 'mail'])
|
||||||
data = self.ldap.connection.response
|
data = self.ldap.connection.response
|
||||||
|
debug.debug("data is {{ {} }}".format(data))
|
||||||
for user in data:
|
for user in data:
|
||||||
if 'uid' in user['attributes']:
|
if 'uid' in user['attributes']:
|
||||||
username = user['attributes']['uid'][0]
|
username = user['attributes']['uid'][0]
|
||||||
firstname = user['attributes']['givenName'][0]
|
firstname = user['attributes']['givenName'][0]
|
||||||
lastname = user['attributes']['sn'][0]
|
lastname = user['attributes']['sn'][0]
|
||||||
retVal.append({'username': username, 'firstname': firstname, 'lastname': lastname})
|
retVal.append({'username': username, 'firstname': firstname, 'lastname': lastname})
|
||||||
|
debug.debug("users are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def searchUser(self, searchString):
|
def searchUser(self, searchString):
|
||||||
|
@ -139,10 +164,13 @@ class LDAPController(metaclass=Singleton):
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def modifyUser(self, user, conn, attributes):
|
def modifyUser(self, user, conn, attributes):
|
||||||
|
debug.info("modify ldap data from user {{ {} }} with attributes {{ {} }}".format(user, attributes))
|
||||||
try:
|
try:
|
||||||
if 'username' in attributes:
|
if 'username' in attributes:
|
||||||
|
debug.debug("change username")
|
||||||
conn.search('ou=user,{}'.format(self.dn), '(uid={})'.format(attributes['username']))
|
conn.search('ou=user,{}'.format(self.dn), '(uid={})'.format(attributes['username']))
|
||||||
if conn.entries:
|
if conn.entries:
|
||||||
|
debug.warning("username already exists", exc_info=True)
|
||||||
raise UsernameExistLDAP("Username already exists in LDAP")
|
raise UsernameExistLDAP("Username already exists in LDAP")
|
||||||
#create modifyer
|
#create modifyer
|
||||||
mody = {}
|
mody = {}
|
||||||
|
@ -157,9 +185,10 @@ class LDAPController(metaclass=Singleton):
|
||||||
if 'password' in attributes:
|
if 'password' in attributes:
|
||||||
salted_password = hashed(HASHED_SALTED_MD5, attributes['password'])
|
salted_password = hashed(HASHED_SALTED_MD5, attributes['password'])
|
||||||
mody['userPassword'] = [(MODIFY_REPLACE, [salted_password])]
|
mody['userPassword'] = [(MODIFY_REPLACE, [salted_password])]
|
||||||
|
debug.debug("modyfier are {{ {} }}".format(mody))
|
||||||
conn.modify(user.dn, mody)
|
conn.modify(user.dn, mody)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
traceback.print_exc()
|
debug.warning("exception in modify user data from ldap", exc_info=True)
|
||||||
raise LDAPExcetpion("Something went wrong in LDAP: {}".format(err))
|
raise LDAPExcetpion("Something went wrong in LDAP: {}".format(err))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,147 +24,147 @@ class UserController(metaclass=Singleton):
|
||||||
def getAllStatus(self):
|
def getAllStatus(self):
|
||||||
debug.info("get all status for user")
|
debug.info("get all status for user")
|
||||||
retVal = db.getAllStatus()
|
retVal = db.getAllStatus()
|
||||||
debug.debug("status are {{}}".format(retVal))
|
debug.debug("status are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getStatus(self, name):
|
def getStatus(self, name):
|
||||||
debug.info("get status of user {{}}".format(name))
|
debug.info("get status of user {{ {} }}".format(name))
|
||||||
retVal = db.getStatus(name)
|
retVal = db.getStatus(name)
|
||||||
debug.debug("status of user {{}} is {{}}".format(name, retVal))
|
debug.debug("status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def setStatus(self, name):
|
def setStatus(self, name):
|
||||||
debug.info("set status of user {{}}".format(name))
|
debug.info("set status of user {{ {} }}".format(name))
|
||||||
retVal = db.setStatus(name)
|
retVal = db.setStatus(name)
|
||||||
debug.debug("settet status of user {{}} is {{}}".format(name, retVal))
|
debug.debug("settet status of user {{ {} }} is {{ {} }}".format(name, retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def deleteStatus(self, status):
|
def deleteStatus(self, status):
|
||||||
debug.info("delete status {{}}".format(status))
|
debug.info("delete status {{ {} }}".format(status))
|
||||||
db.deleteStatus(status)
|
db.deleteStatus(status)
|
||||||
|
|
||||||
def updateStatus(self, status):
|
def updateStatus(self, status):
|
||||||
debug.info("update status {{}}".format(status))
|
debug.info("update status {{ {} }}".format(status))
|
||||||
retVal = db.updateStatus(status)
|
retVal = db.updateStatus(status)
|
||||||
debug.debug("updated status is {{}}".format(retVal))
|
debug.debug("updated status is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def updateStatusOfUser(self, username, status):
|
def updateStatusOfUser(self, username, status):
|
||||||
debug.info("update status {{}} of user {{}}".format(status, username))
|
debug.info("update status {{ {} }} of user {{ {} }}".format(status, username))
|
||||||
retVal = db.updateStatusOfUser(username, status)
|
retVal = db.updateStatusOfUser(username, status)
|
||||||
debug.debug("updatet status of user {{}} is {{}}".format(username, retVal))
|
debug.debug("updatet status of user {{ {} }} is {{ {} }}".format(username, retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def updateVotingOfUser(self, username, voting):
|
def updateVotingOfUser(self, username, voting):
|
||||||
debug.info("update voting {{}} of user {{}}".format(voting, username))
|
debug.info("update voting {{ {} }} of user {{ {} }}".format(voting, username))
|
||||||
retVal = db.updateVotingOfUser(username, voting)
|
retVal = db.updateVotingOfUser(username, voting)
|
||||||
debug.debug("updatet voting of user {{}} is {{}}".format(username, retVal))
|
debug.debug("updatet voting of user {{ {} }} is {{ {} }}".format(username, retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def deleteDrinkType(self, type):
|
def deleteDrinkType(self, type):
|
||||||
debug.info("delete drink type {{}}".format(type))
|
debug.info("delete drink type {{ {} }}".format(type))
|
||||||
db.deleteDrinkType(type)
|
db.deleteDrinkType(type)
|
||||||
|
|
||||||
def updateDrinkType(self, type):
|
def updateDrinkType(self, type):
|
||||||
debug.info("update drink type {{}}".format(type))
|
debug.info("update drink type {{ {} }}".format(type))
|
||||||
retVal = db.updateDrinkType(type)
|
retVal = db.updateDrinkType(type)
|
||||||
debug.debug("updated drink type is {{}}".format(retVal))
|
debug.debug("updated drink type is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def setDrinkType(self, type):
|
def setDrinkType(self, type):
|
||||||
debug.info("set drink type {{}}".format(type))
|
debug.info("set drink type {{ {} }}".format(type))
|
||||||
retVal = db.setDrinkType(type)
|
retVal = db.setDrinkType(type)
|
||||||
debug.debug("seted drink type is {{}}".format(retVal))
|
debug.debug("seted drink type is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def deletDrinkPrice(self, drink):
|
def deletDrinkPrice(self, drink):
|
||||||
debug.info("delete drink {{}}".format(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))
|
debug.info("set drink {{ {} }}".format(drink))
|
||||||
retVal = db.setDrinkPrice(drink)
|
retVal = db.setDrinkPrice(drink)
|
||||||
debug.debug("seted drink is {{}}".format(retVal))
|
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))
|
debug.info("update drink {{ {} }}".format(drink))
|
||||||
retVal = db.updateDrinkPrice(drink)
|
retVal = db.updateDrinkPrice(drink)
|
||||||
debug.debug("updated drink is {{}}".format(retVal))
|
debug.debug("updated drink is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getAllDrinkTypes(self):
|
def getAllDrinkTypes(self):
|
||||||
debug.info("get all drink types")
|
debug.info("get all drink types")
|
||||||
retVal = db.getAllDrinkTypes()
|
retVal = db.getAllDrinkTypes()
|
||||||
debug.debug("all drink types are {{}}".format(retVal))
|
debug.debug("all drink types are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getPricelist(self):
|
def getPricelist(self):
|
||||||
debug.info("get all drinks")
|
debug.info("get all drinks")
|
||||||
list = db.getPriceList()
|
list = db.getPriceList()
|
||||||
debug.debug("all drinks are {{}}".format(list))
|
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))
|
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.debug("transact job is {{ {} }}".format(jobtransact))
|
||||||
debug.info("send mail with transact job to user")
|
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):
|
||||||
debug.info("get transact job from user {{}} on {{}}".format(user, date))
|
debug.info("get transact job from user {{ {} }} on {{ {} }}".format(user, date))
|
||||||
retVal = db.getTransactJobFromUser(user, date.date())
|
retVal = db.getTransactJobFromUser(user, date.date())
|
||||||
debug.debug("transact job from user {{}} is {{}}".format(user, retVal))
|
debug.debug("transact job from user {{ {} }} is {{ {} }}".format(user, retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getAllTransactJobFromUser(self, user, date):
|
def getAllTransactJobFromUser(self, user, date):
|
||||||
debug.info("get all transact job from user {{}} start on {{}}".format(user, date))
|
debug.info("get all transact job from user {{ {} }} start on {{ {} }}".format(user, date))
|
||||||
retVal = db.getAllTransactJobFromUser(user, date,date())
|
retVal = db.getAllTransactJobFromUser(user, date.date())
|
||||||
debug.debug("all transact job are {{}}".format(retVal))
|
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getAllTransactJobToUser(self, user, date):
|
def getAllTransactJobToUser(self, user, date):
|
||||||
debug.info("get all transact job from to_user {{}} start on {{}}".format(user, date))
|
debug.info("get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date))
|
||||||
retVal = db.getAllTransactJobToUser(user, date.date())
|
retVal = db.getAllTransactJobToUser(user, date.date())
|
||||||
debug.debug("all transact job are {{}}".format(retVal))
|
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getTransactJob(self, from_user, to_user, date):
|
def getTransactJob(self, from_user, to_user, date):
|
||||||
debug.info("get transact job from user {{}} to user {{}} on {{}}".format(from_user, to_user, 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())
|
retVal = db.getTransactJob(from_user, to_user, date.date())
|
||||||
debug.debug("transact job is {{}}".format(retVal))
|
debug.debug("transact job is {{ {} }}".format(retVal))
|
||||||
return 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))
|
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))
|
debug.debug("transact job is {{ {} }}".format(transactJob))
|
||||||
if transactJob['answerd']:
|
if transactJob['answerd']:
|
||||||
debug.warning("transactjob {{}} can not delete because is 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))
|
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))
|
debug.debug("transactjob is {{ {} }}".format(transactJob))
|
||||||
if answer:
|
if answer:
|
||||||
debug.info("add worker on date {{}}".format(date))
|
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):
|
||||||
debug.info("set day locked on {{}} with state {{}}".format(date, locked))
|
debug.info("set day locked on {{ {} }} with state {{ {} }}".format(date, locked))
|
||||||
retVal = db.setLockedDay(date.date(), locked, hard)
|
retVal = db.setLockedDay(date.date(), locked, hard)
|
||||||
debug.debug("seted day locked is {{}}".format(retVal))
|
debug.debug("seted day locked is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getLockedDay(self, date):
|
def getLockedDay(self, date):
|
||||||
debug.info("get locked day on {{}}".format(date))
|
debug.info("get locked day on {{ {} }}".format(date))
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
debug.debug("now is {{}}".format(now))
|
debug.debug("now is {{ {} }}".format(now))
|
||||||
oldMonth = False
|
oldMonth = False
|
||||||
debug.debug("check if date old month or current month")
|
debug.debug("check if date old month or current month")
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
|
@ -172,7 +172,7 @@ class UserController(metaclass=Singleton):
|
||||||
if now.day < i:
|
if now.day < i:
|
||||||
oldMonth = True
|
oldMonth = True
|
||||||
break
|
break
|
||||||
debug.debug("oldMonth is {{}}".format(oldMonth))
|
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]
|
||||||
|
@ -182,36 +182,36 @@ class UserController(metaclass=Singleton):
|
||||||
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("start day of month is {{ {} }}".format(startDay))
|
||||||
debug.debug("check if date should be locked")
|
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)))
|
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)))
|
debug.debug("lock day {{ {} }}".format(datetime(lockedYear, lockedMonth, i)))
|
||||||
self.setLockedDay(nextMonth, True)
|
self.setLockedDay(nextMonth, True)
|
||||||
retVal = db.getLockedDay(date.date())
|
retVal = db.getLockedDay(date.date())
|
||||||
debug.debug("locked day is {{}}".format(retVal))
|
debug.debug("locked day is {{ {} }}".format(retVal))
|
||||||
return
|
return retVal
|
||||||
|
|
||||||
def getWorker(self, date, username=None):
|
def getWorker(self, date, username=None):
|
||||||
debug.info("get worker on {{}}".format(username, date))
|
debug.info("get worker on {{ {} }}".format(username, date))
|
||||||
if (username):
|
if (username):
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
debug.debug("user is {{}}".format(user))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
retVal = [db.getWorker(user, date)]
|
retVal = [db.getWorker(user, date)]
|
||||||
debug.debug("worker is {{}}".format(retVal))
|
debug.debug("worker is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
retVal = db.getWorkers(date)
|
retVal = db.getWorkers(date)
|
||||||
debug.debug("workers are {{}}".format(retVal))
|
debug.debug("workers are {{ {} }}".format(retVal))
|
||||||
return 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))
|
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")
|
debug.debug("this is a user execution, check if day is locked")
|
||||||
lockedDay = self.getLockedDay(date)
|
lockedDay = self.getLockedDay(date)
|
||||||
|
@ -220,19 +220,19 @@ class UserController(metaclass=Singleton):
|
||||||
debug.debug("day is lockey. user cant get job")
|
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("user is {{ {} }}".format(user))
|
||||||
debug.debug("check if user has job on date")
|
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")
|
debug.debug("set job to user")
|
||||||
db.setWorker(user, date)
|
db.setWorker(user, date)
|
||||||
retVal = self.getWorker(date, username=username)
|
retVal = self.getWorker(date, username=username)
|
||||||
debug.debug("worker on date is {{}}".format(retVal))
|
debug.debug("worker on date is {{ {} }}".format(retVal))
|
||||||
return 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))
|
debug.info("delete worker {{ {} }} on date {{ {} }}".format(username, date))
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
debug.debug("user is {{}}".format(user))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
if userExc:
|
if userExc:
|
||||||
debug.debug("is user execution, check if day locked")
|
debug.debug("is user execution, check if day locked")
|
||||||
lockedDay = self.getLockedDay(date)
|
lockedDay = self.getLockedDay(date)
|
||||||
|
@ -240,7 +240,7 @@ class UserController(metaclass=Singleton):
|
||||||
if lockedDay['locked']:
|
if lockedDay['locked']:
|
||||||
debug.debug("day is locked, check if accepted transact job exists")
|
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))
|
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']:
|
||||||
|
@ -253,98 +253,98 @@ class UserController(metaclass=Singleton):
|
||||||
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))
|
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))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
user.updateData({'locked': locked})
|
user.updateData({'locked': locked})
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
retVal = self.getUser(username)
|
retVal = self.getUser(username)
|
||||||
debug.debug("locked user is {{}}".format(retVal))
|
debug.debug("locked user is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def updateConfig(self, username, data):
|
def updateConfig(self, username, data):
|
||||||
debug.info("update config of user {{}} with config {{}}".format(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))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
user.updateData(data)
|
user.updateData(data)
|
||||||
db.updateUser(user)
|
db.updateUser(user)
|
||||||
retVal = self.getUser(username)
|
retVal = self.getUser(username)
|
||||||
debug.debug("updated config of user is {{}}".format(retVal))
|
debug.debug("updated config of user is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def __updateDataFromLDAP(self, user):
|
def __updateDataFromLDAP(self, user):
|
||||||
debug.info("update data from ldap for user {{}}".format(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))
|
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))
|
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))
|
debug.info("start autolock of user {{ {} }}".format(user))
|
||||||
if user.autoLock:
|
if user.autoLock:
|
||||||
debug.debug("autolock is active")
|
debug.debug("autolock is active")
|
||||||
credit = user.getGeruecht(year=datetime.now().year).getSchulden()
|
credit = user.getGeruecht(year=datetime.now().year).getSchulden()
|
||||||
limit = -1*user.limit
|
limit = -1*user.limit
|
||||||
if credit <= limit:
|
if credit <= limit:
|
||||||
debug.debug("credit {{}} is more than user limit {{}}".format(credit, limit))
|
debug.debug("credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit))
|
||||||
debug.debug("lock user")
|
debug.debug("lock user")
|
||||||
user.updateData({'locked': True})
|
user.updateData({'locked': True})
|
||||||
debug.debug("send mail to user")
|
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("cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit))
|
||||||
debug.debug("unlock user")
|
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))
|
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))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
if user.uid == 'extern':
|
if user.uid == 'extern':
|
||||||
debug.debug("user is extern user, so exit add amount")
|
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))
|
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))
|
debug.debug("creditList is {{ {} }}".format(creditLists))
|
||||||
for creditList in creditLists:
|
for creditList in creditLists:
|
||||||
debug.debug("update creditlist {{}}".format(creditList))
|
debug.debug("update creditlist {{ {} }}".format(creditList))
|
||||||
db.updateCreditList(creditList)
|
db.updateCreditList(creditList)
|
||||||
debug.debug("do autolock")
|
debug.debug("do autolock")
|
||||||
self.autoLock(user)
|
self.autoLock(user)
|
||||||
retVal = user.getGeruecht(year)
|
retVal = user.getGeruecht(year)
|
||||||
debug.debug("updated creditlists is {{}}".format(retVal))
|
debug.debug("updated creditlists is {{ {} }}".format(retVal))
|
||||||
return 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))
|
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))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
if user.uid == 'extern':
|
if user.uid == 'extern':
|
||||||
debug.debug("user is extern user, so exit add credit")
|
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))
|
debug.debug("creditlists are {{ {} }}".format(creditLists))
|
||||||
for creditList in creditLists:
|
for creditList in creditLists:
|
||||||
debug.debug("update creditlist {{}}".format(creditList))
|
debug.debug("update creditlist {{ {} }}".format(creditList))
|
||||||
db.updateCreditList(creditList)
|
db.updateCreditList(creditList)
|
||||||
debug.debug("do autolock")
|
debug.debug("do autolock")
|
||||||
self.autoLock(user)
|
self.autoLock(user)
|
||||||
retVal = user.getGeruecht(year)
|
retVal = user.getGeruecht(year)
|
||||||
debug.debug("updated creditlists are {{}}".format(retVal))
|
debug.debug("updated creditlists are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def getAllUsersfromDB(self):
|
def getAllUsersfromDB(self):
|
||||||
debug.info("get all users from database")
|
debug.info("get all users from database")
|
||||||
users = db.getAllUser()
|
users = db.getAllUser()
|
||||||
debug.debug("users are {{}}".format(users))
|
debug.debug("users are {{ {} }}".format(users))
|
||||||
for user in users:
|
for user in users:
|
||||||
try:
|
try:
|
||||||
debug.debug("update data from ldap")
|
debug.debug("update data from ldap")
|
||||||
|
@ -354,11 +354,11 @@ class UserController(metaclass=Singleton):
|
||||||
debug.debug("update creditlists")
|
debug.debug("update creditlists")
|
||||||
self.__updateGeruechte(user)
|
self.__updateGeruechte(user)
|
||||||
retVal = db.getAllUser(extern=True)
|
retVal = db.getAllUser(extern=True)
|
||||||
debug.debug("all users are {{}}".format(retVal))
|
debug.debug("all users are {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def checkBarUser(self, user):
|
def checkBarUser(self, user):
|
||||||
debug.info("check if user {{}} is baruser")
|
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)
|
||||||
|
@ -366,22 +366,22 @@ 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))
|
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))
|
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))
|
debug.info("get user {{ {} }}".format(username))
|
||||||
user = db.getUser(username)
|
user = db.getUser(username)
|
||||||
debug.debug("user is {{}}".format(user))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
groups = ldap.getGroup(username)
|
groups = ldap.getGroup(username)
|
||||||
debug.debug("groups are {{}}".format(groups))
|
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))
|
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:
|
||||||
|
@ -394,41 +394,41 @@ class UserController(metaclass=Singleton):
|
||||||
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))
|
debug.debug("user is {{ {} }}".format(user))
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def __updateGeruechte(self, user):
|
def __updateGeruechte(self, user):
|
||||||
debug.debug("update creditlists")
|
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))
|
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))
|
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))
|
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)
|
||||||
retVal = emailController.sendMail(user)
|
retVal = emailController.sendMail(user)
|
||||||
debug.debug("send mail is {{}}".format(retVal))
|
debug.debug("send mail is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def sendAllMail(self):
|
def sendAllMail(self):
|
||||||
debug.info("send mail to all user")
|
debug.info("send mail to all user")
|
||||||
retVal = []
|
retVal = []
|
||||||
users = db.getAllUser()
|
users = db.getAllUser()
|
||||||
debug.debug("users are {{}}".format(users))
|
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))
|
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))
|
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")
|
debug.debug("change username, so change first in database")
|
||||||
|
@ -436,11 +436,11 @@ class UserController(metaclass=Singleton):
|
||||||
ldap.modifyUser(user, ldap_conn, attributes)
|
ldap.modifyUser(user, ldap_conn, attributes)
|
||||||
if 'username' in attributes:
|
if 'username' in attributes:
|
||||||
retVal = self.getUser(attributes['username'])
|
retVal = self.getUser(attributes['username'])
|
||||||
debug.debug("user is {{}}".format(retVal))
|
debug.debug("user is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
else:
|
else:
|
||||||
retVal = self.getUser(user.uid)
|
retVal = self.getUser(user.uid)
|
||||||
debug.debug("user is {{}}".format(retVal))
|
debug.debug("user is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
except UsernameExistLDAP as err:
|
except UsernameExistLDAP as err:
|
||||||
debug.debug("username exists on ldap, rechange username on database", exc_info=True)
|
debug.debug("username exists on ldap, rechange username on database", exc_info=True)
|
||||||
|
@ -454,10 +454,10 @@ 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))
|
debug.info("login user {{ {} }}".format(username))
|
||||||
try:
|
try:
|
||||||
user = self.getUser(username)
|
user = self.getUser(username)
|
||||||
debug.debug("user is {{}}".format(user))
|
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)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.logger import getDebugLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
class AccessToken():
|
class AccessToken():
|
||||||
""" Model for an AccessToken
|
""" Model for an AccessToken
|
||||||
|
@ -27,19 +27,20 @@ class AccessToken():
|
||||||
token: Is a String to verify later
|
token: Is a String to verify later
|
||||||
timestamp: Default current time, but can set to an other datetime-Object.
|
timestamp: Default current time, but can set to an other datetime-Object.
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Initialize AccessToken")
|
debug.debug("init accesstoken")
|
||||||
self.user = user
|
self.user = user
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.lifetime = lifetime
|
self.lifetime = lifetime
|
||||||
self.token = token
|
self.token = token
|
||||||
self.ldap_conn = ldap_conn
|
self.ldap_conn = ldap_conn
|
||||||
|
debug.debug("accesstoken is {{ {} }}".format(self))
|
||||||
|
|
||||||
def updateTimestamp(self):
|
def updateTimestamp(self):
|
||||||
""" Update the Timestamp
|
""" Update the Timestamp
|
||||||
|
|
||||||
Update the Timestamp to the current Time.
|
Update the Timestamp to the current Time.
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Update Timestamp")
|
debug.debug("update timestamp from accesstoken {{ {} }}".format(self))
|
||||||
self.timestamp = datetime.now()
|
self.timestamp = datetime.now()
|
||||||
|
|
||||||
def __eq__(self, token):
|
def __eq__(self, token):
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geruecht.logger import getDebugLogger
|
from geruecht.logger import getDebugLogger
|
||||||
|
|
||||||
LOGGER = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
def create_empty_data():
|
def create_empty_data():
|
||||||
empty_data = {'id': 0,
|
empty_data = {'id': 0,
|
||||||
'jan_guthaben': 0,
|
'jan_guthaben': 0,
|
||||||
|
@ -46,7 +47,7 @@ class CreditList():
|
||||||
user_id: id from the User.
|
user_id: id from the User.
|
||||||
"""
|
"""
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
LOGGER.debug("Initialize Geruecht")
|
debug.debug("init creditlist")
|
||||||
self.id = int(data['id'])
|
self.id = int(data['id'])
|
||||||
|
|
||||||
self.jan_guthaben = int(data['jan_guthaben'])
|
self.jan_guthaben = int(data['jan_guthaben'])
|
||||||
|
@ -91,6 +92,8 @@ class CreditList():
|
||||||
|
|
||||||
self.user_id = int(data['user_id'])
|
self.user_id = int(data['user_id'])
|
||||||
|
|
||||||
|
debug.debug("credit list is {{ {} }}".format(self))
|
||||||
|
|
||||||
def getSchulden(self):
|
def getSchulden(self):
|
||||||
""" Get Schulden
|
""" Get Schulden
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ class CreditList():
|
||||||
Returns:
|
Returns:
|
||||||
double of the calculated amount
|
double of the calculated amount
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Calculate amount")
|
debug.info("calculate amount")
|
||||||
jan = self.jan_guthaben - self.jan_schulden
|
jan = self.jan_guthaben - self.jan_schulden
|
||||||
feb = self.feb_guthaben - self.feb_schulden
|
feb = self.feb_guthaben - self.feb_schulden
|
||||||
maer = self.maer_guthaben - self.maer_schulden
|
maer = self.maer_guthaben - self.maer_schulden
|
||||||
|
@ -119,7 +122,7 @@ class CreditList():
|
||||||
dez = self.dez_guthaben - self.dez_schulden
|
dez = self.dez_guthaben - self.dez_schulden
|
||||||
|
|
||||||
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
|
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
|
||||||
LOGGER.debug("Calculated amount is {}".format(sum))
|
debug.debug("amount is {{ {} }}".format(sum))
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
def getMonth(self, month=datetime.now().month):
|
def getMonth(self, month=datetime.now().month):
|
||||||
|
@ -134,7 +137,7 @@ class CreditList():
|
||||||
Returns:
|
Returns:
|
||||||
double (credit, amount)
|
double (credit, amount)
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Get Credit and Amount from Month {}".format(month))
|
debug.info("get credit and amount from month {{ {} }}".format(month))
|
||||||
retValue = None
|
retValue = None
|
||||||
|
|
||||||
if month == 1:
|
if month == 1:
|
||||||
|
@ -161,7 +164,7 @@ class CreditList():
|
||||||
retValue = (self.nov_guthaben, self.nov_schulden)
|
retValue = (self.nov_guthaben, self.nov_schulden)
|
||||||
elif month == 12:
|
elif month == 12:
|
||||||
retValue = (self.dez_guthaben, self.dez_schulden)
|
retValue = (self.dez_guthaben, self.dez_schulden)
|
||||||
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
debug.debug("credit and amount is {{ {} }}".format(retValue))
|
||||||
return retValue
|
return retValue
|
||||||
|
|
||||||
def addAmount(self, amount, month=datetime.now().month):
|
def addAmount(self, amount, month=datetime.now().month):
|
||||||
|
@ -177,7 +180,7 @@ class CreditList():
|
||||||
Returns:
|
Returns:
|
||||||
double (credit, amount)
|
double (credit, amount)
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Add Amount in Month {}".format(month))
|
debug.info("add amount in month {{ {} }}".format(month))
|
||||||
if month == 1:
|
if month == 1:
|
||||||
self.jan_schulden += amount
|
self.jan_schulden += amount
|
||||||
retValue = (self.jan_guthaben, self.jan_schulden)
|
retValue = (self.jan_guthaben, self.jan_schulden)
|
||||||
|
@ -214,7 +217,7 @@ class CreditList():
|
||||||
elif month == 12:
|
elif month == 12:
|
||||||
self.dez_schulden += amount
|
self.dez_schulden += amount
|
||||||
retValue = (self.dez_guthaben, self.dez_schulden)
|
retValue = (self.dez_guthaben, self.dez_schulden)
|
||||||
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
debug.debug("credit and amount is {{ {} }}".format(retValue))
|
||||||
return retValue
|
return retValue
|
||||||
|
|
||||||
def addCredit(self, credit, month=datetime.now().month):
|
def addCredit(self, credit, month=datetime.now().month):
|
||||||
|
@ -230,7 +233,7 @@ class CreditList():
|
||||||
Returns:
|
Returns:
|
||||||
double (credit, amount)
|
double (credit, amount)
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Add Credit in Month {}".format(month))
|
debug.info("add credit in month {{ {} }}".format(month))
|
||||||
if month == 1:
|
if month == 1:
|
||||||
self.jan_guthaben += credit
|
self.jan_guthaben += credit
|
||||||
retValue = (self.jan_guthaben, self.jan_schulden)
|
retValue = (self.jan_guthaben, self.jan_schulden)
|
||||||
|
@ -267,7 +270,7 @@ class CreditList():
|
||||||
elif month == 12:
|
elif month == 12:
|
||||||
self.dez_guthaben += credit
|
self.dez_guthaben += credit
|
||||||
retValue = (self.dez_guthaben, self.dez_schulden)
|
retValue = (self.dez_guthaben, self.dez_schulden)
|
||||||
LOGGER.debug("Credit and Amount is {}".format(retValue))
|
debug.debug("credit and amount is {{ {} }}".format(retValue))
|
||||||
return retValue
|
return retValue
|
||||||
|
|
||||||
def toJSON(self):
|
def toJSON(self):
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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 = getDebugLogger()
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
|
||||||
class User():
|
class User():
|
||||||
|
@ -20,6 +20,7 @@ class User():
|
||||||
password: salted hashed password for the User.
|
password: salted hashed password for the User.
|
||||||
"""
|
"""
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
debug.info("init user")
|
||||||
if 'id' in data:
|
if 'id' in data:
|
||||||
self.id = int(data['id'])
|
self.id = int(data['id'])
|
||||||
self.uid = data['uid']
|
self.uid = data['uid']
|
||||||
|
@ -58,8 +59,10 @@ class User():
|
||||||
if 'creditLists' in data:
|
if 'creditLists' in data:
|
||||||
self.geruechte = data['creditLists']
|
self.geruechte = data['creditLists']
|
||||||
self.password = ''
|
self.password = ''
|
||||||
|
debug.debug("user is {{ {} }}".format(self))
|
||||||
|
|
||||||
def updateData(self, data):
|
def updateData(self, data):
|
||||||
|
debug.info("update data of user")
|
||||||
if 'dn' in data:
|
if 'dn' in data:
|
||||||
self.dn = data['dn']
|
self.dn = data['dn']
|
||||||
if 'firstname' in data:
|
if 'firstname' in data:
|
||||||
|
@ -98,14 +101,14 @@ class User():
|
||||||
Returns:
|
Returns:
|
||||||
the created geruecht
|
the created geruecht
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Create Geruecht for user {} in year {}".format(self, year))
|
debug.info("create creditlist for user {{ {} }} in year {{ {} }}".format(self, year))
|
||||||
data = create_empty_data()
|
data = create_empty_data()
|
||||||
data['user_id'] = self.id
|
data['user_id'] = self.id
|
||||||
data['last_schulden'] = amount
|
data['last_schulden'] = amount
|
||||||
data['year_date'] = year
|
data['year_date'] = year
|
||||||
credit = CreditList(data)
|
credit = CreditList(data)
|
||||||
self.geruechte.append(credit)
|
self.geruechte.append(credit)
|
||||||
LOGGER.debug("Created Geruecht {}".format(credit))
|
debug.debug("creditlist is {{ {} }}".format(credit))
|
||||||
return credit
|
return credit
|
||||||
|
|
||||||
def getGeruecht(self, year=datetime.now().year):
|
def getGeruecht(self, year=datetime.now().year):
|
||||||
|
@ -120,13 +123,12 @@ class User():
|
||||||
Returns:
|
Returns:
|
||||||
the geruecht of the year
|
the geruecht of the year
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Iterate through Geruechte of User {}".format(self))
|
debug.info("get creditlist from user on year {{ {} }}".format(year))
|
||||||
for geruecht in self.geruechte:
|
for geruecht in self.geruechte:
|
||||||
LOGGER.debug("Check if Geruecht {} has year {}".format(geruecht, year))
|
|
||||||
if geruecht.year == year:
|
if geruecht.year == year:
|
||||||
LOGGER.debug("Find Geruecht {} for User {}".format(geruecht, self))
|
debug.debug("creditlist is {{ {} }} for user {{ {} }}".format(geruecht, self))
|
||||||
return geruecht
|
return geruecht
|
||||||
LOGGER.debug("No Geruecht found for User {}. Will create one".format(self))
|
debug.debug("no creditlist found for user {{ {} }}".format(self))
|
||||||
geruecht = self.createGeruecht(year=year)
|
geruecht = self.createGeruecht(year=year)
|
||||||
|
|
||||||
return self.getGeruecht(year=year)
|
return self.getGeruecht(year=year)
|
||||||
|
@ -145,7 +147,7 @@ class User():
|
||||||
Returns:
|
Returns:
|
||||||
double (credit, amount)
|
double (credit, amount)
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Add amount to User {} in year {} and month {}".format(self, year, month))
|
debug.info("add amount to user {{ {} }} in year {{ {} }} and month {{ {} }}".format(self, year, month))
|
||||||
geruecht = self.getGeruecht(year=year)
|
geruecht = self.getGeruecht(year=year)
|
||||||
retVal = geruecht.addAmount(amount, month=month)
|
retVal = geruecht.addAmount(amount, month=month)
|
||||||
|
|
||||||
|
@ -165,7 +167,7 @@ class User():
|
||||||
Returns:
|
Returns:
|
||||||
double (credit, amount)
|
double (credit, amount)
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Add credit to User {} in year {} and month {}".format(self, year, month))
|
debug.info("add credit to user {{ {} }} in year {{ {} }} and month {{ {} }}".format(self, year, month))
|
||||||
geruecht = self.getGeruecht(year=year)
|
geruecht = self.getGeruecht(year=year)
|
||||||
retVal = geruecht.addCredit(credit, month=month)
|
retVal = geruecht.addCredit(credit, month=month)
|
||||||
|
|
||||||
|
@ -176,7 +178,7 @@ class User():
|
||||||
|
|
||||||
This function iterate through the geruechte, which sorted by year and update the last_schulden of the geruecht.
|
This function iterate through the geruechte, which sorted by year and update the last_schulden of the geruecht.
|
||||||
"""
|
"""
|
||||||
LOGGER.debug("Update all Geruechte ")
|
debug.info("update all creditlists ")
|
||||||
self.geruechte.sort(key=self.sortYear)
|
self.geruechte.sort(key=self.sortYear)
|
||||||
|
|
||||||
for index, geruecht in enumerate(self.geruechte):
|
for index, geruecht in enumerate(self.geruechte):
|
||||||
|
|
|
@ -102,7 +102,7 @@ def _addUser(**kwargs):
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
retVal = userController.addWorker(user['username'], date)
|
retVal = userController.addWorker(user['username'], date)
|
||||||
debug.debug("retrun {{ {} }}".format(retVal))
|
debug.debug("retrun {{ {} }}".format(retVal))
|
||||||
userl = userController.getUser(user)
|
userl = userController.getUser(user['username'])
|
||||||
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
|
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
|
||||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
|
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
@ -164,7 +164,7 @@ def _deletUser(**kwargs):
|
||||||
date = datetime(year, month, day, 12)
|
date = datetime(year, month, day, 12)
|
||||||
userController.deleteWorker(user['username'], date)
|
userController.deleteWorker(user['username'], date)
|
||||||
debug.debug("return ok")
|
debug.debug("return ok")
|
||||||
user = userController.getUser(user)
|
user = userController.getUser(user['username'])
|
||||||
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
|
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
|
||||||
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
|
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
|
||||||
return jsonify({"ok": "ok"})
|
return jsonify({"ok": "ok"})
|
||||||
|
|
Loading…
Reference in New Issue