utg-base 1.13.1__tar.gz → 1.14.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.
- {utg_base-1.13.1 → utg_base-1.14.0}/PKG-INFO +1 -1
- {utg_base-1.13.1 → utg_base-1.14.0}/pyproject.toml +1 -1
- utg_base-1.14.0/src/utg_base/permissions/decorators.py +65 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/permissions/utils.py +3 -2
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/references_api/utils.py +5 -2
- utg_base-1.13.1/src/utg_base/api/views.py +0 -13
- utg_base-1.13.1/src/utg_base/permissions/decorators.py +0 -25
- utg_base-1.13.1/src/utg_base/references_api/admin.py +0 -3
- utg_base-1.13.1/src/utg_base/references_api/models.py +0 -3
- {utg_base-1.13.1 → utg_base-1.14.0}/README.md +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/base.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/pagination.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/permissions.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/routers.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/serializers.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/api/spectacular.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/authentications/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/authentications/microservice_authentication.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/authentications/models.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/apps.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/filters/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/filters/task_result.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/management/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/management/commands/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/management/commands/migrate_tasks.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/serializers/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/serializers/periodic_task.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/serializers/task_result.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/urls.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/views/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/views/periodic_task.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/views/task_result.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/constants/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/constants/available_languages.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/env.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/logging.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/middleware/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/middleware/debug.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/middleware/locale.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/apps.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/management/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/management/commands/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/management/commands/makemigrations.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/models/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/models/jwt_user.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/models/timestamp.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/permissions/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/references_api/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/references_api/apps.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/references_api/migrations/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/references_api/urls.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/services/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/services/base_api.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/signals/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/signals/sync_perms.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/apps.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/constants.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/migrations/0001_initial.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/migrations/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/models.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/u_services/u_requests.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/__init__.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/data.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/date.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/dict_util.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/response_processors.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/signals.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/sql.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/string.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/thread.py +0 -0
- {utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/utils/translation.py +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from typing import Literal, Dict, Union, List
|
|
3
|
+
|
|
4
|
+
from rest_framework.exceptions import PermissionDenied
|
|
5
|
+
|
|
6
|
+
from .utils import has_perms as has_permissions
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def has_perm(*permission: str, operator: Literal["OR", "AND"] = "OR"):
|
|
10
|
+
"""
|
|
11
|
+
Usage:
|
|
12
|
+
has_perm('PERM1')
|
|
13
|
+
has_perm('PERM1', 'PERM2')
|
|
14
|
+
|
|
15
|
+
:param permission: One or many permissions.
|
|
16
|
+
"""
|
|
17
|
+
def decorator(view_func):
|
|
18
|
+
view_func._perms = permission
|
|
19
|
+
@wraps(view_func)
|
|
20
|
+
def _wrapped_view(self, request, *args, **kwargs):
|
|
21
|
+
if not has_permissions(user_id=request.user.id, perms=list(permission), operator=operator):
|
|
22
|
+
raise PermissionDenied
|
|
23
|
+
return view_func(self, request, *args, **kwargs)
|
|
24
|
+
return _wrapped_view
|
|
25
|
+
return decorator
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def has_class_perm(permissions_map: Dict[str, Union[str, List[str]]], operator: Literal["OR", "AND"] = "OR"):
|
|
29
|
+
"""
|
|
30
|
+
Usage:
|
|
31
|
+
@has_class_perm({
|
|
32
|
+
'list': ['perm1', 'perm2'],
|
|
33
|
+
'create': 'perm3',
|
|
34
|
+
'update': ['perm4']
|
|
35
|
+
})
|
|
36
|
+
"""
|
|
37
|
+
def decorator(cls):
|
|
38
|
+
for action, perms in permissions_map.items():
|
|
39
|
+
if isinstance(perms, str):
|
|
40
|
+
perms = [perms]
|
|
41
|
+
|
|
42
|
+
if hasattr(cls, action):
|
|
43
|
+
method = getattr(cls, action)
|
|
44
|
+
setattr(method, "_perms", perms)
|
|
45
|
+
original_initial = cls.initial
|
|
46
|
+
|
|
47
|
+
@wraps(original_initial)
|
|
48
|
+
def new_initial(self, request, *args, **kwargs):
|
|
49
|
+
action = getattr(self, 'action', None) or request.method.lower()
|
|
50
|
+
|
|
51
|
+
if action in permissions_map:
|
|
52
|
+
required_perms = permissions_map[action]
|
|
53
|
+
|
|
54
|
+
if isinstance(required_perms, str):
|
|
55
|
+
required_perms = [required_perms]
|
|
56
|
+
|
|
57
|
+
if not has_permissions(user_id=request.user.id, perms=required_perms, operator=operator):
|
|
58
|
+
raise PermissionDenied
|
|
59
|
+
|
|
60
|
+
return original_initial(self, request, *args, **kwargs)
|
|
61
|
+
|
|
62
|
+
cls.initial = new_initial
|
|
63
|
+
return cls
|
|
64
|
+
|
|
65
|
+
return decorator
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import traceback
|
|
1
2
|
from typing import Literal
|
|
2
3
|
|
|
3
4
|
from django.http import HttpRequest
|
|
@@ -72,6 +73,6 @@ def sync_permissions():
|
|
|
72
73
|
"service": to_snake_case(env('APP_NAME')),
|
|
73
74
|
"codes": perm_codes
|
|
74
75
|
})
|
|
75
|
-
print(response.json())
|
|
76
|
+
print('[INFO] sync_permissions:', response.json())
|
|
76
77
|
except Exception as e:
|
|
77
|
-
|
|
78
|
+
traceback.print_exc()
|
|
@@ -8,7 +8,7 @@ from drf_spectacular.utils import extend_schema, extend_schema_serializer
|
|
|
8
8
|
from rest_framework import filters
|
|
9
9
|
from rest_framework import viewsets, serializers
|
|
10
10
|
|
|
11
|
-
from
|
|
11
|
+
from utg_base.permissions.decorators import has_class_perm
|
|
12
12
|
|
|
13
13
|
serializer_classes = {}
|
|
14
14
|
|
|
@@ -82,7 +82,7 @@ def create_view_set(model: Model):
|
|
|
82
82
|
fields_list = get_model_fields_list(model)
|
|
83
83
|
|
|
84
84
|
@extend_schema(tags=[get_url_prefix(model)])
|
|
85
|
-
class ViewSet(viewsets.ModelViewSet
|
|
85
|
+
class ViewSet(viewsets.ModelViewSet):
|
|
86
86
|
http_method_names = get_api_meta_property(model, 'http_method_names') or ['get', 'patch']
|
|
87
87
|
manager = model.objects.order_by(*get_ordering(model))
|
|
88
88
|
filter_backends = [filters.SearchFilter]
|
|
@@ -98,6 +98,9 @@ def create_view_set(model: Model):
|
|
|
98
98
|
|
|
99
99
|
return create_serializer(model)
|
|
100
100
|
|
|
101
|
+
if permissions := get_api_meta_property(model, 'permissions'):
|
|
102
|
+
has_class_perm(permissions)(ViewSet)
|
|
103
|
+
|
|
101
104
|
return ViewSet
|
|
102
105
|
|
|
103
106
|
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
from django.db.models import Manager
|
|
3
|
-
from rest_framework import generics
|
|
4
|
-
|
|
5
|
-
from .base import BaseAPIView
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class TranslatedListView(generics.ListAPIView, BaseAPIView):
|
|
9
|
-
manager: Manager
|
|
10
|
-
|
|
11
|
-
def get_queryset(self):
|
|
12
|
-
self.update_lang()
|
|
13
|
-
return self.manager.all()
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
from functools import wraps
|
|
2
|
-
from typing import Literal
|
|
3
|
-
|
|
4
|
-
from rest_framework.exceptions import PermissionDenied
|
|
5
|
-
|
|
6
|
-
from .utils import has_perms as has_permissions
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def has_perm(*permission: str, operator: Literal["OR", "AND"] = "OR"):
|
|
10
|
-
"""
|
|
11
|
-
Usage:
|
|
12
|
-
has_perm('PERM1')
|
|
13
|
-
has_perm('PERM1', 'PERM2')
|
|
14
|
-
|
|
15
|
-
:param permission: One or many permissions.
|
|
16
|
-
"""
|
|
17
|
-
def decorator(view_func):
|
|
18
|
-
view_func._perms = permission
|
|
19
|
-
@wraps(view_func)
|
|
20
|
-
def _wrapped_view(self, request, *args, **kwargs):
|
|
21
|
-
if not has_permissions(user_id=request.user.id, perms=list(permission), operator=operator):
|
|
22
|
-
raise PermissionDenied
|
|
23
|
-
return view_func(self, request, *args, **kwargs)
|
|
24
|
-
return _wrapped_view
|
|
25
|
-
return decorator
|
|
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
|
{utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/authentications/microservice_authentication.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
|
{utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/celery/management/commands/migrate_tasks.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
|
{utg_base-1.13.1 → utg_base-1.14.0}/src/utg_base/migration/management/commands/makemigrations.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
|
|
File without changes
|
|
File without changes
|