add new route for user, so he can see, when he has jobs

This commit is contained in:
Tim Gröger 2020-01-27 20:16:04 +01:00
parent ca1f2259c5
commit 3dca45f12e
3 changed files with 34 additions and 6 deletions

View File

@ -56,10 +56,12 @@ class DatabaseController(metaclass=Singleton):
def _convertGroupToString(self, groups):
retVal = ''
for group in groups:
if len(retVal) != 0:
retVal += ','
retVal += group
print('groups: {}'.format(groups))
if groups:
for group in groups:
if len(retVal) != 0:
retVal += ','
retVal += group
return retVal
@ -73,6 +75,7 @@ class DatabaseController(metaclass=Singleton):
def updateUser(self, user):
cursor = self.db.connection.cursor()
print('uid: {}; group: {}'.format(user.uid, user.group))
groups = self._convertGroupToString(user.group)
sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format(
user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid)

View File

@ -69,7 +69,7 @@ class LDAPController(metaclass=Singleton):
retVal.append(BAR)
return retVal
except Exception as err:
traceback.print_exception(err)
traceback.print_exc()
def __isUserInList(self, list, username):
help_list = []

View File

@ -4,6 +4,7 @@ import geruecht.controller.userController as uc
from geruecht.model import USER
from datetime import datetime
import time
import traceback
user = Blueprint("user", __name__)
@ -48,4 +49,28 @@ def _saveConfig(**kwargs):
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
return jsonify(retVal)
except Exception as err:
return jsonify({"error": err}), 409
return jsonify({"error": err}), 409
@user.route("/user/job", methods=['POST'])
@login_required(groups=[USER])
def _getJob(**kwargs):
try:
if 'accToken' in kwargs:
accToken = kwargs['accToken']
data = request.get_json()
date = datetime.utcfromtimestamp(int(data['date']))
test = userController.getWorker(date, username=accToken.user.uid)
if test == [None]:
job = False
else:
job = True
if job:
workers = userController.getWorker(date)
for worker in workers:
if worker['user']['uid'] == accToken.user.uid:
workers.remove(worker)
return jsonify({'job': job, 'workers': workers})
return jsonify({'job': job})
except Exception as err:
traceback.print_exc()
return jsonify({"error": str(err)}), 409