sharedkernel 2.11.2__tar.gz → 2.12.0__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.
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/PKG-INFO +5 -1
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/README.md +163 -159
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/setup.py +1 -1
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/config.py +8 -1
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/distributed_cache.py +4 -4
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/__init__.py +2 -1
- sharedkernel-2.12.0/sharedkernel/enum/permission.py +91 -0
- sharedkernel-2.12.0/sharedkernel/objects/user_permissions.py +5 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/s3_uploader.py +56 -15
- sharedkernel-2.12.0/sharedkernel/toolbox_service.py +148 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel.egg-info/PKG-INFO +5 -1
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel.egg-info/SOURCES.txt +2 -0
- sharedkernel-2.11.2/sharedkernel/toolbox_service.py +0 -86
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/setup.cfg +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/chunker/chunk_rule.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/chunker/text_chunker.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/common.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/data_format_converter.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/__init__.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/audit_model.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/cache/__init__.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/cache/cache_repository.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/cache/redis_generic_cache.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/mongo_generic_audit_repository.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/mongo_generic_repository.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/mongo_health_checker.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/pagination_response_dto.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/date_converter.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/diff_utils.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/encryption_service.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/error_code.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/feature_display_type.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/feature_key.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/order_type.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/plan_interval.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/plan_type.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/redis_mode_enum.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/sort_order.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/enum/user_role.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/file_validation.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/ip_session_service.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/log_decorator.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/log_dto.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/log_enums.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/log_info.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/log_middlewares.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/logger/logger_service.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/multipart_upload.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/normalizer/__init__.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/normalizer/number_normalizer.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/normalizer/string_normalizer.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/base_document.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/json_string_model.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/result.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/subscription.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/user_info.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/objects/user_workspace.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel.egg-info/requires.txt +0 -0
- {sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.12.0
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -33,6 +33,10 @@ Dynamic: summary
|
|
|
33
33
|
this is a shared kernel package
|
|
34
34
|
|
|
35
35
|
# Change Log
|
|
36
|
+
### Version 2.12.0
|
|
37
|
+
- implement user access level version and check permission
|
|
38
|
+
### Version 2.11.3
|
|
39
|
+
- Add S3Uploader.download, which reads an object from S3 using its URL
|
|
36
40
|
### Version 2.11.2
|
|
37
41
|
- Minor fix versioning
|
|
38
42
|
### Version 2.11.1
|
|
@@ -1,159 +1,163 @@
|
|
|
1
|
-
# SharedKernel
|
|
2
|
-
this is a shared kernel package
|
|
3
|
-
|
|
4
|
-
# Change Log
|
|
5
|
-
### Version 2.
|
|
6
|
-
-
|
|
7
|
-
### Version 2.11.
|
|
8
|
-
-
|
|
9
|
-
### Version 2.11.
|
|
10
|
-
-
|
|
11
|
-
### Version 2.
|
|
12
|
-
-
|
|
13
|
-
### Version 2.
|
|
14
|
-
-
|
|
15
|
-
### Version 2.
|
|
16
|
-
-
|
|
17
|
-
### Version 2.9.
|
|
18
|
-
-
|
|
19
|
-
### Version 2.9.
|
|
20
|
-
-
|
|
21
|
-
### Version 2.9.
|
|
22
|
-
-
|
|
23
|
-
### Version 2.
|
|
24
|
-
-
|
|
25
|
-
### Version 2.
|
|
26
|
-
- Add
|
|
27
|
-
### Version 2.
|
|
28
|
-
- Add
|
|
29
|
-
### Version 2.
|
|
30
|
-
-
|
|
31
|
-
### Version 2.6.
|
|
32
|
-
- Add Verbose
|
|
33
|
-
### Version 2.6.
|
|
34
|
-
-
|
|
35
|
-
### Version 2.6.
|
|
36
|
-
-
|
|
37
|
-
### Version 2.
|
|
38
|
-
-
|
|
39
|
-
### Version 2.
|
|
40
|
-
-
|
|
41
|
-
### Version 2.5.
|
|
42
|
-
-
|
|
43
|
-
### Version 2.5.
|
|
44
|
-
-
|
|
45
|
-
### Version 2.5.
|
|
46
|
-
-
|
|
47
|
-
### Version 2.5.
|
|
48
|
-
-
|
|
49
|
-
### Version 2.5.
|
|
50
|
-
-
|
|
51
|
-
### Version 2.5.
|
|
52
|
-
-
|
|
53
|
-
### Version 2.5.
|
|
54
|
-
-
|
|
55
|
-
### Version 2.5.
|
|
56
|
-
-
|
|
57
|
-
### Version 2.
|
|
58
|
-
-
|
|
59
|
-
### Version 2.
|
|
60
|
-
- Implement
|
|
61
|
-
### Version 2.
|
|
62
|
-
-
|
|
63
|
-
### Version 2.
|
|
64
|
-
-
|
|
65
|
-
### Version 2.
|
|
66
|
-
-
|
|
67
|
-
### Version 2.2.
|
|
68
|
-
- add
|
|
69
|
-
### Version 2.2.
|
|
70
|
-
-
|
|
71
|
-
### Version 2.2.
|
|
72
|
-
- add
|
|
73
|
-
### Version 2.2.
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
-
|
|
80
|
-
### Version 2.1
|
|
81
|
-
-
|
|
82
|
-
### Version 2.
|
|
83
|
-
-
|
|
84
|
-
### Version 2.
|
|
85
|
-
-
|
|
86
|
-
### Version 2.0
|
|
87
|
-
-
|
|
88
|
-
### Version 2.0.
|
|
89
|
-
- Fix
|
|
90
|
-
### Version 2.0.
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
-
|
|
94
|
-
### Version
|
|
95
|
-
-
|
|
96
|
-
|
|
97
|
-
- Implement
|
|
98
|
-
### Version 1.
|
|
99
|
-
-
|
|
100
|
-
### Version 1.
|
|
101
|
-
-
|
|
102
|
-
### Version 1.7.
|
|
103
|
-
-
|
|
104
|
-
### Version 1.7.
|
|
105
|
-
-
|
|
106
|
-
### Version 1.
|
|
107
|
-
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
### Version 1.6.
|
|
114
|
-
-
|
|
115
|
-
### Version 1.6.
|
|
116
|
-
- Fix
|
|
117
|
-
### Version 1.6.
|
|
118
|
-
-
|
|
119
|
-
### Version 1.6.
|
|
120
|
-
-
|
|
121
|
-
### Version 1.6.
|
|
122
|
-
-
|
|
123
|
-
### Version 1.6.
|
|
124
|
-
-
|
|
125
|
-
### Version 1.6.
|
|
126
|
-
-
|
|
127
|
-
### Version 1.6
|
|
128
|
-
-
|
|
129
|
-
### Version 1.
|
|
130
|
-
-
|
|
131
|
-
### Version 1.
|
|
132
|
-
-
|
|
133
|
-
### Version 1.5.
|
|
134
|
-
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
-
|
|
140
|
-
### Version 1.4.
|
|
141
|
-
-
|
|
142
|
-
### Version 1.4.
|
|
143
|
-
- Fix
|
|
144
|
-
### Version 1.4.
|
|
145
|
-
- Fix
|
|
146
|
-
### Version 1.4.
|
|
147
|
-
-
|
|
148
|
-
### Version 1.
|
|
149
|
-
-
|
|
150
|
-
### Version 1.
|
|
151
|
-
- Implement
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
pip install
|
|
1
|
+
# SharedKernel
|
|
2
|
+
this is a shared kernel package
|
|
3
|
+
|
|
4
|
+
# Change Log
|
|
5
|
+
### Version 2.12.0
|
|
6
|
+
- implement user access level version and check permission
|
|
7
|
+
### Version 2.11.3
|
|
8
|
+
- Add S3Uploader.download, which reads an object from S3 using its URL
|
|
9
|
+
### Version 2.11.2
|
|
10
|
+
- Minor fix versioning
|
|
11
|
+
### Version 2.11.1
|
|
12
|
+
- Fix event name field
|
|
13
|
+
### Version 2.11.0
|
|
14
|
+
- Add router name to log service
|
|
15
|
+
### Version 2.10.0
|
|
16
|
+
- implement encryption service
|
|
17
|
+
### Version 2.9.5
|
|
18
|
+
- remove redis fixed version
|
|
19
|
+
### Version 2.9.4
|
|
20
|
+
- fix bug
|
|
21
|
+
### Version 2.9.2
|
|
22
|
+
- add check_access_level to toolbox
|
|
23
|
+
### Version 2.9.1
|
|
24
|
+
- add check_access_level to toolbox
|
|
25
|
+
### Version 2.9.0
|
|
26
|
+
- Add toolbox_service
|
|
27
|
+
### Version 2.8.0
|
|
28
|
+
- Add chunker for tts
|
|
29
|
+
### Version 2.7.0
|
|
30
|
+
- Add Redis and cache repository
|
|
31
|
+
### Version 2.6.4
|
|
32
|
+
- Add Verbose to log
|
|
33
|
+
### Version 2.6.3
|
|
34
|
+
- fix bug ip-header-name
|
|
35
|
+
### Version 2.6.2
|
|
36
|
+
- Add Verbose
|
|
37
|
+
### Version 2.6.1
|
|
38
|
+
- hotfix namings
|
|
39
|
+
### Version 2.6.0
|
|
40
|
+
- add cookie validation to jwt service
|
|
41
|
+
### Version 2.5.9
|
|
42
|
+
- Fix bug
|
|
43
|
+
### Version 2.5.8
|
|
44
|
+
- Add Session Lifetime Update
|
|
45
|
+
### Version 2.5.7
|
|
46
|
+
- Add Database Health Check
|
|
47
|
+
### Version 2.5.6
|
|
48
|
+
- fix bug
|
|
49
|
+
### Version 2.5.5
|
|
50
|
+
- fix bug
|
|
51
|
+
### Version 2.5.4
|
|
52
|
+
- Add Ip Session Service
|
|
53
|
+
### Version 2.5.3
|
|
54
|
+
- Fix bug
|
|
55
|
+
### Version 2.5.2
|
|
56
|
+
- Minor Fix
|
|
57
|
+
### Version 2.5.1
|
|
58
|
+
- Apply log on jwt service
|
|
59
|
+
### Version 2.5.0
|
|
60
|
+
- Implement logger
|
|
61
|
+
### Version 2.4.1
|
|
62
|
+
- Fix file validation
|
|
63
|
+
### Version 2.4.0
|
|
64
|
+
- Implement file validation
|
|
65
|
+
### Version 2.3.0
|
|
66
|
+
- Implement multipart uploader for S3
|
|
67
|
+
### Version 2.2.7
|
|
68
|
+
- add presigned url in s3 uploader
|
|
69
|
+
### Version 2.2.6
|
|
70
|
+
- implement api key
|
|
71
|
+
### Version 2.2.5
|
|
72
|
+
- add org_token to user_info Object
|
|
73
|
+
### Version 2.2.4
|
|
74
|
+
- make pagination response default values to None
|
|
75
|
+
### Version 2.2.3
|
|
76
|
+
- add paginate to mongo repository
|
|
77
|
+
### Version 2.2.2
|
|
78
|
+
- update on audit logging queries
|
|
79
|
+
- added is_audit to update_one parameters
|
|
80
|
+
### Version 2.2.1
|
|
81
|
+
- fixbug requirements
|
|
82
|
+
### Version 2.2.0
|
|
83
|
+
- implement Audit logging
|
|
84
|
+
### Version 2.1.2
|
|
85
|
+
- Update pydantic parse_object with model_validate
|
|
86
|
+
### Version 2.1.0
|
|
87
|
+
- Implement persian string normalizer
|
|
88
|
+
### Version 2.0.3
|
|
89
|
+
- Fix boto3 version
|
|
90
|
+
### Version 2.0.2
|
|
91
|
+
- Fix FastApi dependency
|
|
92
|
+
### Version 2.0.1
|
|
93
|
+
- Fix minor bugs
|
|
94
|
+
### Version 2.0.0
|
|
95
|
+
- Update pydantic version
|
|
96
|
+
- Delete vector databases
|
|
97
|
+
- Implement JsonStringModel
|
|
98
|
+
### Version 1.9.0
|
|
99
|
+
- Implement DataFormatConverter
|
|
100
|
+
### Version 1.8.0
|
|
101
|
+
- Implement persian number normalizer
|
|
102
|
+
### Version 1.7.3
|
|
103
|
+
- Add optional folder name for s3 uploader to save the file in
|
|
104
|
+
### Version 1.7.2
|
|
105
|
+
- Fix bug of to_diff_persian_date_time_string
|
|
106
|
+
### Version 1.7.1
|
|
107
|
+
- Update BaseDocument initial values
|
|
108
|
+
### Version 1.7.0
|
|
109
|
+
- Implement S3 Uploader
|
|
110
|
+
### Version 1.6.10
|
|
111
|
+
- Add updated_on to BaseDocument
|
|
112
|
+
- Update phonenumber normalizer
|
|
113
|
+
### Version 1.6.9
|
|
114
|
+
- Delete milvus
|
|
115
|
+
### Version 1.6.8
|
|
116
|
+
- Fix Date Converter Bug
|
|
117
|
+
### Version 1.6.7
|
|
118
|
+
- Fix bug and remove additional features
|
|
119
|
+
### Version 1.6.6
|
|
120
|
+
- Fix bug of phonenumber normalizer
|
|
121
|
+
### Version 1.6.5
|
|
122
|
+
- Update on the JWTBearer (Save decoded token in request state)
|
|
123
|
+
### Version 1.6.4
|
|
124
|
+
- Update normlizer package
|
|
125
|
+
### Version 1.6.3
|
|
126
|
+
- Fix minor bug in phone normalizer
|
|
127
|
+
### Version 1.6.2
|
|
128
|
+
- Minor update: normalize function name
|
|
129
|
+
### Version 1.6.1
|
|
130
|
+
- Minor update normalize functions
|
|
131
|
+
### Version 1.6
|
|
132
|
+
- Add phone number normalizer
|
|
133
|
+
### Version 1.5.2
|
|
134
|
+
- Add created_on to base_document
|
|
135
|
+
### Version 1.5.1
|
|
136
|
+
- fix mongo repository bug
|
|
137
|
+
### Version 1.5.0
|
|
138
|
+
- implement date converter
|
|
139
|
+
- example: فردا - دیروز - یک ماه قبل
|
|
140
|
+
### Version 1.4.5
|
|
141
|
+
- upgrade fastapi version
|
|
142
|
+
### Version 1.4.4
|
|
143
|
+
- Fix regex masking bugs
|
|
144
|
+
### Version 1.4.3
|
|
145
|
+
- Fix collection bug in MongoGenericRepository
|
|
146
|
+
### Version 1.4.2
|
|
147
|
+
- Fix minor bugs
|
|
148
|
+
### Version 1.4.1
|
|
149
|
+
- Fix minor bug in MongoGenericRepository
|
|
150
|
+
### Version 1.4.0
|
|
151
|
+
- Implement date convertor for jalali and georgian
|
|
152
|
+
### Version 1.3.0
|
|
153
|
+
- Implement Sentry For Log Exceptions
|
|
154
|
+
### Version 1.2.0
|
|
155
|
+
- Implement Regex Masking
|
|
156
|
+
# Create Package
|
|
157
|
+
python3 -m pip install --upgrade build
|
|
158
|
+
python3 -m build
|
|
159
|
+
python3 -m pip install --upgrade twine
|
|
160
|
+
python3 -m twine upload dist/*
|
|
161
|
+
|
|
162
|
+
# Pypi
|
|
163
|
+
pip install sharedkernel
|
|
@@ -44,7 +44,7 @@ setup(
|
|
|
44
44
|
"cryptography",
|
|
45
45
|
],
|
|
46
46
|
# *strongly* suggested for sharing
|
|
47
|
-
version="2.
|
|
47
|
+
version="2.12.0",
|
|
48
48
|
description="sharekernel is a shared package between all python projects",
|
|
49
49
|
long_description=long_description,
|
|
50
50
|
long_description_content_type="text/markdown",
|
|
@@ -34,4 +34,11 @@ CACHE_EXPIRE_TIME_HOURS = int(os.getenv("CACHE_EXPIRE_TIME_HOURS", 24))
|
|
|
34
34
|
REDIS_SENTINELS = os.getenv("REDIS_SENTINELS")
|
|
35
35
|
REDIS_MASTER_NAME = os.getenv("REDIS_MASTER_NAME")
|
|
36
36
|
REDIS_CLUSTER_NODES = os.getenv("REDIS_CLUSTER_NODES")
|
|
37
|
-
REDIS_MODE = os.getenv("REDIS_MODE") # sentinel / cluster / standalone
|
|
37
|
+
REDIS_MODE = os.getenv("REDIS_MODE") # sentinel / cluster / standalone
|
|
38
|
+
|
|
39
|
+
PRODUCTS_BASE_URL = os.getenv(
|
|
40
|
+
"PRODUCTS_BASE_URL",
|
|
41
|
+
"https://gateway-dev.hamhoush.ir/products/v1",
|
|
42
|
+
)
|
|
43
|
+
GET_PERMISSIONS_BASE_URL = os.getenv("GET_PERMISSIONS_BASE_URL", PRODUCTS_BASE_URL + "/internal/user-permissions")
|
|
44
|
+
USER_PERMISSIONS_CACHE_NAMESPACE = "user_permissions"
|
|
@@ -101,9 +101,9 @@ class DistributedCache(Generic[T]):
|
|
|
101
101
|
def _deserialize(self, raw: bytes) -> T:
|
|
102
102
|
return self.model.model_validate_json(raw.decode())
|
|
103
103
|
|
|
104
|
-
def set(self, key: str, value: T) ->
|
|
104
|
+
def set(self, key: str, value: T) -> bool:
|
|
105
105
|
if value is None:
|
|
106
|
-
return
|
|
106
|
+
return False
|
|
107
107
|
skey = self._pref(key)
|
|
108
108
|
payload = self._serialize(value)
|
|
109
109
|
self.client.set(skey, payload, ex=self.expire_time)
|
|
@@ -125,8 +125,8 @@ class DistributedCache(Generic[T]):
|
|
|
125
125
|
skey = self._pref(key)
|
|
126
126
|
return self.client.exists(skey)
|
|
127
127
|
|
|
128
|
-
def delete(self, key):
|
|
129
|
-
self.client.delete(key)
|
|
128
|
+
def delete(self, key: str) -> None:
|
|
129
|
+
self.client.delete(self._pref(key))
|
|
130
130
|
|
|
131
131
|
def delete_group(self, key_prefix: str):
|
|
132
132
|
pattern = f"{self.namespace}:{key_prefix}*"
|
|
@@ -4,4 +4,5 @@ from .feature_key import FeatureKey
|
|
|
4
4
|
from .plan_type import PlanType
|
|
5
5
|
from .plan_interval import PlanInterval
|
|
6
6
|
from .order_type import OrderType
|
|
7
|
-
from .feature_display_type import FeatureDisplayType
|
|
7
|
+
from .feature_display_type import FeatureDisplayType
|
|
8
|
+
from .permission import PermissionsEnum
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PermissionsEnum(str, Enum):
|
|
5
|
+
WORKSPACE_USAGE_VIEW = "workspace.usage.view"
|
|
6
|
+
WORKSPACE_SETTINGS_VIEW = "workspace.settings.view"
|
|
7
|
+
WORKSPACE_SETTINGS_EDIT = "workspace.settings.edit"
|
|
8
|
+
WORKSPACE_SETTINGS_DELETE = "workspace.settings.delete"
|
|
9
|
+
WORKSPACE_MEMBERS_VIEW = "workspace.members.view"
|
|
10
|
+
WORKSPACE_MEMBERS_INVITE = "workspace.members.invite"
|
|
11
|
+
WORKSPACE_MEMBERS_EDIT = "workspace.members.edit"
|
|
12
|
+
WORKSPACE_MEMBERS_SUSPEND = "workspace.members.suspend"
|
|
13
|
+
WORKSPACE_MEMBERS_REMOVE = "workspace.members.remove"
|
|
14
|
+
WORKSPACE_MEMBERS_ACTIVATE = "workspace.members.activate"
|
|
15
|
+
WORKSPACE_ROLES_VIEW = "workspace.roles.view"
|
|
16
|
+
WORKSPACE_ROLES_CREATE = "workspace.roles.create"
|
|
17
|
+
WORKSPACE_ROLES_EDIT = "workspace.roles.edit"
|
|
18
|
+
WORKSPACE_ROLES_DELETE = "workspace.roles.delete"
|
|
19
|
+
WORKSPACE_ROLES_CLONE = "workspace.roles.clone"
|
|
20
|
+
WORKSPACE_AUDIT_VIEW = "workspace.audit.view"
|
|
21
|
+
WORKSPACE_AUDIT_EXPORT = "workspace.audit.export"
|
|
22
|
+
PAYMENT_PLANS_VIEW = "payment.plans.view"
|
|
23
|
+
PAYMENT_PLANS_EDIT = "payment.plans.edit"
|
|
24
|
+
PAYMENT_PLANS_PURCHASE = "payment.plans.purchase"
|
|
25
|
+
PAYMENT_ADDON_PURCHASE = "payment.addon.purchase"
|
|
26
|
+
PAYMENT_HISTORY_VIEW = "payment.history.view"
|
|
27
|
+
FAQBOT_ANALYTICS_VIEW = "faqbot.analytics.view"
|
|
28
|
+
FAQBOT_ANALYTICS_EXPORT = "faqbot.analytics.export"
|
|
29
|
+
FAQBOT_CONVERSATION_VIEW = "faqbot.conversation.view"
|
|
30
|
+
FAQBOT_CONVERSATION_EXPORT = "faqbot.conversation.export"
|
|
31
|
+
FAQBOT_KNOWLEDGE_VIEW = "faqbot.knowledge.view"
|
|
32
|
+
FAQBOT_KNOWLEDGE_EDIT = "faqbot.knowledge.edit"
|
|
33
|
+
FAQBOT_BOT_DELETE = "faqbot.bot.delete"
|
|
34
|
+
FAQBOT_INTEGRATION_VIEW = "faqbot.integration.view"
|
|
35
|
+
FAQBOT_INTEGRATION_API_KEY_EDIT = "faqbot.integration.api_key.edit"
|
|
36
|
+
FAQBOT_APPEARANCE_VIEW = "faqbot.appearance.view"
|
|
37
|
+
FAQBOT_APPEARANCE_EDIT = "faqbot.appearance.edit"
|
|
38
|
+
FAQBOT_PROSETTINGS_VIEW = "faqbot.prosettings.view"
|
|
39
|
+
FAQBOT_PROSETTINGS_ASR_EDIT = "faqbot.prosettings.asr.edit"
|
|
40
|
+
FAQBOT_PROSETTINGS_TTS_EDIT = "faqbot.prosettings.tts.edit"
|
|
41
|
+
FAQBOT_PROSETTINGS_TONE_EDIT = "faqbot.prosettings.tone.edit"
|
|
42
|
+
FAQBOT_PROSETTINGS_SUGGESTIONS_EDIT = "faqbot.prosettings.suggestions.edit"
|
|
43
|
+
FAQBOT_PROSETTINGS_KNOWLEDGE_ONLY_EDIT = "faqbot.prosettings.knowledge_only.edit"
|
|
44
|
+
FAQBOT_PROSETTINGS_SOURCES_EDIT = "faqbot.prosettings.sources.edit"
|
|
45
|
+
FAQBOT_PROSETTINGS_LEAD_CAPTURE_EDIT = "faqbot.prosettings.lead_capture.edit"
|
|
46
|
+
FAQBOT_PROSETTINGS_OPERATOR_EDIT = "faqbot.prosettings.operator.edit"
|
|
47
|
+
FAQBOT_PROSETTINGS_USAGE_LIMIT_EDIT = "faqbot.prosettings.usage_limit.edit"
|
|
48
|
+
FAQBOT_PROSETTINGS_DOMAIN_EDIT = "faqbot.prosettings.domain.edit"
|
|
49
|
+
SENTIMENT_CREATE = "sentiment.create"
|
|
50
|
+
SENTIMENT_DELETE = "sentiment.delete"
|
|
51
|
+
SENTIMENT_TOPIC_VIEW = "sentiment.topic.view"
|
|
52
|
+
SENTIMENT_SUMMARY_VIEW = "sentiment.summary.view"
|
|
53
|
+
SENTIMENT_RECOMMENDATION_VIEW = "sentiment.recommendation.view"
|
|
54
|
+
SENTIMENT_RECOMMENDATION_REVIEW = "sentiment.recommendation.review"
|
|
55
|
+
SENTIMENT_SOURCE_CONTENT_VIEW = "sentiment.source.content.view"
|
|
56
|
+
SENTIMENT_SETTINGS_VIEW = "sentiment.settings.view"
|
|
57
|
+
SENTIMENT_EDIT = "sentiment.edit"
|
|
58
|
+
SENTIMENT_SOURCE_MAPPING_VIEW = "sentiment.source.mapping.view"
|
|
59
|
+
SENTIMENT_SOURCE_MAPPING_EXPORT = "sentiment.source.mapping.export"
|
|
60
|
+
CALLCENTER_ANALYTICS_VIEW = "callcenter.analytics.view"
|
|
61
|
+
CALLCENTER_HISTORY_VIEW = "callcenter.history.view"
|
|
62
|
+
CALLCENTER_TRANSCRIPT_VIEW = "callcenter.transcript.view"
|
|
63
|
+
CALLCENTER_CONTACT_VIEW = "callcenter.contact.view"
|
|
64
|
+
CALLCENTER_RECORDING_LISTEN = "callcenter.recording.listen"
|
|
65
|
+
CALLCENTER_RECORDING_DOWNLOAD = "callcenter.recording.download"
|
|
66
|
+
CALLCENTER_CALL_EVENTS_VIEW = "callcenter.call.events.view"
|
|
67
|
+
CALLCENTER_SCENARIO_VIEW = "callcenter.scenario.view"
|
|
68
|
+
CALLCENTER_SCENARIO_MESSAGES_EDIT = "callcenter.scenario.messages.edit"
|
|
69
|
+
CALLCENTER_SCENARIO_FLOW_EDIT = "callcenter.scenario.flow.edit"
|
|
70
|
+
CALLCENTER_SCENARIO_DTMF_EDIT = "callcenter.scenario.dtmf.edit"
|
|
71
|
+
CALLCENTER_VOICE_SETTINGS_VIEW = "callcenter.voice.settings.view"
|
|
72
|
+
CALLCENTER_VOICE_TTS_EDIT = "callcenter.voice.tts.edit"
|
|
73
|
+
CALLCENTER_VOICE_VAD_EDIT = "callcenter.voice.vad.edit"
|
|
74
|
+
CALLCENTER_VOICE_BARGE_IN_EDIT = "callcenter.voice.barge_in.edit"
|
|
75
|
+
ASR_AUDIO_UPLOAD = "asr.audio.upload"
|
|
76
|
+
ASR_RUN = "asr.run"
|
|
77
|
+
ASR_HISTORY_VIEW = "asr.history.view"
|
|
78
|
+
ASR_RESULT_VIEW = "asr.result.view"
|
|
79
|
+
ASR_AUDIO_LISTEN = "asr.audio.listen"
|
|
80
|
+
ASR_RESULT_EXPORT = "asr.result.export"
|
|
81
|
+
ASR_RESULT_RENAME = "asr.result.rename"
|
|
82
|
+
ASR_RESULT_DELETE = "asr.result.delete"
|
|
83
|
+
ASR_SETTINGS_EDIT = "asr.settings.edit"
|
|
84
|
+
TTS_RUN = "tts.run"
|
|
85
|
+
TTS_HISTORY_VIEW = "tts.history.view"
|
|
86
|
+
TTS_RESULT_VIEW = "tts.result.view"
|
|
87
|
+
TTS_RESULT_LISTEN = "tts.result.listen"
|
|
88
|
+
TTS_RESULT_DOWNLOAD = "tts.result.download"
|
|
89
|
+
TTS_RESULT_RENAME = "tts.result.rename"
|
|
90
|
+
TTS_RESULT_DELETE = "tts.result.delete"
|
|
91
|
+
TTS_SETTINGS_EDIT = "tts.settings.edit"
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
import requests
|
|
3
|
-
import boto3
|
|
4
|
-
from io import BytesIO
|
|
5
|
-
import uuid
|
|
6
2
|
import os
|
|
3
|
+
import uuid
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
from typing import BinaryIO
|
|
6
|
+
from urllib.parse import unquote, urlparse
|
|
7
|
+
|
|
8
|
+
import boto3
|
|
9
|
+
import requests
|
|
10
|
+
|
|
7
11
|
from sharedkernel.multipart_upload import MultipartUploadSession
|
|
8
12
|
|
|
13
|
+
|
|
9
14
|
class S3Uploader:
|
|
10
|
-
def __init__(self, endpoint_url, bucket, access_key, secret_key):
|
|
15
|
+
def __init__(self, endpoint_url: str, bucket: str, access_key: str, secret_key: str) -> None:
|
|
11
16
|
self.endpoint_url = endpoint_url
|
|
12
17
|
self.bucket = bucket
|
|
13
18
|
self.access_key = access_key
|
|
@@ -21,7 +26,11 @@ class S3Uploader:
|
|
|
21
26
|
)
|
|
22
27
|
|
|
23
28
|
@staticmethod
|
|
24
|
-
def __generate_object_name(
|
|
29
|
+
def __generate_object_name(
|
|
30
|
+
object_name: str | None = None,
|
|
31
|
+
file_extension: str | None = None,
|
|
32
|
+
folder_name: str | None = None,
|
|
33
|
+
) -> str:
|
|
25
34
|
if object_name is None:
|
|
26
35
|
object_name = str(uuid.uuid4())
|
|
27
36
|
|
|
@@ -34,7 +43,14 @@ class S3Uploader:
|
|
|
34
43
|
return object_name
|
|
35
44
|
|
|
36
45
|
|
|
37
|
-
def upload_file_object(
|
|
46
|
+
def upload_file_object(
|
|
47
|
+
self,
|
|
48
|
+
file_obj: BinaryIO,
|
|
49
|
+
object_name: str | None = None,
|
|
50
|
+
file_extension: str | None = None,
|
|
51
|
+
folder_name: str | None = None,
|
|
52
|
+
public_read: bool = True,
|
|
53
|
+
) -> str:
|
|
38
54
|
object_name = self.__generate_object_name(object_name, file_extension, folder_name)
|
|
39
55
|
|
|
40
56
|
acl = "public-read" if public_read else "private"
|
|
@@ -45,7 +61,13 @@ class S3Uploader:
|
|
|
45
61
|
|
|
46
62
|
return file_url
|
|
47
63
|
|
|
48
|
-
def generate_presigned_url(
|
|
64
|
+
def generate_presigned_url(
|
|
65
|
+
self,
|
|
66
|
+
object_name: str | None = None,
|
|
67
|
+
file_extension: str | None = None,
|
|
68
|
+
folder_name: str | None = None,
|
|
69
|
+
expire_time: int = 3600,
|
|
70
|
+
) -> str:
|
|
49
71
|
object_name = self.__generate_object_name(object_name, file_extension, folder_name)
|
|
50
72
|
|
|
51
73
|
temp_url = self.s3.generate_presigned_url(
|
|
@@ -58,8 +80,27 @@ class S3Uploader:
|
|
|
58
80
|
)
|
|
59
81
|
|
|
60
82
|
return temp_url
|
|
61
|
-
|
|
62
|
-
def
|
|
83
|
+
|
|
84
|
+
def download(self, file_url: str) -> bytes:
|
|
85
|
+
"""Downloads a file by parsing its URL and reading that object from S3."""
|
|
86
|
+
object_name = self.__object_name_from_url(file_url)
|
|
87
|
+
response = self.s3.get_object(Bucket=self.bucket, Key=object_name)
|
|
88
|
+
return response["Body"].read()
|
|
89
|
+
|
|
90
|
+
def __object_name_from_url(self, file_url: str) -> str:
|
|
91
|
+
parsed = urlparse(file_url)
|
|
92
|
+
path = unquote(parsed.path).lstrip("/")
|
|
93
|
+
bucket_prefix = "{}/".format(self.bucket)
|
|
94
|
+
if path.startswith(bucket_prefix):
|
|
95
|
+
return path[len(bucket_prefix):]
|
|
96
|
+
return path
|
|
97
|
+
|
|
98
|
+
def upload_file_from_url(
|
|
99
|
+
self,
|
|
100
|
+
file_url: str,
|
|
101
|
+
object_name: str | None = None,
|
|
102
|
+
folder_name: str | None = None,
|
|
103
|
+
) -> str:
|
|
63
104
|
"""
|
|
64
105
|
Downloads a file from a URL and uploads it to an S3 bucket, returning its URL.
|
|
65
106
|
|
|
@@ -85,11 +126,11 @@ class S3Uploader:
|
|
|
85
126
|
|
|
86
127
|
def create_multipart_session(
|
|
87
128
|
self,
|
|
88
|
-
object_name=None,
|
|
89
|
-
file_extension=None,
|
|
90
|
-
folder_name=None,
|
|
91
|
-
public_read=True,
|
|
92
|
-
):
|
|
129
|
+
object_name: str | None = None,
|
|
130
|
+
file_extension: str | None = None,
|
|
131
|
+
folder_name: str | None = None,
|
|
132
|
+
public_read: bool = True,
|
|
133
|
+
) -> MultipartUploadSession:
|
|
93
134
|
object_key = self.__generate_object_name(
|
|
94
135
|
object_name, file_extension, folder_name
|
|
95
136
|
)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from typing import Type
|
|
3
|
+
|
|
4
|
+
import aiohttp
|
|
5
|
+
from fastapi import Request
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
|
|
8
|
+
from sharedkernel import config
|
|
9
|
+
from sharedkernel.database.cache.cache_repository import CacheRepository
|
|
10
|
+
from sharedkernel.database.distributed_cache import DistributedCache
|
|
11
|
+
from sharedkernel.enum import ErrorCode, FeatureKey, PlanType
|
|
12
|
+
from sharedkernel.enum.permission import PermissionsEnum
|
|
13
|
+
from sharedkernel.exception.exception import BusinessException
|
|
14
|
+
from sharedkernel.objects.result import Result
|
|
15
|
+
from sharedkernel.objects.subscription import Subscription
|
|
16
|
+
from sharedkernel.objects.user_info import current_user_info
|
|
17
|
+
from sharedkernel.objects.user_permissions import UserPermissions
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ToolboxService:
|
|
21
|
+
__permission_cache: DistributedCache[UserPermissions] | None = None
|
|
22
|
+
|
|
23
|
+
def __init__(self, cache: CacheRepository | None = None):
|
|
24
|
+
self.cache = cache
|
|
25
|
+
|
|
26
|
+
async def send_request(
|
|
27
|
+
self,
|
|
28
|
+
method: str,
|
|
29
|
+
endpoint: str,
|
|
30
|
+
payload: dict | None = None,
|
|
31
|
+
params: dict | None = None,
|
|
32
|
+
headers: dict | None = None,
|
|
33
|
+
model: Type[BaseModel] | None = None,
|
|
34
|
+
) -> Result:
|
|
35
|
+
async with aiohttp.ClientSession() as session:
|
|
36
|
+
async with session.request(
|
|
37
|
+
method=method.upper(),
|
|
38
|
+
url=endpoint,
|
|
39
|
+
json=payload,
|
|
40
|
+
params=params,
|
|
41
|
+
headers=headers,
|
|
42
|
+
) as response:
|
|
43
|
+
if not response.ok:
|
|
44
|
+
print(f"API Request to {endpoint} Failed: {response.status} {response.text}")
|
|
45
|
+
raise BusinessException(error_code=ErrorCode.Internal_Server)
|
|
46
|
+
|
|
47
|
+
response_data = await response.json()
|
|
48
|
+
|
|
49
|
+
return Result(**response_data)
|
|
50
|
+
|
|
51
|
+
async def check_permissions(
|
|
52
|
+
self,
|
|
53
|
+
required_permission_codes: list[PermissionsEnum],
|
|
54
|
+
workspace_id: str,
|
|
55
|
+
*,
|
|
56
|
+
match_any: bool = False,
|
|
57
|
+
) -> None:
|
|
58
|
+
if not required_permission_codes:
|
|
59
|
+
raise BusinessException(error_code=ErrorCode.User_Access_Denied)
|
|
60
|
+
|
|
61
|
+
if self.__permission_cache is None:
|
|
62
|
+
self.__permission_cache = DistributedCache(
|
|
63
|
+
namespace=config.USER_PERMISSIONS_CACHE_NAMESPACE,
|
|
64
|
+
model=UserPermissions,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
user_id = current_user_info.get().nameid
|
|
68
|
+
cache_key = f"{workspace_id}:{user_id}"
|
|
69
|
+
permissions = self.__permission_cache.get(cache_key)
|
|
70
|
+
if permissions is None:
|
|
71
|
+
result = await self.send_request(
|
|
72
|
+
method="GET",
|
|
73
|
+
endpoint=config.GET_PERMISSIONS_BASE_URL,
|
|
74
|
+
params={"user_id": user_id},
|
|
75
|
+
headers={"x-workspace-id": workspace_id},
|
|
76
|
+
)
|
|
77
|
+
if not result.isSucceed or result.data is None:
|
|
78
|
+
error_code = (
|
|
79
|
+
ErrorCode.Workspace_Access_Denied
|
|
80
|
+
if result.errorCode == ErrorCode.Workspace_Access_Denied.name
|
|
81
|
+
else ErrorCode.User_Access_Denied
|
|
82
|
+
)
|
|
83
|
+
raise BusinessException(error_code=error_code)
|
|
84
|
+
|
|
85
|
+
permissions = UserPermissions.model_validate(result.data)
|
|
86
|
+
self.__permission_cache.set(cache_key, permissions)
|
|
87
|
+
|
|
88
|
+
granted_permission_codes = set(permissions.permission_codes)
|
|
89
|
+
required_codes = {code.value for code in required_permission_codes}
|
|
90
|
+
allowed = (
|
|
91
|
+
not granted_permission_codes.isdisjoint(required_codes)
|
|
92
|
+
if match_any
|
|
93
|
+
else required_codes.issubset(granted_permission_codes)
|
|
94
|
+
)
|
|
95
|
+
if not allowed:
|
|
96
|
+
raise BusinessException(error_code=ErrorCode.User_Access_Denied)
|
|
97
|
+
|
|
98
|
+
def check_user_subscription(
|
|
99
|
+
self,
|
|
100
|
+
user_subscription: Subscription,
|
|
101
|
+
feature: FeatureKey,
|
|
102
|
+
quantity: int = 1,
|
|
103
|
+
):
|
|
104
|
+
feature_errors = {
|
|
105
|
+
FeatureKey.MESSAGES: ErrorCode.Subscription_Insufficient_Message_Feature,
|
|
106
|
+
FeatureKey.BOTS: ErrorCode.Subscription_Insufficient_Bot_Feature,
|
|
107
|
+
FeatureKey.URLS: ErrorCode.Subscription_Insufficient_URL_FEATURE,
|
|
108
|
+
FeatureKey.TEXTS: ErrorCode.Subscription_Insufficient_TEXT_FEATURE,
|
|
109
|
+
FeatureKey.FILES: ErrorCode.Subscription_Insufficient_FILE_FEATURE,
|
|
110
|
+
FeatureKey.OCR: ErrorCode.Subscription_Insufficient_OCR_FEATURE,
|
|
111
|
+
FeatureKey.TTS: ErrorCode.Subscription_Insufficient_TTS_FEATURE,
|
|
112
|
+
FeatureKey.ASR: ErrorCode.Subscription_Insufficient_ASR_FEATURE,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if not user_subscription:
|
|
116
|
+
raise BusinessException(error_code=ErrorCode.Subscription_Not_Found)
|
|
117
|
+
|
|
118
|
+
if user_subscription.plan_type == PlanType.UNLIMITED:
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
for _feature in user_subscription.features:
|
|
122
|
+
if _feature.feature_key == feature:
|
|
123
|
+
if _feature.remaining - quantity < 0:
|
|
124
|
+
raise BusinessException(error_code=feature_errors[feature])
|
|
125
|
+
break
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
_permission_service = ToolboxService()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def check_permission(
|
|
132
|
+
required_permission_codes: list[PermissionsEnum],
|
|
133
|
+
*,
|
|
134
|
+
match_any: bool = False,
|
|
135
|
+
):
|
|
136
|
+
def decorator(func):
|
|
137
|
+
@wraps(func)
|
|
138
|
+
async def wrapper(*args, request: Request, **kwargs):
|
|
139
|
+
await _permission_service.check_permissions(
|
|
140
|
+
required_permission_codes=list(required_permission_codes),
|
|
141
|
+
workspace_id=request.state.workspace_id,
|
|
142
|
+
match_any=match_any,
|
|
143
|
+
)
|
|
144
|
+
return await func(*args, request=request, **kwargs)
|
|
145
|
+
|
|
146
|
+
return wrapper
|
|
147
|
+
|
|
148
|
+
return decorator
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.12.0
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -33,6 +33,10 @@ Dynamic: summary
|
|
|
33
33
|
this is a shared kernel package
|
|
34
34
|
|
|
35
35
|
# Change Log
|
|
36
|
+
### Version 2.12.0
|
|
37
|
+
- implement user access level version and check permission
|
|
38
|
+
### Version 2.11.3
|
|
39
|
+
- Add S3Uploader.download, which reads an object from S3 using its URL
|
|
36
40
|
### Version 2.11.2
|
|
37
41
|
- Minor fix versioning
|
|
38
42
|
### Version 2.11.1
|
|
@@ -36,6 +36,7 @@ sharedkernel/enum/error_code.py
|
|
|
36
36
|
sharedkernel/enum/feature_display_type.py
|
|
37
37
|
sharedkernel/enum/feature_key.py
|
|
38
38
|
sharedkernel/enum/order_type.py
|
|
39
|
+
sharedkernel/enum/permission.py
|
|
39
40
|
sharedkernel/enum/plan_interval.py
|
|
40
41
|
sharedkernel/enum/plan_type.py
|
|
41
42
|
sharedkernel/enum/redis_mode_enum.py
|
|
@@ -61,4 +62,5 @@ sharedkernel/objects/jwt_model.py
|
|
|
61
62
|
sharedkernel/objects/result.py
|
|
62
63
|
sharedkernel/objects/subscription.py
|
|
63
64
|
sharedkernel/objects/user_info.py
|
|
65
|
+
sharedkernel/objects/user_permissions.py
|
|
64
66
|
sharedkernel/objects/user_workspace.py
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
from typing import Type
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
import aiohttp
|
|
4
|
-
from typing import List
|
|
5
|
-
|
|
6
|
-
from sharedkernel.objects.result import Result
|
|
7
|
-
from sharedkernel.enum import FeatureKey, PlanType
|
|
8
|
-
from sharedkernel.enum import ErrorCode
|
|
9
|
-
from sharedkernel.objects.subscription import Subscription
|
|
10
|
-
from sharedkernel.objects.user_workspace import UserWorkspace
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class ToolboxService:
|
|
18
|
-
def __init__(self, cache: CacheRepository | None = None):
|
|
19
|
-
self.cache = cache
|
|
20
|
-
|
|
21
|
-
async def send_request(
|
|
22
|
-
self,
|
|
23
|
-
method: str,
|
|
24
|
-
endpoint: str,
|
|
25
|
-
payload: dict = None,
|
|
26
|
-
params: dict | None = None,
|
|
27
|
-
headers: dict | None = None,
|
|
28
|
-
model: Type[BaseModel] | None = None,
|
|
29
|
-
) -> Result:
|
|
30
|
-
|
|
31
|
-
async with aiohttp.ClientSession() as session:
|
|
32
|
-
async with session.request(
|
|
33
|
-
method=method.upper(),
|
|
34
|
-
url=endpoint,
|
|
35
|
-
json=payload,
|
|
36
|
-
params=params,
|
|
37
|
-
headers=headers,
|
|
38
|
-
) as response:
|
|
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
|
-
|
|
44
|
-
response_data = await response.json()
|
|
45
|
-
return Result(
|
|
46
|
-
**response_data,
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def check_user_subscription(
|
|
52
|
-
self,
|
|
53
|
-
user_subscription: Subscription,
|
|
54
|
-
feature: FeatureKey,
|
|
55
|
-
quantity: int = 1
|
|
56
|
-
):
|
|
57
|
-
|
|
58
|
-
feature_errors = {
|
|
59
|
-
FeatureKey.MESSAGES: ErrorCode.Subscription_Insufficient_Message_Feature,
|
|
60
|
-
FeatureKey.BOTS: ErrorCode.Subscription_Insufficient_Bot_Feature,
|
|
61
|
-
FeatureKey.URLS: ErrorCode.Subscription_Insufficient_URL_FEATURE,
|
|
62
|
-
FeatureKey.TEXTS: ErrorCode.Subscription_Insufficient_TEXT_FEATURE,
|
|
63
|
-
FeatureKey.FILES: ErrorCode.Subscription_Insufficient_FILE_FEATURE,
|
|
64
|
-
FeatureKey.OCR: ErrorCode.Subscription_Insufficient_OCR_FEATURE,
|
|
65
|
-
FeatureKey.TTS: ErrorCode.Subscription_Insufficient_TTS_FEATURE,
|
|
66
|
-
FeatureKey.ASR: ErrorCode.Subscription_Insufficient_ASR_FEATURE,
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if not user_subscription:
|
|
70
|
-
raise BusinessException(error_code=ErrorCode.Subscription_Not_Found)
|
|
71
|
-
|
|
72
|
-
if user_subscription.plan_type == PlanType.UNLIMITED:
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
for _feature in user_subscription.features:
|
|
76
|
-
if _feature.feature_key == feature:
|
|
77
|
-
if _feature.remaining - quantity < 0:
|
|
78
|
-
raise BusinessException(error_code=feature_errors[feature])
|
|
79
|
-
break
|
|
80
|
-
|
|
81
|
-
def check_access_level(self, allowed_roles: List[Role], user_workspace: UserWorkspace):
|
|
82
|
-
if not user_workspace:
|
|
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)
|
|
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
|
{sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/cache/redis_generic_cache.py
RENAMED
|
File without changes
|
{sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/mongo_generic_audit_repository.py
RENAMED
|
File without changes
|
{sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/mongo_generic_repository.py
RENAMED
|
File without changes
|
|
File without changes
|
{sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/database/pagination_response_dto.py
RENAMED
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-2.11.2 → sharedkernel-2.12.0}/sharedkernel/normalizer/phone_number_normalizer.py
RENAMED
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|