fix(roles): Minor fix in set_permissions
This commit is contained in:
parent
1db3391826
commit
691345cf40
|
@ -12,7 +12,7 @@ def get_all():
|
||||||
return Role.query.all()
|
return Role.query.all()
|
||||||
|
|
||||||
|
|
||||||
def get(role_name: Union[int,str]) -> Role:
|
def get(role_name: Union[int, str]) -> Role:
|
||||||
"""Get role by ID or name
|
"""Get role by ID or name
|
||||||
Args:
|
Args:
|
||||||
role_name: Name or ID of the role
|
role_name: Name or ID of the role
|
||||||
|
@ -46,11 +46,10 @@ def update_role(role, new_name):
|
||||||
|
|
||||||
|
|
||||||
def set_permissions(role, permissions):
|
def set_permissions(role, permissions):
|
||||||
for name in permissions:
|
perms = Permission.query.filter(Permission.name.in_(permissions)).all()
|
||||||
p = Permission.query.filter(Permission.name.in_(permissions)).all()
|
if len(perms) < len(permissions):
|
||||||
if not p or len(p) < len(permissions):
|
raise BadRequest("Invalid permission name")
|
||||||
raise BadRequest("Invalid permission name >{}<".format(name))
|
role.permissions = list(perms)
|
||||||
role.permissions = list(p)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue