nlbone 0.7.26__py3-none-any.whl → 0.7.28__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.
- nlbone/adapters/i18n/__init__.py +7 -0
- nlbone/adapters/i18n/locales/{fa.json → fa-IR.json} +5 -0
- nlbone/container.py +0 -4
- nlbone/core/ports/translation.py +3 -0
- nlbone/interfaces/api/dependencies/async_auth.py +13 -1
- nlbone/interfaces/api/exception_handlers.py +2 -1
- nlbone/utils/context.py +1 -1
- {nlbone-0.7.26.dist-info → nlbone-0.7.28.dist-info}/METADATA +1 -1
- {nlbone-0.7.26.dist-info → nlbone-0.7.28.dist-info}/RECORD +12 -12
- {nlbone-0.7.26.dist-info → nlbone-0.7.28.dist-info}/WHEEL +0 -0
- {nlbone-0.7.26.dist-info → nlbone-0.7.28.dist-info}/entry_points.txt +0 -0
- {nlbone-0.7.26.dist-info → nlbone-0.7.28.dist-info}/licenses/LICENSE +0 -0
nlbone/adapters/i18n/__init__.py
CHANGED
nlbone/container.py
CHANGED
|
@@ -14,8 +14,6 @@ from nlbone.adapters.db.postgres.engine import get_async_session_factory, get_sy
|
|
|
14
14
|
from nlbone.adapters.http_clients import PricingService
|
|
15
15
|
from nlbone.adapters.http_clients.uploadchi import UploadchiClient
|
|
16
16
|
from nlbone.adapters.http_clients.uploadchi.uploadchi_async import UploadchiAsyncClient
|
|
17
|
-
from nlbone.adapters.i18n.engine import I18nAdapter
|
|
18
|
-
from nlbone.adapters.i18n.loaders import JSONFileLoader
|
|
19
17
|
from nlbone.core.ports.auth import AuthService
|
|
20
18
|
from nlbone.core.ports.cache import AsyncCachePort, CachePort
|
|
21
19
|
from nlbone.core.ports.files import AsyncFileServicePort, FileServicePort
|
|
@@ -55,8 +53,6 @@ class Container(containers.DeclarativeContainer):
|
|
|
55
53
|
redis=providers.Singleton(AsyncRedisCache, url=config.REDIS_URL),
|
|
56
54
|
)
|
|
57
55
|
|
|
58
|
-
translator = I18nAdapter(loader=JSONFileLoader(locales_path="path/to/locales"), default_locale="fa")
|
|
59
|
-
|
|
60
56
|
|
|
61
57
|
def create_container(settings: Optional[BaseSettings | Dict] = None) -> Container:
|
|
62
58
|
c = Container()
|
nlbone/core/ports/translation.py
CHANGED
|
@@ -6,3 +6,6 @@ class TranslationPort(ABC):
|
|
|
6
6
|
@abstractmethod
|
|
7
7
|
def translate(self, key: str, locale: Optional[str] = None, **kwargs) -> str:
|
|
8
8
|
pass
|
|
9
|
+
|
|
10
|
+
def __call__(self, key: str, locale: Optional[str] = None, **kwargs) -> Optional[str]:
|
|
11
|
+
return self.translate(key, locale, **kwargs)
|
|
@@ -4,7 +4,7 @@ from nlbone.adapters.auth import KeycloakAuthService
|
|
|
4
4
|
from nlbone.interfaces.api.exceptions import ForbiddenException, UnauthorizedException
|
|
5
5
|
from nlbone.utils.context import current_request
|
|
6
6
|
|
|
7
|
-
from .auth import client_has_access_func
|
|
7
|
+
from .auth import client_has_access_func, client_or_user_has_access_func
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
async def current_user_id() -> int:
|
|
@@ -58,3 +58,15 @@ def has_access(*, permissions=None):
|
|
|
58
58
|
return wrapper
|
|
59
59
|
|
|
60
60
|
return decorator
|
|
61
|
+
|
|
62
|
+
def client_or_user_has_access(*, permissions=None, client_permissions=None):
|
|
63
|
+
def decorator(func):
|
|
64
|
+
@functools.wraps(func)
|
|
65
|
+
async def wrapper(*args, **kwargs):
|
|
66
|
+
client_or_user_has_access_func(permissions=permissions, client_permissions=client_permissions)
|
|
67
|
+
return await func(*args, **kwargs)
|
|
68
|
+
|
|
69
|
+
return wrapper
|
|
70
|
+
|
|
71
|
+
return decorator
|
|
72
|
+
|
|
@@ -12,6 +12,7 @@ from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
|
12
12
|
|
|
13
13
|
from .exceptions import BaseHttpException
|
|
14
14
|
|
|
15
|
+
from nlbone.adapters.i18n import translator as _
|
|
15
16
|
# ---- Helpers ---------------------------------------------------------------
|
|
16
17
|
|
|
17
18
|
|
|
@@ -59,7 +60,7 @@ def install_exception_handlers(
|
|
|
59
60
|
"http_error",
|
|
60
61
|
extra={"status": exc.status_code, "detail": exc.detail, "path": request.url.path},
|
|
61
62
|
)
|
|
62
|
-
return _json_response(request, exc.status_code, detail=exc.detail)
|
|
63
|
+
return _json_response(request, exc.status_code, detail=_(exc.detail))
|
|
63
64
|
|
|
64
65
|
@app.exception_handler(FastAPIHTTPException)
|
|
65
66
|
async def _handle_fastapi_http_exception(request: Request, exc: FastAPIHTTPException):
|
nlbone/utils/context.py
CHANGED
|
@@ -6,7 +6,7 @@ request_id_ctx: ContextVar[str | None] = ContextVar("request_id", default=None)
|
|
|
6
6
|
user_id_ctx: ContextVar[str | None] = ContextVar("user_id", default=None)
|
|
7
7
|
ip_ctx: ContextVar[str | None] = ContextVar("ip", default=None)
|
|
8
8
|
user_agent_ctx: ContextVar[str | None] = ContextVar("user_agent", default=None)
|
|
9
|
-
_current_locale: ContextVar[str] = ContextVar("current_locale"
|
|
9
|
+
_current_locale: ContextVar[str] = ContextVar("current_locale")
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def bind_context(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
nlbone/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
nlbone/container.py,sha256=
|
|
2
|
+
nlbone/container.py,sha256=VSc72QBllFzW_3kj5znRkqnmK3WZvez404S13kb9ifw,2748
|
|
3
3
|
nlbone/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
nlbone/adapters/__init__.py,sha256=NzUmk4XPyp3GJOw7VSE86xkQMZLtG3MrOoXLeoB551M,41
|
|
5
5
|
nlbone/adapters/snowflake.py,sha256=eC5eXWgkTIJlO5J44VFbD1-MXj8HYs0lCNp37paSfXY,2324
|
|
@@ -30,10 +30,10 @@ nlbone/adapters/http_clients/pricing/pricing_service.py,sha256=_15vyEwJD3S2DJG-y
|
|
|
30
30
|
nlbone/adapters/http_clients/uploadchi/__init__.py,sha256=uBzEOuVtY22teWW2b36Pitkdk5yVdSqa6xbg22JfTNg,105
|
|
31
31
|
nlbone/adapters/http_clients/uploadchi/uploadchi.py,sha256=erpjOees25FW0nuK1PkYS-oU0h8MeRV9Rhs1cf3gaEs,4881
|
|
32
32
|
nlbone/adapters/http_clients/uploadchi/uploadchi_async.py,sha256=PQbVNeaYde5CmgT3vcnQoI1PGeSs9AxHlPFuB8biOmU,4717
|
|
33
|
-
nlbone/adapters/i18n/__init__.py,sha256=
|
|
33
|
+
nlbone/adapters/i18n/__init__.py,sha256=19C_u8ZzWLQRfhG96FmEyk9x3pP9Iv8yEk59Or7UMU8,257
|
|
34
34
|
nlbone/adapters/i18n/engine.py,sha256=f_nxxy-_T5CITnPp3vnxBl0hZZ8MSn0aA-PzajSx_dQ,908
|
|
35
35
|
nlbone/adapters/i18n/loaders.py,sha256=Qz2B8YFaYx8u5OusO4Vo2zCwvnnVfTH7fetAOJZiK3c,1778
|
|
36
|
-
nlbone/adapters/i18n/locales/fa.json,sha256=
|
|
36
|
+
nlbone/adapters/i18n/locales/fa-IR.json,sha256=SMShgJErN-tDLOSH3hAsjg08O8GPlDfDVyFGjIUQpGU,340
|
|
37
37
|
nlbone/adapters/messaging/__init__.py,sha256=o6ZiMihm_MhRXfcEpcjHBB3JGQovQbg3pxe0qS6516c,41
|
|
38
38
|
nlbone/adapters/messaging/event_bus.py,sha256=MSM70JPHoDK17efWlh20ATT1O0KW7xWnwZ5D-gI6U_w,3773
|
|
39
39
|
nlbone/adapters/messaging/rabbitmq.py,sha256=Io3flSj8DMIHExJguh3hDgWT4LuDoPYb_xmQQ3k47Cs,1894
|
|
@@ -66,11 +66,11 @@ nlbone/core/ports/event_bus.py,sha256=7iC8WRBg-EmcKJx7AVPkP-r823SLKGuDxGp9WF4q-_
|
|
|
66
66
|
nlbone/core/ports/files.py,sha256=7Ov2ITYRpPwwDTZGCeNVISg8e3A9l08jbOgpTImgfK8,1863
|
|
67
67
|
nlbone/core/ports/outbox.py,sha256=ZSgADjOpn2fgrUTDy-d-2WTc2Yuk4dRm5dzaGDsG6w4,2142
|
|
68
68
|
nlbone/core/ports/repository.py,sha256=Ee8iSt4WxUIt113zLd7hq0HwtHc8r8qRSFBMTiGuJq4,2822
|
|
69
|
-
nlbone/core/ports/translation.py,sha256=
|
|
69
|
+
nlbone/core/ports/translation.py,sha256=pnqbxhdRCR7eprm8UI8ZKKx7VDUPntvBtlytrnTGkrc,354
|
|
70
70
|
nlbone/core/ports/uow.py,sha256=VhqSc-Ryt9m-rlNMiXTzD3dPGz6mM_JxND8D0UJGRu4,962
|
|
71
71
|
nlbone/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
72
|
nlbone/interfaces/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
73
|
-
nlbone/interfaces/api/exception_handlers.py,sha256=
|
|
73
|
+
nlbone/interfaces/api/exception_handlers.py,sha256=pk7ehq15fZ6If57BvDjo_Ot-R5hTEFMhBP5KDwp61AM,4102
|
|
74
74
|
nlbone/interfaces/api/exceptions.py,sha256=Phv0nXaEHCgJVEAuQ2q8QHxpn_diXahKarupSHOATY0,2964
|
|
75
75
|
nlbone/interfaces/api/routers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
76
76
|
nlbone/interfaces/api/schemas.py,sha256=NIEKeTdJtwwIkIxL7WURNZF8g34I4TlRAqs-x1Uq7YI,108
|
|
@@ -81,7 +81,7 @@ nlbone/interfaces/api/additional_filed/resolver.py,sha256=jv1TIBBHN4LBIMwHGipcy4
|
|
|
81
81
|
nlbone/interfaces/api/additional_filed/default_field_rules/__init__.py,sha256=LUSAOO3xRUt5ptlraIx7H-7dSkdr1D-WprmnqXRB16g,48
|
|
82
82
|
nlbone/interfaces/api/additional_filed/default_field_rules/image_field_rules.py,sha256=ecKqPeXZ-YiF14RK9PmK7ln3PCzpCUc18S5zm5IF3fw,339
|
|
83
83
|
nlbone/interfaces/api/dependencies/__init__.py,sha256=rnYRrFVZCfICQrp_PVFlzNg3BeC57yM08wn2DbOHCfk,359
|
|
84
|
-
nlbone/interfaces/api/dependencies/async_auth.py,sha256=
|
|
84
|
+
nlbone/interfaces/api/dependencies/async_auth.py,sha256=uQV36yk7s7SVsnwuA3eZ2NfqqVOe0vPFOSLuZcVsS8s,2122
|
|
85
85
|
nlbone/interfaces/api/dependencies/auth.py,sha256=GGhXTUG0J_VHOjsQTBFpxHQV1OvT6RIGo2Jvj9IwQ6E,3310
|
|
86
86
|
nlbone/interfaces/api/dependencies/client_credential.py,sha256=Bo4dYx75Qw0JzTKD9ZfV5EXDEOuwndJk2D-V37K2ePg,1293
|
|
87
87
|
nlbone/interfaces/api/dependencies/db.py,sha256=-UD39J_86UU7ZJs2ZncpdND0yhAG0NeeeALrgSDuuFw,466
|
|
@@ -107,15 +107,15 @@ nlbone/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
107
107
|
nlbone/utils/cache.py,sha256=KHUYjhIo6dbaSdY9RjbxUJQlLMdacMLjdDm5QZ5dLUw,7305
|
|
108
108
|
nlbone/utils/cache_keys.py,sha256=Y2YSellHTbUOcoaNbl1jaD4r485VU_e4KXsfBWhYTBo,1075
|
|
109
109
|
nlbone/utils/cache_registry.py,sha256=3FWYyhujW8oPBiVUPzk1CqJ3jJfxs9729Sbb1pQ5Fag,707
|
|
110
|
-
nlbone/utils/context.py,sha256=
|
|
110
|
+
nlbone/utils/context.py,sha256=Wq3QLYsMzo_xUiVAHLgEPQUG6LhgJTmFn8MO5Qa7S8w,1837
|
|
111
111
|
nlbone/utils/crypto.py,sha256=PX0Tlf2nqXcGbuv16J26MoUPzo2c4xcD4sZBXxhBXgQ,746
|
|
112
112
|
nlbone/utils/flatten_sqlalchemy_result.py,sha256=JGwQEauoJVjhzvXrOtqabj3wQ7zp2-OPwhuh44sUdUE,625
|
|
113
113
|
nlbone/utils/http.py,sha256=0yeI34j5FfelqvX3PJnKknSXji1jl15VYbVIIvrSbXg,997
|
|
114
114
|
nlbone/utils/normalize_mobile.py,sha256=sGH4tV9gX-6eVKozviNWJhm1DN1J28Nj-ERldCYkS_E,732
|
|
115
115
|
nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
|
|
116
116
|
nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
|
|
117
|
-
nlbone-0.7.
|
|
118
|
-
nlbone-0.7.
|
|
119
|
-
nlbone-0.7.
|
|
120
|
-
nlbone-0.7.
|
|
121
|
-
nlbone-0.7.
|
|
117
|
+
nlbone-0.7.28.dist-info/METADATA,sha256=px1B_Kvd923agUHScPD1lRerGtdjdMVsrHbCZKv5OiI,2295
|
|
118
|
+
nlbone-0.7.28.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
119
|
+
nlbone-0.7.28.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
|
|
120
|
+
nlbone-0.7.28.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
121
|
+
nlbone-0.7.28.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|