Skip to content

Commit 85c779c

Browse files
committed
cleanup permission key
1 parent 4e0d39f commit 85c779c

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

services/web/server/src/simcore_service_webserver/login/decorators.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from servicelib.request_keys import RQT_USERID_KEY
77

88
from ..products.api import get_product_name
9-
from ..security.api import AuthContextDict, check_user_authorized, check_user_permission
9+
from ..security.api import (
10+
PERMISSION_PRODUCT_LOGIN,
11+
AuthContextDict,
12+
check_user_authorized,
13+
check_user_permission,
14+
)
1015

1116

1217
def login_required(handler: HandlerAnyReturn) -> HandlerAnyReturn:
@@ -53,7 +58,7 @@ async def _wrapper(request: web.Request):
5358

5459
await check_user_permission(
5560
request,
56-
"product",
61+
PERMISSION_PRODUCT_LOGIN,
5762
context=AuthContextDict(
5863
product_name=get_product_name(request),
5964
authorized_uid=user_id,

services/web/server/src/simcore_service_webserver/security/_authz_policy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""" AUTHoriZation (auth) policy:
1+
""" AUTHoriZation (auth) policy
2+
23
"""
34

45
import contextlib
@@ -23,7 +24,7 @@
2324
has_access_by_role,
2425
)
2526
from ._authz_db import AuthInfoDict, get_active_user_or_none, is_user_in_product_name
26-
from ._constants import MSG_AUTH_NOT_AVAILABLE
27+
from ._constants import MSG_AUTH_NOT_AVAILABLE, PERMISSION_PRODUCT_LOGIN_KEY
2728
from ._identity_api import IdentityStr
2829

2930
_logger = logging.getLogger(__name__)
@@ -132,7 +133,7 @@ async def permits(
132133
context = context or AuthContextDict()
133134

134135
# product access
135-
if permission == "product":
136+
if permission == PERMISSION_PRODUCT_LOGIN_KEY:
136137
product_name = context.get("product_name")
137138
ok: bool = product_name is not None and await self._has_access_to_product(
138139
user_id=auth_info["id"], product_name=product_name
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from typing import Final
22

33
MSG_AUTH_NOT_AVAILABLE: Final[str] = "Authentication service is temporary unavailable"
4+
5+
PERMISSION_PRODUCT_LOGIN_KEY: Final[str] = "product.login"

services/web/server/src/simcore_service_webserver/security/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
NOTE: DO NOT USE aiohttp_security.api directly but use this interface instead
77
"""
88

9-
109
import aiohttp_security.api # type: ignore[import-untyped]
1110
import passlib.hash
1211
from aiohttp import web
@@ -64,7 +63,9 @@ async def check_user_permission(
6463

6564
allowed = await aiohttp_security.api.permits(request, permission, context)
6665
if not allowed:
67-
raise web.HTTPForbidden(reason=f"Not sufficient access rights for {permission}")
66+
raise web.HTTPForbidden(
67+
reason=f"You do not have sufficient access rights for {permission}"
68+
)
6869

6970

7071
#
@@ -93,5 +94,6 @@ def check_password(password: str, password_hash: str) -> bool:
9394
"forget_identity",
9495
"get_access_model",
9596
"is_anonymous",
97+
"PERMISSION_PRODUCT_LOGIN",
9698
"remember_identity",
9799
)

0 commit comments

Comments
 (0)