finished ##208

This commit is contained in:
Tim Gröger 2020-03-03 22:33:47 +01:00
parent 708ecb1aa6
commit 068da1e57b
7 changed files with 202 additions and 3 deletions

View File

@ -39,7 +39,7 @@ def _bar(**kwargs):
dic[user.uid] = {"username": user.uid, dic[user.uid] = {"username": user.uid,
"firstname": user.firstname, "firstname": user.firstname,
"lastname": user.lastname, "lastname": user.lastname,
"amount": abs(all), "amount": all,
"locked": user.locked, "locked": user.locked,
"type": type "type": type
} }

View File

@ -491,6 +491,86 @@ class DatabaseController(metaclass=Singleton):
self.db.connection.rollback() self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Database: {}".format(err)) raise DatabaseExecption("Something went worng with Database: {}".format(err))
def getAllStatus(self):
try:
cursor = self.db.connection.cursor()
cursor.execute('select * from statusgroup')
return cursor.fetchall()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def getStatus(self, name):
try:
cursor = self.db.connection.cursor()
if type(name) == str:
sql = "select * from statusgroup where name='{}'".format(name)
elif type(name) == int:
sql = 'select * from statusgroup where id={}'.format(name)
else:
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
cursor.execute(sql)
return cursor.fetchone()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def setStatus(self, name):
try:
cursor = self.db.connection.cursor()
cursor.execute("insert into statusgroup (name) values ('{}')".format(name))
self.db.connection.commit()
return self.getStatus(name)
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def updateStatus(self, status):
try:
cursor = self.db.connection.cursor()
cursor.execute("update statusgroup set name='{}' where id={}".format(status['name'], status['id']))
self.db.connection.commit()
return self.getStatus(status['id'])
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def deleteStatus(self, status):
try:
cursor = self.db.connection.cursor()
cursor.execute("delete from statusgroup where id={}".format(status['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def updateStatusOfUser(self, username, status):
try:
cursor = self.db.connection.cursor()
cursor.execute("update user set statusgroup={} where uid='{}'".format(status['id'], username))
self.db.connection.commit()
return self.getUser(username)
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def updateVotingOfUser(self, username, voting):
try:
cursor = self.db.connection.cursor()
cursor.execute("update user set voting={} where uid='{}'".format(voting, username))
self.db.connection.commit()
return self.getUser(username)
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
if __name__ == '__main__': if __name__ == '__main__':
db = DatabaseController() db = DatabaseController()
user = db.getUser('jhille') user = db.getUser('jhille')

View File

@ -17,6 +17,27 @@ class UserController(metaclass=Singleton):
def __init__(self): def __init__(self):
pass pass
def getAllStatus(self):
return db.getAllStatus()
def getStatus(self, name):
return db.getStatus(name)
def setStatus(self, name):
return db.setStatus(name)
def deleteStatus(self, status):
db.deleteStatus(status)
def updateStatus(self, status):
return db.updateStatus(status)
def updateStatusOfUser(self, username, status):
return db.updateStatusOfUser(username, status)
def updateVotingOfUser(self, username, voting):
return db.updateVotingOfUser(username, voting)
def deleteDrinkType(self, type): def deleteDrinkType(self, type):
db.deleteDrinkType(type) db.deleteDrinkType(type)

View File

@ -142,7 +142,7 @@ class CreditList():
elif month == 2: elif month == 2:
retValue = (self.feb_guthaben, self.feb_schulden) retValue = (self.feb_guthaben, self.feb_schulden)
elif month == 3: elif month == 3:
retValue = (self.mear_guthaben, self.maer_schulden) retValue = (self.maer_guthaben, self.maer_schulden)
elif month == 4: elif month == 4:
retValue = (self.apr_guthaben, self.apr_schulden) retValue = (self.apr_guthaben, self.apr_schulden)
elif month == 5: elif month == 5:

View File

@ -27,6 +27,14 @@ class User():
self.firstname = data['firstname'] self.firstname = data['firstname']
self.lastname = data['lastname'] self.lastname = data['lastname']
self.group = data['gruppe'] self.group = data['gruppe']
if 'statusgroup' in data:
self.statusgroup = data['statusgroup']
else:
self.statusgroup = None
if 'voting' in data:
self.voting = data['voting']
else:
self.voting = None
if 'mail' in data: if 'mail' in data:
self.mail = data['mail'] self.mail = data['mail']
else: else:
@ -68,6 +76,10 @@ class User():
self.autoLock = bool(data['autoLock']) self.autoLock = bool(data['autoLock'])
if 'mail' in data: if 'mail' in data:
self.mail = data['mail'] self.mail = data['mail']
if 'statusgorup' in data:
self.statusgroup = data['statusgroup']
if 'voting' in data:
self.voting = data['voting']
def initGeruechte(self, creditLists): def initGeruechte(self, creditLists):
if type(creditLists) == list: if type(creditLists) == list:
@ -196,6 +208,7 @@ class User():
A Dic with static Attributes. A Dic with static Attributes.
""" """
dic = { dic = {
"id": self.id,
"userId": self.uid, "userId": self.uid,
"uid": self.uid, "uid": self.uid,
"dn": self.dn, "dn": self.dn,
@ -206,7 +219,9 @@ class User():
"locked": self.locked, "locked": self.locked,
"autoLock": self.autoLock, "autoLock": self.autoLock,
"limit": self.limit, "limit": self.limit,
"mail": self.mail "mail": self.mail,
"statusgroup": self.statusgroup,
"voting": self.voting
} }
return dic return dic

View File

@ -1,4 +1,5 @@
from geruecht import app, LOGGER from geruecht import app, LOGGER
from geruecht.decorator import login_required
from geruecht.exceptions import PermissionDenied from geruecht.exceptions import PermissionDenied
import geruecht.controller.accesTokenController as ac import geruecht.controller.accesTokenController as ac
import geruecht.controller.userController as uc import geruecht.controller.userController as uc
@ -46,7 +47,35 @@ def getTypes():
except Exception as err: except Exception as err:
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/getAllStatus', methods=['GET'])
@login_required(groups=[USER, MONEY, GASTRO, BAR])
def _getAllStatus(**kwargs):
try:
retVal = userController.getAllStatus()
return jsonify(retVal)
except Exception as err:
return jsonify({"error": str(err)}), 500
@app.route('/getStatus', methods=['POST'])
@login_required(groups=[USER, MONEY, GASTRO, BAR])
def _getStatus(**kwargs):
try:
data = request.get_json()
name = data['name']
retVal = userController.getStatus(name)
return jsonify(retVal)
except Exception as err:
return jsonify({"error": str(err)}), 500
@app.route('/getUsers', methods=['GET'])
@login_required(groups=[MONEY, GASTRO])
def _getUsers(**kwargs):
try:
users = userController.getAllUsersfromDB()
retVal = [user.toJSON() for user in users]
return jsonify(retVal)
except Exception as err:
return jsonify({"error": str(err)}), 500
@app.route("/login", methods=['POST']) @app.route("/login", methods=['POST'])
def _login(): def _login():

View File

@ -8,6 +8,60 @@ import time
vorstand = Blueprint("vorstand", __name__) vorstand = Blueprint("vorstand", __name__)
userController = uc.UserController() userController = uc.UserController()
@vorstand.route('/um/setStatus', methods=['POST'])
@login_required(groups=[MONEY, GASTRO])
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'])
@login_required(groups=[MONEY, GASTRO])
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'])
@login_required(groups=[MONEY, GASTRO])
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'])
@login_required(groups=[MONEY, GASTRO])
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'])
@login_required(groups=[MONEY, GASTRO])
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
@vorstand.route("/sm/addUser", methods=['POST', 'GET']) @vorstand.route("/sm/addUser", methods=['POST', 'GET'])
@login_required(groups=[MONEY, GASTRO]) @login_required(groups=[MONEY, GASTRO])