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.
- rb_commons/configs/injections.py +5 -1
 - rb_commons/orm/managers.py +1 -1
 - rb_commons/permissions/__init__.py +1 -0
 - rb_commons/permissions/role_permissions.py +23 -0
 - {rb_commons-0.1.14.dist-info → rb_commons-0.1.16.dist-info}/METADATA +1 -1
 - rb_commons-0.1.16.dist-info/RECORD +15 -0
 - {rb_commons-0.1.14.dist-info → rb_commons-0.1.16.dist-info}/WHEEL +1 -1
 - rb_commons-0.1.14.dist-info/RECORD +0 -13
 - {rb_commons-0.1.14.dist-info → rb_commons-0.1.16.dist-info}/top_level.txt +0 -0
 
    
        rb_commons/configs/injections.py
    CHANGED
    
    | 
         @@ -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())]
         
     | 
    
        rb_commons/orm/managers.py
    CHANGED
    
    | 
         @@ -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
         
     | 
| 
         @@ -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,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,,
         
     | 
| 
         
            File without changes
         
     |