2020-01-18 22:31:49 +00:00
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
from datetime import datetime
|
2020-01-19 08:07:45 +00:00
|
|
|
import geruecht.controller.userController as uc
|
2020-03-04 20:11:41 +00:00
|
|
|
import geruecht.controller.ldapController as lc
|
2020-01-19 08:07:45 +00:00
|
|
|
from geruecht.decorator import login_required
|
2020-03-04 20:11:41 +00:00
|
|
|
from geruecht.model import MONEY, GASTRO, VORSTAND
|
2020-01-23 22:27:26 +00:00
|
|
|
import time
|
2020-01-18 22:31:49 +00:00
|
|
|
|
|
|
|
vorstand = Blueprint("vorstand", __name__)
|
2020-01-19 08:07:45 +00:00
|
|
|
userController = uc.UserController()
|
2020-03-04 20:11:41 +00:00
|
|
|
ldap= lc.LDAPController()
|
2020-01-19 08:07:45 +00:00
|
|
|
|
2020-03-03 21:33:47 +00:00
|
|
|
@vorstand.route('/um/setStatus', methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-03-03 21:33:47 +00:00
|
|
|
def _setStatus(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
name = data['name']
|
|
|
|
retVal = userController.setStatus(name)
|
|
|
|
return jsonify(retVal)
|
|
|
|
except Exception as err:
|
|
|
|
return jsonify({"error": str(err)}), 500
|
|
|
|
|
|
|
|
@vorstand.route('/um/updateStatus', methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-03-03 21:33:47 +00:00
|
|
|
def _updateStatus(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
retVal = userController.updateStatus(data)
|
|
|
|
return jsonify(retVal)
|
|
|
|
except Exception as err:
|
|
|
|
return jsonify({"error": str(err)}), 500
|
|
|
|
|
|
|
|
@vorstand.route('/um/deleteStatus', methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-03-03 21:33:47 +00:00
|
|
|
def _deleteStatus(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
userController.deleteStatus(data)
|
|
|
|
return jsonify({"ok": "ok"})
|
|
|
|
except Exception as err:
|
|
|
|
return jsonify({"error": str(err)}), 409
|
|
|
|
|
|
|
|
@vorstand.route('/um/updateStatusUser', methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-03-03 21:33:47 +00:00
|
|
|
def _updateStatusUser(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
username = data['username']
|
|
|
|
status = data['status']
|
|
|
|
retVal = userController.updateStatusOfUser(username, status).toJSON()
|
|
|
|
return jsonify(retVal)
|
|
|
|
except Exception as err:
|
|
|
|
return jsonify({"error": str(err)}), 500
|
|
|
|
|
|
|
|
@vorstand.route('/um/updateVoting', methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-03-03 21:33:47 +00:00
|
|
|
def _updateVoting(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
username = data['username']
|
|
|
|
voting = data['voting']
|
|
|
|
retVal = userController.updateVotingOfUser(username, voting).toJSON()
|
|
|
|
return jsonify(retVal)
|
|
|
|
except Exception as err:
|
|
|
|
return jsonify({"error": str(err)}), 500
|
2020-01-18 22:31:49 +00:00
|
|
|
|
|
|
|
@vorstand.route("/sm/addUser", methods=['POST', 'GET'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-01-19 20:32:58 +00:00
|
|
|
def _addUser(**kwargs):
|
2020-01-18 22:31:49 +00:00
|
|
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
return "<h1>HEllo World</h1>"
|
|
|
|
|
2020-01-19 08:07:45 +00:00
|
|
|
data = request.get_json()
|
|
|
|
user = data['user']
|
2020-02-23 10:18:54 +00:00
|
|
|
day = data['day']
|
|
|
|
month = data['month']
|
|
|
|
year = data['year']
|
|
|
|
date = datetime(year,month,day,12)
|
2020-01-19 20:32:58 +00:00
|
|
|
retVal = userController.addWorker(user['username'], date)
|
|
|
|
print(retVal)
|
|
|
|
return jsonify(retVal)
|
|
|
|
|
|
|
|
@vorstand.route("/sm/getUser", methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-01-19 20:32:58 +00:00
|
|
|
def _getUser(**kwargs):
|
|
|
|
data = request.get_json()
|
2020-02-23 10:18:54 +00:00
|
|
|
day = data['day']
|
|
|
|
month = data['month']
|
|
|
|
year = data['year']
|
|
|
|
date = datetime(year, month, day, 12)
|
2020-02-23 21:31:22 +00:00
|
|
|
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']
|
|
|
|
}
|
2020-02-23 20:27:03 +00:00
|
|
|
retVal = {
|
|
|
|
'worker': userController.getWorker(date),
|
2020-02-23 21:31:22 +00:00
|
|
|
'day': lockedDay
|
2020-02-23 20:27:03 +00:00
|
|
|
}
|
2020-01-19 20:32:58 +00:00
|
|
|
print(retVal)
|
|
|
|
return jsonify(retVal)
|
2020-01-18 22:31:49 +00:00
|
|
|
|
2020-01-19 20:32:58 +00:00
|
|
|
@vorstand.route("/sm/deleteUser", methods=['POST'])
|
2020-03-05 20:24:32 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-01-19 20:32:58 +00:00
|
|
|
def _deletUser(**kwargs):
|
|
|
|
data = request.get_json()
|
|
|
|
user = data['user']
|
2020-02-23 10:18:54 +00:00
|
|
|
day = data['day']
|
|
|
|
month = data['month']
|
|
|
|
year = data['year']
|
|
|
|
date = datetime(year, month, day, 12)
|
2020-01-19 20:32:58 +00:00
|
|
|
userController.deleteWorker(user['username'], date)
|
2020-02-24 11:19:52 +00:00
|
|
|
return jsonify({"ok": "ok"})
|
|
|
|
|
|
|
|
@vorstand.route("/sm/lockDay", methods=['POST'])
|
2020-03-04 20:11:41 +00:00
|
|
|
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
2020-02-24 11:19:52 +00:00
|
|
|
def _lockDay(**kwargs):
|
|
|
|
try:
|
|
|
|
data = request.get_json()
|
|
|
|
year = data['year']
|
|
|
|
month = data['month']
|
|
|
|
day = data['day']
|
|
|
|
locked = data['locked']
|
|
|
|
date = datetime(year, month, day, 12)
|
|
|
|
lockedDay = userController.setLockedDay(date, locked, True)
|
|
|
|
if not lockedDay:
|
|
|
|
retVal = {
|
|
|
|
'date': {
|
|
|
|
'year': year,
|
|
|
|
'month': month,
|
|
|
|
'day': day
|
|
|
|
},
|
|
|
|
'locked': False
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
retVal = {
|
|
|
|
'date': {
|
|
|
|
'year': year,
|
|
|
|
'month': month,
|
|
|
|
'day': day
|
|
|
|
},
|
|
|
|
'locked': lockedDay['locked']
|
|
|
|
}
|
|
|
|
print(retVal)
|
|
|
|
return jsonify(retVal)
|
|
|
|
except Exception as err:
|
2020-03-04 20:11:41 +00:00
|
|
|
return jsonify({'error': err}), 409
|
|
|
|
|
|
|
|
@vorstand.route("/sm/searchWithExtern", methods=['GET'])
|
|
|
|
@login_required(groups=[VORSTAND])
|
|
|
|
def _search(**kwargs):
|
|
|
|
retVal = ldap.getAllUser()
|
|
|
|
return jsonify(retVal)
|