finished ##193

route for user to delete job, but only if day not locked
fixed a bug, that the month start on the first wednesday in month and ended in first tuesday in nextmonth
This commit is contained in:
Tim Gröger 2020-02-24 18:55:57 +01:00
parent 61b9f7001a
commit 4e91587731
2 changed files with 32 additions and 3 deletions

View File

@ -23,8 +23,13 @@ class UserController(metaclass=Singleton):
def getLockedDay(self, date): def getLockedDay(self, date):
now = datetime.now() now = datetime.now()
daysInMonth = calendar.monthrange(date.year, date.month)[1] daysInMonth = calendar.monthrange(date.year, date.month)[1]
startMonth = 1
for i in range(1, 8):
if datetime(date.year, date.month, i).weekday() == 2:
startMonth = i
break
if date.year <= now.year and date.month <= now.month: if date.year <= now.year and date.month <= now.month:
for i in range(1, daysInMonth + 1): for i in range(startMonth, daysInMonth + 1):
self.setLockedDay(datetime(date.year, date.month, i), True) self.setLockedDay(datetime(date.year, date.month, i), True)
for i in range(1, 8): for i in range(1, 8):
nextMonth = datetime(date.year, date.month + 1, i) nextMonth = datetime(date.year, date.month + 1, i)
@ -50,7 +55,12 @@ class UserController(metaclass=Singleton):
db.setWorker(user, date) db.setWorker(user, date)
return self.getWorker(date, username=username) return self.getWorker(date, username=username)
def deleteWorker(self, username, date): def deleteWorker(self, username, date, userExc=False):
if userExc:
lockedDay = self.getLockedDay(date)
if lockedDay:
if lockedDay['locked']:
raise DayLocked("Day is locked. You can't delete the Job")
user = self.getUser(username) user = self.getUser(username)
db.deleteWorker(user, date) db.deleteWorker(user, date)

View File

@ -103,3 +103,22 @@ def _addUser(**kwargs):
return jsonify({'error': err}), 403 return jsonify({'error': err}), 403
except Exception as err: except Exception as err:
return jsonify({'error': err}), 409 return jsonify({'error': err}), 409
@user.route("/user/deleteJob", methods=['POST'])
@login_required(groups=[USER])
def _deletJob(**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)
userController.deleteWorker(user.uid, date, True)
return jsonify({"ok": "ok"})
except DayLocked as err:
return jsonify({"error": err}), 403
except Exception as err:
return jsonify({"error": err}), 409