utg-base 1.22.1__py3-none-any.whl → 1.23.0__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.
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
from functools import wraps
|
|
2
2
|
from typing import Literal, Dict, Union, List
|
|
3
3
|
|
|
4
|
+
from drf_spectacular.utils import extend_schema
|
|
5
|
+
|
|
4
6
|
from .utils import has_perms as has_permissions
|
|
5
7
|
|
|
6
8
|
|
|
9
|
+
def _get_perms_desc(perms, operator):
|
|
10
|
+
perms_text = ", ".join(perms)
|
|
11
|
+
desc = f"**Perms(operator={operator}):** `[{perms_text}]`"
|
|
12
|
+
return desc
|
|
13
|
+
|
|
14
|
+
|
|
7
15
|
def has_perm(*permission: str, operator: Literal["OR", "AND"] = "OR"):
|
|
8
16
|
"""
|
|
9
17
|
Usage:
|
|
@@ -16,6 +24,9 @@ def has_perm(*permission: str, operator: Literal["OR", "AND"] = "OR"):
|
|
|
16
24
|
|
|
17
25
|
def decorator(view_func):
|
|
18
26
|
view_func._perms = permission
|
|
27
|
+
description = _get_perms_desc(permission, operator)
|
|
28
|
+
|
|
29
|
+
view_func = extend_schema(description=description)(view_func)
|
|
19
30
|
|
|
20
31
|
@wraps(view_func)
|
|
21
32
|
def _wrapped_view(self, request, *args, **kwargs):
|
|
@@ -45,7 +56,13 @@ def has_class_perm(permissions_map: Dict[str, Union[str, List[str]]], operator:
|
|
|
45
56
|
|
|
46
57
|
if hasattr(cls, action):
|
|
47
58
|
method = getattr(cls, action)
|
|
48
|
-
|
|
59
|
+
|
|
60
|
+
description = _get_perms_desc(perms, operator)
|
|
61
|
+
decorated_method = extend_schema(description=description)(method)
|
|
62
|
+
|
|
63
|
+
setattr(decorated_method, "_perms", perms)
|
|
64
|
+
setattr(cls, action, decorated_method)
|
|
65
|
+
|
|
49
66
|
original_initial = cls.initial
|
|
50
67
|
|
|
51
68
|
@wraps(original_initial)
|
|
@@ -58,7 +75,8 @@ def has_class_perm(permissions_map: Dict[str, Union[str, List[str]]], operator:
|
|
|
58
75
|
if isinstance(required_perms, str):
|
|
59
76
|
required_perms = [required_perms]
|
|
60
77
|
|
|
61
|
-
if not has_permissions(user_id=request.user.id, perms=required_perms, operator=operator,
|
|
78
|
+
if not has_permissions(user_id=request.user.id, perms=required_perms, operator=operator,
|
|
79
|
+
request=request):
|
|
62
80
|
self.permission_denied(request)
|
|
63
81
|
|
|
64
82
|
return original_initial(self, request, *args, **kwargs)
|
|
@@ -40,7 +40,7 @@ utg_base/models/__init__.py,sha256=1zXygGICiR3iUCKdkNal9d3i3kNp654gFgBf_VlR2gI,6
|
|
|
40
40
|
utg_base/models/jwt_user.py,sha256=6TQ5wB_OZBtGhRL-2MonBGZm0n0Y86s4BRTxiRlUJOk,375
|
|
41
41
|
utg_base/models/timestamp.py,sha256=AkCliNXnvs8Z17b1mcS7gOK7v6h3Jul6WCyGyVAkb-w,217
|
|
42
42
|
utg_base/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
-
utg_base/permissions/decorators.py,sha256=
|
|
43
|
+
utg_base/permissions/decorators.py,sha256=EsJGnb8hV-l1jeHUT6WEepQn5wwhxE0-K-v_2QBS74c,2690
|
|
44
44
|
utg_base/permissions/folder.py,sha256=uJv40FVb7R379qss66a5oUcLK7KCUIL6DPbzEcGOw38,694
|
|
45
45
|
utg_base/permissions/utils.py,sha256=Rp8_ZuU5SdXri4amfFlMmrBoJUjwwQ4GYxDujRpt8YU,3264
|
|
46
46
|
utg_base/references_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -69,6 +69,6 @@ utg_base/utils/sql.py,sha256=rqIWcSjdjIMszdRnsnhV5TTYB8W17RPOujIQA9rKC_Y,762
|
|
|
69
69
|
utg_base/utils/string.py,sha256=ATwIo9uLa00p85h_NjRYLcjRs8o3KSGF7s2yhTg5GiA,1073
|
|
70
70
|
utg_base/utils/thread.py,sha256=4RqRnwtyHymY-dNcuPrMSTamE2V7wCMVfzzyIb0P4TI,2191
|
|
71
71
|
utg_base/utils/translation.py,sha256=GxJHUt0iar_0E7RWBPbeLFQ4DhgXBjffHCmxfKyjFtk,463
|
|
72
|
-
utg_base-1.
|
|
73
|
-
utg_base-1.
|
|
74
|
-
utg_base-1.
|
|
72
|
+
utg_base-1.23.0.dist-info/METADATA,sha256=N8dneTBQ9rDaUdoCNnYBqeAw62pzJwnDwfExaMw54Lg,960
|
|
73
|
+
utg_base-1.23.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
74
|
+
utg_base-1.23.0.dist-info/RECORD,,
|
|
File without changes
|