Skip to content

Commit

Permalink
Merge pull request #10 from gazev/session
Browse files Browse the repository at this point in the history
fix: roles management
  • Loading branch information
vugonz authored Nov 14, 2024
2 parents 9cdf540 + 0752cff commit ca7b547
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__/

data/flask_sessions/
data/logs/
data/photos/
*.sqlite3

.env
8 changes: 6 additions & 2 deletions app/api/members/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def add_member_role(username):
roles = member_service.add_member_role(member, **json_data)
if roles is None:
throw_api_error(HTTPStatus.NOT_FOUND, {"error": "User already has this role"})
session['roles'] = roles

if session.get('username', '') == member.username:
session['roles'] = roles

return roles

Expand Down Expand Up @@ -299,6 +301,8 @@ def remove_member_role(username):
roles = member_service.remove_member_role(member, **json_data)
if roles is None:
throw_api_error(HTTPStatus.NOT_FOUND, {"error": "User does not have this role"})
session['roles'] = roles

if session.get('username', '') == member.username:
session['roles'] = roles

return roles
5 changes: 5 additions & 0 deletions app/roles/roles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def has_permission(self, roles_list: List[str], permission: str):
def has_higher_level(self, roles_list: List[str], role: str):
"""" Checks whether any role in `roles_list` has higher level than `role`. """
_, highest_lvl = self._get_highest(roles_list)
print(highest_lvl)
print(role)
print(self._get_role_level(role))
if highest_lvl == 0:
return True # level 0 has all permissions
return highest_lvl < self._get_role_level(role) # < instead of <= means we cannot add "horizontally"

def init_app(self, app: Flask) -> None:
Expand Down

0 comments on commit ca7b547

Please sign in to comment.