rb-commons 0.1.14__py3-none-any.whl → 0.1.16__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.
@@ -1,4 +1,6 @@
1
1
  from typing import Annotated
2
+
3
+ from rb_commons.permissions import IsAdmin, IsCustomer
2
4
  from rb_commons.schemes.jwt import Claims
3
5
  from fastapi import Request, Depends
4
6
 
@@ -6,4 +8,6 @@ from fastapi import Request, Depends
6
8
  async def get_claims(request: Request) -> Claims:
7
9
  return Claims.from_headers(dict(request.headers))
8
10
 
9
- ClaimsDep = Annotated[Claims, Depends(get_claims)]
11
+ ClaimsDep = Annotated[Claims, Depends(get_claims)]
12
+ IsAdminDep = Annotated[IsAdmin, Depends(IsAdmin())]
13
+ IsCustomerDep = Annotated[IsCustomer, Depends(IsCustomer())]
@@ -67,7 +67,7 @@ class BaseManager(Generic[ModelType]):
67
67
  delete_stmt = delete(self.model).filter_by(**filters)
68
68
  result = await self.session.execute(delete_stmt)
69
69
  await self.session.commit()
70
- return result.rowcount() > 0
70
+ return result
71
71
  except NoResultFound:
72
72
  return False
73
73
  except SQLAlchemyError as e:
@@ -0,0 +1 @@
1
+ from role_permissions import *
@@ -0,0 +1,23 @@
1
+ from fastapi import Depends, HTTPException
2
+
3
+ from rb_commons.configs.injections import get_claims
4
+ from rb_commons.schemes.jwt import Claims, UserRole
5
+
6
+
7
+ class BasePermission:
8
+ def __call__(self, claims: Claims = Depends(get_claims)):
9
+ if not self.has_permission(claims):
10
+ raise HTTPException(status_code=403, detail="Permission Denied")
11
+
12
+ def has_permission(self, claims: Claims) -> bool:
13
+ return False
14
+
15
+
16
+ class IsAdmin(BasePermission):
17
+ def has_permission(self, claims: Claims) -> bool:
18
+ return claims.user_role == UserRole.ADMIN
19
+
20
+
21
+ class IsCustomer(BasePermission):
22
+ def has_permission(self, claims: Claims) -> bool:
23
+ return claims.user_role == UserRole.CUSTOMER
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rb-commons
3
- Version: 0.1.14
3
+ Version: 0.1.16
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
@@ -0,0 +1,15 @@
1
+ rb_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ rb_commons/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ rb_commons/configs/config.py,sha256=tpqC1V9PXx88m0N5L13WqkoalPUk6SthjxgL_lmf-lE,1439
4
+ rb_commons/configs/injections.py,sha256=jOnabKVNj490nYqGuqw5jeSFFvq1lM8vfmx-R1NJobc,448
5
+ rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
7
+ rb_commons/orm/managers.py,sha256=s0MeGfuDmQA287IV57s8kk467AJwskAoG4HvgQxKTYc,6711
8
+ rb_commons/permissions/__init__.py,sha256=2AWODOWWC_p7ThC6kilzSFm4vZbekgk3Tk8hFOHzyTM,30
9
+ rb_commons/permissions/role_permissions.py,sha256=SSLToBcz6OLGBo2Jw9L8BcfZlGsTy_kB1VRrVTizKy0,735
10
+ rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ rb_commons/schemes/jwt.py,sha256=F66JJDhholuOPPzlKeoC6f1TL4gXg4oRUrV5yheNpyo,1675
12
+ rb_commons-0.1.16.dist-info/METADATA,sha256=k_eJ4IUYbN5y9wz4FC0uZDwtZ4DbQwsAofGLQO84wJI,6533
13
+ rb_commons-0.1.16.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
14
+ rb_commons-0.1.16.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
15
+ rb_commons-0.1.16.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (76.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,13 +0,0 @@
1
- rb_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- rb_commons/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- rb_commons/configs/config.py,sha256=tpqC1V9PXx88m0N5L13WqkoalPUk6SthjxgL_lmf-lE,1439
4
- rb_commons/configs/injections.py,sha256=6B1EOgIGnkWv3UrFaV9PRgG0-CJAbLu1UZ3kq-SjPVU,273
5
- rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
7
- rb_commons/orm/managers.py,sha256=VopUw29sCXrPTriBALR9qwkG5yCu6BDHRgR7cCygNiE,6726
8
- rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- rb_commons/schemes/jwt.py,sha256=F66JJDhholuOPPzlKeoC6f1TL4gXg4oRUrV5yheNpyo,1675
10
- rb_commons-0.1.14.dist-info/METADATA,sha256=C9gd_r_xXK_-GzP7_VLj5xC5EQxfDkUJGT0AxGboHZc,6533
11
- rb_commons-0.1.14.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
12
- rb_commons-0.1.14.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
13
- rb_commons-0.1.14.dist-info/RECORD,,