rb-commons 0.1.14__tar.gz → 0.1.16__tar.gz
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-0.1.14 → rb_commons-0.1.16}/PKG-INFO +1 -1
- rb_commons-0.1.16/rb_commons/configs/injections.py +13 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/orm/managers.py +1 -1
- rb_commons-0.1.16/rb_commons/permissions/__init__.py +1 -0
- rb_commons-0.1.16/rb_commons/permissions/role_permissions.py +23 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons.egg-info/PKG-INFO +1 -1
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons.egg-info/SOURCES.txt +2 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/setup.py +1 -1
- rb_commons-0.1.14/rb_commons/configs/injections.py +0 -9
- {rb_commons-0.1.14 → rb_commons-0.1.16}/README.md +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/__init__.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/configs/__init__.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/configs/config.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/orm/__init__.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/orm/exceptions.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/schemes/__init__.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons/schemes/jwt.py +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons.egg-info/dependency_links.txt +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons.egg-info/requires.txt +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/rb_commons.egg-info/top_level.txt +0 -0
- {rb_commons-0.1.14 → rb_commons-0.1.16}/setup.cfg +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
from typing import Annotated
|
2
|
+
|
3
|
+
from rb_commons.permissions import IsAdmin, IsCustomer
|
4
|
+
from rb_commons.schemes.jwt import Claims
|
5
|
+
from fastapi import Request, Depends
|
6
|
+
|
7
|
+
|
8
|
+
async def get_claims(request: Request) -> Claims:
|
9
|
+
return Claims.from_headers(dict(request.headers))
|
10
|
+
|
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
|
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
|
@@ -12,5 +12,7 @@ rb_commons/configs/injections.py
|
|
12
12
|
rb_commons/orm/__init__.py
|
13
13
|
rb_commons/orm/exceptions.py
|
14
14
|
rb_commons/orm/managers.py
|
15
|
+
rb_commons/permissions/__init__.py
|
16
|
+
rb_commons/permissions/role_permissions.py
|
15
17
|
rb_commons/schemes/__init__.py
|
16
18
|
rb_commons/schemes/jwt.py
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
5
|
|
6
6
|
setup(
|
7
7
|
name="rb-commons",
|
8
|
-
version="0.1.
|
8
|
+
version="0.1.16",
|
9
9
|
author="Abdulvoris",
|
10
10
|
author_email="erkinovabdulvoris101@gmail.com",
|
11
11
|
description="Commons of project and simplified orm based on sqlalchemy.",
|
@@ -1,9 +0,0 @@
|
|
1
|
-
from typing import Annotated
|
2
|
-
from rb_commons.schemes.jwt import Claims
|
3
|
-
from fastapi import Request, Depends
|
4
|
-
|
5
|
-
|
6
|
-
async def get_claims(request: Request) -> Claims:
|
7
|
-
return Claims.from_headers(dict(request.headers))
|
8
|
-
|
9
|
-
ClaimsDep = Annotated[Claims, Depends(get_claims)]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|