sharedkernel 2.9.1__py3-none-any.whl → 2.9.3__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.
- sharedkernel/enum/user_role.py +16 -0
- sharedkernel/objects/user_workspace.py +13 -0
- sharedkernel/toolbox_service.py +18 -2
- {sharedkernel-2.9.1.dist-info → sharedkernel-2.9.3.dist-info}/METADATA +4 -2
- {sharedkernel-2.9.1.dist-info → sharedkernel-2.9.3.dist-info}/RECORD +7 -5
- {sharedkernel-2.9.1.dist-info → sharedkernel-2.9.3.dist-info}/WHEEL +0 -0
- {sharedkernel-2.9.1.dist-info → sharedkernel-2.9.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Role(str, Enum):
|
|
5
|
+
ADMIN = "admin"
|
|
6
|
+
MANAGER = "manager"
|
|
7
|
+
EDITOR = "editor"
|
|
8
|
+
VIEWER = "viewer"
|
|
9
|
+
OPERATOR = "operator"
|
|
10
|
+
|
|
11
|
+
class RoleFa(str, Enum):
|
|
12
|
+
ADMIN = "ادمین"
|
|
13
|
+
MANAGER = "مدیر"
|
|
14
|
+
EDITOR = "ویرایشگر"
|
|
15
|
+
VIEWER = "بیننده"
|
|
16
|
+
OPERATOR = "اپراتور"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from sharedkernel.objects.base_document import BaseDocument
|
|
2
|
+
from pydantic import BaseModel, RootModel
|
|
3
|
+
from sharedkernel.enum.user_role import Role
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class UserWorkspace(BaseDocument):
|
|
7
|
+
user_id: str
|
|
8
|
+
workspace_id: str | None = None
|
|
9
|
+
is_owner: bool | None = None
|
|
10
|
+
role: Role = Role.ADMIN
|
|
11
|
+
|
|
12
|
+
class UserWorkspaces(RootModel[list[UserWorkspace]]):
|
|
13
|
+
pass
|
sharedkernel/toolbox_service.py
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
from typing import Type
|
|
2
2
|
from pydantic import BaseModel
|
|
3
3
|
import aiohttp
|
|
4
|
+
from typing import List
|
|
4
5
|
|
|
5
6
|
from sharedkernel.objects.result import Result
|
|
6
7
|
from sharedkernel.enum import FeatureKey, PlanType
|
|
7
8
|
from sharedkernel.enum import ErrorCode
|
|
8
9
|
from sharedkernel.objects.subscription import Subscription
|
|
10
|
+
from sharedkernel.objects.user_workspace import UserWorkspace
|
|
9
11
|
from sharedkernel.exception.exception import BusinessException
|
|
12
|
+
from sharedkernel.database.cache.cache_repository import CacheRepository
|
|
13
|
+
from sharedkernel.enum.user_role import Role
|
|
14
|
+
from sharedkernel.objects.user_info import current_user_info
|
|
10
15
|
|
|
11
16
|
|
|
12
17
|
class ToolboxService:
|
|
13
|
-
def __init__(self, cache):
|
|
18
|
+
def __init__(self, cache: CacheRepository | None = None):
|
|
14
19
|
self.cache = cache
|
|
15
20
|
|
|
16
21
|
async def send_request(
|
|
@@ -32,6 +37,10 @@ class ToolboxService:
|
|
|
32
37
|
headers=headers,
|
|
33
38
|
) as response:
|
|
34
39
|
|
|
40
|
+
if not response.ok:
|
|
41
|
+
print(f"API Request to {endpoint} Failed: {response.status} {response.text}")
|
|
42
|
+
raise BusinessException(error_code=ErrorCode.Internal_Server)
|
|
43
|
+
|
|
35
44
|
response_data = await response.json()
|
|
36
45
|
return Result(
|
|
37
46
|
**response_data,
|
|
@@ -67,4 +76,11 @@ class ToolboxService:
|
|
|
67
76
|
if _feature.feature_key == feature:
|
|
68
77
|
if _feature.remaining - quantity < 0:
|
|
69
78
|
raise BusinessException(error_code=feature_errors[feature])
|
|
70
|
-
break
|
|
79
|
+
break
|
|
80
|
+
|
|
81
|
+
def check_access_level(self, allowed_roles: List[Role], user_workspace: UserWorkspace):
|
|
82
|
+
if user_workspace is None:
|
|
83
|
+
raise BusinessException(ErrorCode.Workspace_Access_Denied)
|
|
84
|
+
|
|
85
|
+
if user_workspace.role not in allowed_roles and user_workspace.role != Role.ADMIN:
|
|
86
|
+
raise BusinessException(ErrorCode.User_Access_Denied)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.9.
|
|
3
|
+
Version: 2.9.3
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -32,8 +32,10 @@ Dynamic: summary
|
|
|
32
32
|
this is a shared kernel package
|
|
33
33
|
|
|
34
34
|
# Change Log
|
|
35
|
+
### Version 2.9.3
|
|
36
|
+
- add token to user info
|
|
35
37
|
### Version 2.9.1
|
|
36
|
-
-
|
|
38
|
+
- add check_access_level to toolbox
|
|
37
39
|
### Version 2.9.0
|
|
38
40
|
- Add toolbox_service
|
|
39
41
|
### Version 2.8.0
|
|
@@ -10,7 +10,7 @@ sharedkernel/multipart_upload.py,sha256=JVlCBlznB9dWh2_spjAqzLOqQT1CHUTvrR4m7ug8
|
|
|
10
10
|
sharedkernel/regex_masking.py,sha256=zQrgteP8Cuq1EC9B7QUJqAXUxK9ISD9kWMYK2AbRfw0,3288
|
|
11
11
|
sharedkernel/s3_uploader.py,sha256=VWgN-RVHmLXMDuxgZux3M-iFwWk5zhRnUIECKS0auW4,3637
|
|
12
12
|
sharedkernel/string_extentions.py,sha256=ld02W06gd0Ql80GQU6nlqPAeUSfOe2Yr8cCzf3lJgQY,98
|
|
13
|
-
sharedkernel/toolbox_service.py,sha256
|
|
13
|
+
sharedkernel/toolbox_service.py,sha256=-vIJfKiAMzEcLPrBTqpErygZ56LaC1Edxdza6HyoMdo,3326
|
|
14
14
|
sharedkernel/chunker/chunk_rule.py,sha256=djxeQ3UvMx3_suH-heAQB0VwINT7uMfV7rnuuJChmwU,2531
|
|
15
15
|
sharedkernel/chunker/text_chunker.py,sha256=QL8rQjJX-7U9TXMWiQBPldb9h1EeEECmFwLF1JLoGAM,3146
|
|
16
16
|
sharedkernel/database/__init__.py,sha256=AtIbU7pDKwY6YCg_J8PX62WcYld1lAvBcVFW62MdiFg,241
|
|
@@ -32,6 +32,7 @@ sharedkernel/enum/plan_interval.py,sha256=Fn_E6NyswYa00OETE4E8wV8o4gNE7WfP6tsDxY
|
|
|
32
32
|
sharedkernel/enum/plan_type.py,sha256=ExcPl8wKTbRu1gYB7jZqweaj-K1F8HTXlCuxEOIvl3g,139
|
|
33
33
|
sharedkernel/enum/redis_mode_enum.py,sha256=v_n9g7_rq_pdMiZrC8mMveRcjgF3eBv3K2tsaV1Pidc,136
|
|
34
34
|
sharedkernel/enum/sort_order.py,sha256=T_1AknuVg2OSJMlIDkEiCUNHPW0yDnFvbzoNpTgG3-I,97
|
|
35
|
+
sharedkernel/enum/user_role.py,sha256=CnHCMHqgjsSNsldV8v6DNDWwoLKnHbnCeZE80dkX2rA,329
|
|
35
36
|
sharedkernel/exception/__init__.py,sha256=Yjkd1VsLFuzfWcMj-v8YYTA-vjtUlF4ESglBFeN1zvs,315
|
|
36
37
|
sharedkernel/exception/exception.py,sha256=TOxnymWJfhsrMmuLsG-amqJlDxmzznEfRnqDBe1vizk,1016
|
|
37
38
|
sharedkernel/exception/exception_handlers.py,sha256=VHEYaf1quaf63w_JCsNWFbMs2TxqmQqqlL4yGt1OjXI,3302
|
|
@@ -52,7 +53,8 @@ sharedkernel/objects/jwt_model.py,sha256=XQHQhTbg7PT8XiUh5fd9MwRH4ldPsesI_hfbjaS
|
|
|
52
53
|
sharedkernel/objects/result.py,sha256=I_9hX5TPEO1oStzuFLjFh1rtimXorz7ml-OaW_2BMvc,680
|
|
53
54
|
sharedkernel/objects/subscription.py,sha256=9MT2Vu-cf8ozO4pwh00ovk6aRNMjbJboKP8NkJgeSRI,1043
|
|
54
55
|
sharedkernel/objects/user_info.py,sha256=A6b0M1aQJLnhtEIkgnPpo_mWJ7v6ZqafT7tOhRGrExA,315
|
|
55
|
-
sharedkernel
|
|
56
|
-
sharedkernel-2.9.
|
|
57
|
-
sharedkernel-2.9.
|
|
58
|
-
sharedkernel-2.9.
|
|
56
|
+
sharedkernel/objects/user_workspace.py,sha256=npmkAdfLQkPhkINbSAGfmnSa279I-YjgtBR7zboXTds,362
|
|
57
|
+
sharedkernel-2.9.3.dist-info/METADATA,sha256=gnoPEJ4EXFVpno4TJKP2rF_Cyqz1878iGXWKcQCP2VA,4292
|
|
58
|
+
sharedkernel-2.9.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
59
|
+
sharedkernel-2.9.3.dist-info/top_level.txt,sha256=TVTOnV1MItSSlpSjqkiijuHkoVsGHS4CArpsM-lylkE,13
|
|
60
|
+
sharedkernel-2.9.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|