File tree Expand file tree Collapse file tree 2 files changed +30
-17
lines changed
services/web/server/src/simcore_service_webserver/security Expand file tree Collapse file tree 2 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -54,3 +54,29 @@ async def check_user_permission(
5454 else :
5555 msg += f" { permission } "
5656 raise web .HTTPForbidden (text = msg )
57+
58+
59+ async def check_user_permission_with_groups (
60+ request : web .Request , permission : str
61+ ) -> None :
62+ """Checker that passes to authorized users with given permission via roles OR groups.
63+
64+ Raises:
65+ web.HTTPUnauthorized: If user is not authorized
66+ web.HTTPForbidden: If user is authorized but lacks both role and group permissions
67+ """
68+ from ..products import products_web
69+
70+ context = {
71+ "authorized_uid" : await check_user_authorized (request ),
72+ "enable_group_permissions" : True ,
73+ "request" : request ,
74+ "product_support_group_id" : products_web .get_current_product (
75+ request
76+ ).support_standard_group_id ,
77+ }
78+
79+ allowed = await aiohttp_security .api .permits (request , permission , context )
80+ if not allowed :
81+ msg = f"You do not have sufficient access rights for { permission } "
82+ raise web .HTTPForbidden (text = msg )
Original file line number Diff line number Diff line change 11from functools import wraps
22
3- import aiohttp_security .api # type: ignore[import-untyped]
43from aiohttp import web
54from servicelib .aiohttp .typing_extension import Handler
6- from simcore_service_webserver .products import products_web
75
8- from ._authz_web import check_user_authorized
6+ from ._authz_web import check_user_permission_with_groups
97from .security_web import check_user_permission
108
119
@@ -43,20 +41,9 @@ def group_or_role_permission_required(permission: str):
4341 def _decorator (handler : Handler ):
4442 @wraps (handler )
4543 async def _wrapped (request : web .Request ):
46- context = {
47- "authorized_uid" : await check_user_authorized (request ),
48- "product_support_group_id" : products_web .get_current_product (
49- request
50- ).support_standard_group_id ,
51- }
52-
53- # Check both role-based and group-based permissions
54- if await aiohttp_security .api .permits (request , permission , context ):
55- return await handler (request )
56-
57- # Neither role nor group permissions granted
58- msg = f"You do not have sufficient access rights for { permission } "
59- raise web .HTTPForbidden (text = msg )
44+ await check_user_permission_with_groups (request , permission )
45+
46+ return await handler (request )
6047
6148 return _wrapped
6249
You can’t perform that action at this time.
0 commit comments