finished ##185

This commit is contained in:
Tim Gröger 2020-02-23 22:31:22 +01:00
parent 65d09225b1
commit 12ca655d02
4 changed files with 71 additions and 7 deletions

View File

@ -6,7 +6,7 @@ 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 from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked
db = dc.DatabaseController() db = dc.DatabaseController()
ldap = lc.LDAPController(ldapConfig['dn']) ldap = lc.LDAPController(ldapConfig['dn'])
@ -31,7 +31,12 @@ class UserController(metaclass=Singleton):
return [db.getWorker(user, date)] return [db.getWorker(user, date)]
return db.getWorkers(date) return db.getWorkers(date)
def addWorker(self, username, date): def addWorker(self, username, date, userExc=False):
if (userExc):
lockedDay = self.getLockedDay(date)
if lockedDay:
if lockedDay['locked']:
raise DayLocked("Day is locked. You can't get the Job")
user = self.getUser(username) user = self.getUser(username)
if (not db.getWorker(user, date)): if (not db.getWorker(user, date)):
db.setWorker(user, date) db.setWorker(user, date)

View File

@ -7,4 +7,6 @@ class UsernameExistLDAP(Exception):
class DatabaseExecption(Exception): class DatabaseExecption(Exception):
pass pass
class LDAPExcetpion(Exception): class LDAPExcetpion(Exception):
pass
class DayLocked(Exception):
pass pass

View File

@ -3,8 +3,7 @@ from geruecht.decorator import login_required
import geruecht.controller.userController as uc import geruecht.controller.userController as uc
from geruecht.model import USER from geruecht.model import USER
from datetime import datetime from datetime import datetime
import time from geruecht.exceptions import DayLocked
import traceback
user = Blueprint("user", __name__) user = Blueprint("user", __name__)
@ -59,9 +58,48 @@ def _getUser(**kwargs):
month = data['month'] month = data['month']
year = data['year'] year = data['year']
date = datetime(year, month, day, 12) date = datetime(year, month, day, 12)
lockedDay = userController.getLockedDay(date)
if not lockedDay:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': False
}
else:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': lockedDay['locked']
}
retVal = { retVal = {
'worker': userController.getWorker(date), 'worker': userController.getWorker(date),
'day': userController.getLockedDay(date) 'day': lockedDay
} }
print(retVal) print(retVal)
return jsonify(retVal) return jsonify(retVal)
@user.route("/user/addJob", methods=['POST'])
@login_required(groups=[USER])
def _addUser(**kwargs):
try:
if 'accToken' in kwargs:
accToken = kwargs['accToken']
user = accToken.user
data = request.get_json()
day = data['day']
month = data['month']
year = data['year']
date = datetime(year,month,day,12)
retVal = userController.addWorker(user.uid, date, userExc=True)
print(retVal)
return jsonify(retVal)
except DayLocked as err:
return jsonify({'error': err}), 403
except Exception as err:
return jsonify({'error': err}), 409

View File

@ -34,9 +34,28 @@ def _getUser(**kwargs):
month = data['month'] month = data['month']
year = data['year'] year = data['year']
date = datetime(year, month, day, 12) date = datetime(year, month, day, 12)
lockedDay = userController.getLockedDay(date)
if not lockedDay:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': False
}
else:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': lockedDay['locked']
}
retVal = { retVal = {
'worker': userController.getWorker(date), 'worker': userController.getWorker(date),
'day': userController.getLockedDay(date) 'day': lockedDay
} }
print(retVal) print(retVal)
return jsonify(retVal) return jsonify(retVal)