rb-commons 0.5.17__py3-none-any.whl → 0.5.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rb_commons/permissions/role_permissions.py +2 -1
- rb_commons/schemes/jwt.py +8 -0
- {rb_commons-0.5.17.dist-info → rb_commons-0.5.18.dist-info}/METADATA +1 -1
- {rb_commons-0.5.17.dist-info → rb_commons-0.5.18.dist-info}/RECORD +6 -6
- {rb_commons-0.5.17.dist-info → rb_commons-0.5.18.dist-info}/WHEEL +0 -0
- {rb_commons-0.5.17.dist-info → rb_commons-0.5.18.dist-info}/top_level.txt +0 -0
@@ -23,7 +23,8 @@ class IsAdmin(BasePermission):
|
|
23
23
|
|
24
24
|
class IsCustomer(BasePermission):
|
25
25
|
def has_permission(self, claims: Claims) -> bool:
|
26
|
-
return claims.user_role == UserRole.CUSTOMER and claims.user_id is not None and claims.shop_id is not None
|
26
|
+
return claims.user_role == UserRole.CUSTOMER and claims.user_id is not None and claims.shop_id is not None \
|
27
|
+
and claims.customer_id is not None
|
27
28
|
|
28
29
|
|
29
30
|
IsAdminDep = Annotated[Claims, Depends(IsAdmin())]
|
rb_commons/schemes/jwt.py
CHANGED
@@ -14,6 +14,7 @@ class Claims(BaseModel):
|
|
14
14
|
model_config = ConfigDict(extra="ignore")
|
15
15
|
|
16
16
|
user_id: Optional[int] = Field(None, alias="x-user-id")
|
17
|
+
customer_id: Optional[int] = Field(None, alias="x-customer-id")
|
17
18
|
user_role: UserRole = Field(UserRole.GUEST, alias="x-user-role")
|
18
19
|
shop_id: Optional[uuid.UUID] = Field(None, alias="x-shop-id")
|
19
20
|
jwt_token: Optional[str] = Field(None, alias="x-jwt-token")
|
@@ -22,6 +23,7 @@ class Claims(BaseModel):
|
|
22
23
|
def from_headers(cls, headers: dict) -> 'Claims':
|
23
24
|
raw_claims = {
|
24
25
|
"x-user-id": headers.get("x-user-id"),
|
26
|
+
"x-customer-id": headers.get("x-customer-id"),
|
25
27
|
"x-user-role": headers.get("x-user-role", "admin"),
|
26
28
|
"x-shop-id": headers.get("x-shop-id"),
|
27
29
|
"x-jwt-token": headers.get("x-jwt-token")
|
@@ -34,6 +36,12 @@ class Claims(BaseModel):
|
|
34
36
|
except ValueError as e:
|
35
37
|
raise ValueError(f"Invalid user_id format: {e}")
|
36
38
|
|
39
|
+
if raw_claims["x-customer-id"]:
|
40
|
+
try:
|
41
|
+
raw_claims["x-customer-id"] = int(raw_claims["x-customer-id"])
|
42
|
+
except ValueError as e:
|
43
|
+
raise ValueError(f"Invalid customer_id format: {e}")
|
44
|
+
|
37
45
|
if raw_claims["x-shop-id"]:
|
38
46
|
try:
|
39
47
|
raw_claims["x-shop-id"] = uuid.UUID(raw_claims["x-shop-id"])
|
@@ -16,13 +16,13 @@ rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,
|
|
16
16
|
rb_commons/orm/managers.py,sha256=VMu3v-JzSVZ9pN2d4ZcAF6qZyqmBeXZ62kiHUY73v20,17163
|
17
17
|
rb_commons/orm/services.py,sha256=71eRcJ4TxZvzNz-hLXo12X4U7PGK54ZfbLAb27AjZi8,1589
|
18
18
|
rb_commons/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
-
rb_commons/permissions/role_permissions.py,sha256=
|
19
|
+
rb_commons/permissions/role_permissions.py,sha256=4dV89z6ggzLqCCiFYlMp7kQVJRESu6MHpkT5ZNjLo6A,1096
|
20
20
|
rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
-
rb_commons/schemes/jwt.py,sha256=
|
21
|
+
rb_commons/schemes/jwt.py,sha256=5J-VTAgRWnRrOU6cuumc8eDJQDyTm5y8cn-kLSLan_g,2453
|
22
22
|
rb_commons/schemes/pagination.py,sha256=8VZW1wZGJIPR9jEBUgppZUoB4uqP8ORudHkMwvEJSxg,1866
|
23
23
|
rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
rb_commons/utils/media.py,sha256=J2Zi0J28DhcVQVzt-myNNVuzj9Msaetul53VjZtdDdc,820
|
25
|
-
rb_commons-0.5.
|
26
|
-
rb_commons-0.5.
|
27
|
-
rb_commons-0.5.
|
28
|
-
rb_commons-0.5.
|
25
|
+
rb_commons-0.5.18.dist-info/METADATA,sha256=K4LUgXImE93aU2C4Sl9t0ttSj-WP3TLsTPV1hl9Ziws,6571
|
26
|
+
rb_commons-0.5.18.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
27
|
+
rb_commons-0.5.18.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
|
28
|
+
rb_commons-0.5.18.dist-info/RECORD,,
|
File without changes
|
File without changes
|