rb-commons 0.5.16__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.
@@ -67,10 +67,10 @@ class BaseAPI:
67
67
  data = {}
68
68
  except ValueError as e:
69
69
  error_message = data.get("message") or data.get("detail") or response.text
70
- raise BadRequestException(f"Invalid JSON response: {response.text}", additional_info={"error_message": error_message})
70
+ raise BadRequestException(f"Invalid JSON response", additional_info={"error_message": error_message})
71
71
  if not (200 <= response.status_code < 300):
72
72
  error_message = data.get("message") or data.get("detail") or response.text
73
- raise BadRequestException(f"Unexpected error occured: {response.text}", additional_info={"error_message": error_message})
73
+ raise BadRequestException(f"Unexpected error occured", additional_info={"error_message": error_message})
74
74
 
75
75
  return response
76
76
 
@@ -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"])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rb-commons
3
- Version: 0.5.16
3
+ Version: 0.5.18
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -8,7 +8,7 @@ rb_commons/configs/rabbitmq.py,sha256=vUqa_PcZkPp1lX0B6HLSAXVMUcPR2_8-8cN-C7xFxR
8
8
  rb_commons/configs/v2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  rb_commons/configs/v2/config.py,sha256=kZ02y_HIMD-SXqA990yR1r9qrkpvzwn4Nda6fhVMcmo,1581
10
10
  rb_commons/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- rb_commons/http/base_api.py,sha256=L4bZmJJrtfIp0N9vdlc9m8FzyZXb3dZ7_RMe4RQVers,5313
11
+ rb_commons/http/base_api.py,sha256=ZiSJX5z-1QbL5RuKm30wf-3kbOu4s2plb8q3v0DQUKo,5279
12
12
  rb_commons/http/consul.py,sha256=Ioq72VD1jGwoC96set7n2SgxN40olzI-myA2lwKkYi4,1864
13
13
  rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
14
14
  rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -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=kDvAUvUPt5iUV6ZrdeVPYNJjv4a_Gau7VR8oC_GaaGU,1050
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=4MLw3J1-LiU2CXIgm0kP1mlGoDmNfMXmj9iav2s-1Iw,2056
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.16.dist-info/METADATA,sha256=Qe3eYj1PSMM85qmjtBzpY8TxcbOIAQjqQShsH56p_Lk,6571
26
- rb_commons-0.5.16.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
27
- rb_commons-0.5.16.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
28
- rb_commons-0.5.16.dist-info/RECORD,,
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,,