flaschengeist/geruecht/vorstand/routes.py

249 lines
8.3 KiB
Python
Raw Normal View History

2020-01-18 22:31:49 +00:00
from flask import Blueprint, request, jsonify
from datetime import datetime, time
import geruecht.controller.userController as uc
2020-03-04 20:11:41 +00:00
import geruecht.controller.ldapController as lc
from geruecht.decorator import login_required
2020-03-04 20:11:41 +00:00
from geruecht.model import MONEY, GASTRO, VORSTAND
from geruecht.logger import getDebugLogger, getJobsLogger
debug = getDebugLogger()
jobL = getJobsLogger()
2020-01-18 22:31:49 +00:00
vorstand = Blueprint("vorstand", __name__)
userController = uc.UserController()
ldap = lc.LDAPController()
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):
debug.info("/um/setStatus")
2020-03-03 21:33:47 +00:00
try:
data = request.get_json()
name = data['name']
retVal = userController.setStatus(name)
debug.debug("return {{ {} }}".format(retVal))
2020-03-03 21:33:47 +00:00
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-03 21:33:47 +00:00
return jsonify({"error": str(err)}), 500
2020-03-03 21:33:47 +00:00
@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):
debug.info("/um/updateStatus")
2020-03-03 21:33:47 +00:00
try:
data = request.get_json()
retVal = userController.updateStatus(data)
debug.debug("return {{ {} }}".format(retVal))
2020-03-03 21:33:47 +00:00
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-03 21:33:47 +00:00
return jsonify({"error": str(err)}), 500
2020-03-03 21:33:47 +00:00
@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):
debug.info("/um/deleteStatus")
2020-03-03 21:33:47 +00:00
try:
data = request.get_json()
userController.deleteStatus(data)
debug.debug("return ok")
2020-03-03 21:33:47 +00:00
return jsonify({"ok": "ok"})
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-03 21:33:47 +00:00
return jsonify({"error": str(err)}), 409
2020-03-03 21:33:47 +00:00
@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):
debug.info("/um/updateStatusUser")
2020-03-03 21:33:47 +00:00
try:
data = request.get_json()
username = data['username']
status = data['status']
retVal = userController.updateStatusOfUser(username, status).toJSON()
debug.debug("return {{ {} }}".format(retVal))
2020-03-03 21:33:47 +00:00
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-03 21:33:47 +00:00
return jsonify({"error": str(err)}), 500
2020-03-03 21:33:47 +00:00
@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):
debug.info("/um/updateVoting")
2020-03-03 21:33:47 +00:00
try:
data = request.get_json()
username = data['username']
voting = data['voting']
retVal = userController.updateVotingOfUser(username, voting).toJSON()
debug.debug("return {{ {} }}".format(retVal))
2020-03-03 21:33:47 +00:00
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-03 21:33:47 +00:00
return jsonify({"error": str(err)}), 500
2020-01-18 22:31:49 +00:00
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])
def _addUser(**kwargs):
debug.info("/sm/addUser")
try:
data = request.get_json()
user = data['user']
day = data['day']
month = data['month']
year = data['year']
date = datetime(year, month, day, 12)
retVal = userController.addWorker(user['username'], date)
debug.debug("retrun {{ {} }}".format(retVal))
userl = userController.getUser(user['username'])
jobL.info("Vorstand {} {} schreibt Mitglied {} {} am {} zum Dienst ein".format(
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, userl.firstname, userl.lastname, date.date()))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/getUsers", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND])
def _getUsers(**kwrags):
debug.info("/sm/getUsers")
try:
data = request.get_json()
from_date = data['from_date']
to_date = data['to_date']
from_date = datetime(
from_date['year'], from_date['month'], from_date['day'])
to_date = datetime(to_date['year'], to_date['month'], to_date['day'])
lockedDays = userController.getLockedDays(from_date, to_date)
retVal = []
for lockedDay in lockedDays:
day = datetime.combine(lockedDay['daydate'], time(12))
retDay = {
"worker": userController.getWorker(day),
"day": {
"date": {
"year": day.year,
"month": day.month,
"day": day.day
},
"locked": lockedDay['locked']
}
}
retVal.append(retDay)
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@vorstand.route("/sm/getUser", methods=['POST'])
2020-03-04 20:11:41 +00:00
@login_required(groups=[MONEY, GASTRO, VORSTAND])
def _getUser(**kwargs):
debug.info("/sm/getUser")
try:
data = request.get_json()
day = data['day']
month = data['month']
year = data['year']
date = datetime(year, month, day, 12)
lockedDay = userController.getLockedDay(date)
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': lockedDay['locked']
}
retVal = {
'worker': userController.getWorker(date),
'day': lockedDay
2020-02-23 21:31:22 +00:00
}
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
2020-01-18 22:31:49 +00:00
@vorstand.route("/sm/deleteUser", methods=['POST'])
@login_required(groups=[MONEY, GASTRO, VORSTAND])
def _deletUser(**kwargs):
debug.info("/sm/deletUser")
try:
data = request.get_json()
user = data['user']
day = data['day']
month = data['month']
year = data['year']
date = datetime(year, month, day, 12)
userController.deleteWorker(user['username'], date)
debug.debug("return ok")
user = userController.getUser(user['username'])
jobL.info("Vorstand {} {} entfernt Mitglied {} {} am {} vom Dienst".format(
kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, date.date()))
return jsonify({"ok": "ok"})
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
2020-02-24 11:19:52 +00:00
2020-02-24 11:19:52 +00:00
@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):
debug.info("/sm/lockDay")
2020-02-24 11:19:52 +00:00
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']
}
debug.debug("return {{ {} }}".format(retVal))
2020-02-24 11:19:52 +00:00
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
2020-03-04 20:11:41 +00:00
return jsonify({'error': err}), 409
2020-03-04 20:11:41 +00:00
@vorstand.route("/sm/searchWithExtern", methods=['GET'])
@login_required(groups=[VORSTAND])
def _search(**kwargs):
debug.info("/sm/searchWithExtern")
try:
retVal = ldap.getAllUser()
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500