File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 66 wrap_api_exception ,
77)
88from api .v1 .middleware import (
9+ management_user_validation ,
910 management_read_only_api ,
1011 management_read_write_api ,
1112 deserialize_schema ,
13+ check_admin_rights
1214)
1315from typing import List , Optional
1416import server
@@ -34,9 +36,9 @@ def model_to_schema(
3436
3537
3638@permissions_blueprint .route ("/api/v1/permissions" )
37- @management_read_only_api
39+ @management_user_validation
3840@wrap_api_exception ("permissions fetching failed" )
39- def fetch_all ():
41+ def fetch_all (** kwargs ):
4042 """Fetch all permissions
4143
4244 :status 200: no error
@@ -78,10 +80,12 @@ def fetch_all():
7880 ]
7981 """ # noqa: E501
8082
83+ has_admin_rights = check_admin_rights (kwargs .get ('user_roles' , []), True )
84+ user_id = kwargs .get ('user_id' ) if not has_admin_rights else None
85+
8186 permissions : List [
8287 models .permission .
83- Permission ] = server .instance ._permissions_db .fetch_all (
84- )
88+ Permission ] = server .instance ._permissions_db .fetch_all (user_id = user_id )
8589 return Permission .Schema ().dump ([
8690 model_to_schema (perms ) for perms in permissions
8791 ], many = True ), 200
Original file line number Diff line number Diff line change @@ -14,10 +14,14 @@ class PermissionsDB:
1414 def __init__ (self , db : Engine ):
1515 self .engine = db
1616
17- def fetch_all (self ) -> List [models .permission .Permission ]:
17+ def fetch_all (self , user_id : Optional [ str ] = None ) -> List [models .permission .Permission ]:
1818 """Fetches all permissions from the database"""
1919 with Session (self .engine ) as session :
2020 stmt = select (models .permission .Permission )
21+
22+ if user_id is not None :
23+ stmt = stmt .where (models .permission .Permission .user_id == user_id )
24+
2125 permissions = session .scalars (stmt )
2226 if permissions is None :
2327 return []
You can’t perform that action at this time.
0 commit comments