fix add role to user
This commit is contained in:
parent
5bab4a7cde
commit
d7428b2ed1
|
@ -3,6 +3,7 @@ import sqlalchemy.exc
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
|
|
||||||
|
from flaschengeist import logger
|
||||||
from flaschengeist.database import db
|
from flaschengeist.database import db
|
||||||
from flaschengeist.controller import roleController, userController
|
from flaschengeist.controller import roleController, userController
|
||||||
|
|
||||||
|
@ -70,12 +71,19 @@ def user(add_role, delete, user):
|
||||||
if USER_KEY in ctx.meta:
|
if USER_KEY in ctx.meta:
|
||||||
userController.register(ctx.meta[USER_KEY], ctx.meta[USER_KEY]["password"])
|
userController.register(ctx.meta[USER_KEY], ctx.meta[USER_KEY]["password"])
|
||||||
else:
|
else:
|
||||||
|
if not isinstance(user, list) or not isinstance(user, tuple):
|
||||||
|
user = [user]
|
||||||
for uid in user:
|
for uid in user:
|
||||||
|
logger.debug(f"Userid: {uid}")
|
||||||
user = userController.get_user(uid)
|
user = userController.get_user(uid)
|
||||||
|
logger.debug(f"User: {user}")
|
||||||
if delete:
|
if delete:
|
||||||
|
logger.debug(f"Deleting user {user}")
|
||||||
userController.delete_user(user)
|
userController.delete_user(user)
|
||||||
elif add_role:
|
elif add_role:
|
||||||
|
logger.debug(f"Adding role {add_role} to user {user}")
|
||||||
role = roleController.get(add_role)
|
role = roleController.get(add_role)
|
||||||
|
logger.debug(f"Role: {role}")
|
||||||
user.roles_.append(role)
|
user.roles_.append(role)
|
||||||
userController.modify_user(user, None)
|
userController.modify_user(user, None)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in New Issue