utg-base 1.12.0__py3-none-any.whl → 1.13.1__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.
- utg_base/permissions/utils.py +4 -3
- utg_base/signals/__init__.py +1 -0
- utg_base/signals/sync_perms.py +19 -0
- {utg_base-1.12.0.dist-info → utg_base-1.13.1.dist-info}/METADATA +1 -1
- {utg_base-1.12.0.dist-info → utg_base-1.13.1.dist-info}/RECORD +6 -4
- {utg_base-1.12.0.dist-info → utg_base-1.13.1.dist-info}/WHEEL +0 -0
utg_base/permissions/utils.py
CHANGED
|
@@ -19,13 +19,13 @@ def generate_perm_cache_key(user_id: str):
|
|
|
19
19
|
|
|
20
20
|
def has_perm(user_id, perm):
|
|
21
21
|
redis_conn: Redis = get_redis_connection("shared")
|
|
22
|
-
perm = f"{to_snake_case(env('APP_NAME')):{perm}
|
|
22
|
+
perm = f"{to_snake_case(env('APP_NAME'))}:{perm}"
|
|
23
23
|
return bool(redis_conn.sismember(f'user:{user_id}:permissions', perm))
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def has_perms(user_id: str, perms: list[str], operator: Literal["OR", "AND"] = "OR"):
|
|
27
27
|
redis_conn: Redis = get_redis_connection("shared")
|
|
28
|
-
perms = [f"{to_snake_case(env('APP_NAME')):{perm}
|
|
28
|
+
perms = [f"{to_snake_case(env('APP_NAME'))}:{perm}" for perm in perms]
|
|
29
29
|
result = redis_conn.smismember(f'user:{user_id}:permissions', perms)
|
|
30
30
|
|
|
31
31
|
if operator == "OR":
|
|
@@ -68,9 +68,10 @@ def sync_permissions():
|
|
|
68
68
|
|
|
69
69
|
request = Request(HttpRequest())
|
|
70
70
|
try:
|
|
71
|
-
u_requests.post(request, UServices.USER_MANAGEMENT, '/api/permissions/', data={
|
|
71
|
+
response = u_requests.post(request, UServices.USER_MANAGEMENT, '/api/permissions/', data={
|
|
72
72
|
"service": to_snake_case(env('APP_NAME')),
|
|
73
73
|
"codes": perm_codes
|
|
74
74
|
})
|
|
75
|
+
print(response.json())
|
|
75
76
|
except Exception as e:
|
|
76
77
|
print(e)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .sync_perms import sync_perms
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from django.apps import apps
|
|
4
|
+
from django.core.cache import cache
|
|
5
|
+
from django.dispatch import receiver
|
|
6
|
+
from utg_base.permissions.utils import sync_permissions
|
|
7
|
+
from utg_base.utils.signals import app_ready
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@receiver(app_ready)
|
|
11
|
+
def sync_perms(sender, **kwargs):
|
|
12
|
+
# wait all apps ready
|
|
13
|
+
while not apps.ready:
|
|
14
|
+
time.sleep(0.1)
|
|
15
|
+
|
|
16
|
+
# only run 1 time (not all gunicorn workers)
|
|
17
|
+
if not cache.add("sync_perms", True, timeout=10):
|
|
18
|
+
return
|
|
19
|
+
sync_permissions()
|
|
@@ -41,7 +41,7 @@ utg_base/models/jwt_user.py,sha256=6TQ5wB_OZBtGhRL-2MonBGZm0n0Y86s4BRTxiRlUJOk,3
|
|
|
41
41
|
utg_base/models/timestamp.py,sha256=AkCliNXnvs8Z17b1mcS7gOK7v6h3Jul6WCyGyVAkb-w,217
|
|
42
42
|
utg_base/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
43
|
utg_base/permissions/decorators.py,sha256=JSxyt8LCZWSWBm3Dk9y4JrtgoFH0sWN-MISkn0Z6g7s,777
|
|
44
|
-
utg_base/permissions/utils.py,sha256=
|
|
44
|
+
utg_base/permissions/utils.py,sha256=IZfPxIzfZjOwdp06yF6Dp9lUn0o7M0DySIFOhrFwc0k,2527
|
|
45
45
|
utg_base/references_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
46
|
utg_base/references_api/admin.py,sha256=suMo4x8I3JBxAFBVIdE-5qnqZ6JAZV0FESABHOSc-vg,63
|
|
47
47
|
utg_base/references_api/apps.py,sha256=thAGmO-ZT-OD9dHHBSQRL_RRt-Es_jt-mEmHgVTpERs,168
|
|
@@ -51,6 +51,8 @@ utg_base/references_api/urls.py,sha256=WkLACQ8GfK5pJkvt8FuYdOxcqSZHj7pYRw51M9Wlu
|
|
|
51
51
|
utg_base/references_api/utils.py,sha256=o-mM5S6LRvMZFQU0BAKFD0Kido28_ZytN-DttME2Rjk,5794
|
|
52
52
|
utg_base/services/__init__.py,sha256=LqtwUiqEZPIbKRGJfve5D5m3ucV6Kw1Nbo5Jnj_hPhY,37
|
|
53
53
|
utg_base/services/base_api.py,sha256=bMTmjy8TRN4WTCgV_1RvkquoqijJQ1hP7BBtPgW_AH0,5677
|
|
54
|
+
utg_base/signals/__init__.py,sha256=5SKumqAQrfrXUzi4NO3zjPAXV2TG3EDKxOomaF-e15M,35
|
|
55
|
+
utg_base/signals/sync_perms.py,sha256=XN7AVHyHvo6EQlvHP5jtrT0J4ShC27gFXWThn_TTRb0,491
|
|
54
56
|
utg_base/u_services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
55
57
|
utg_base/u_services/apps.py,sha256=JcLDfs62eoXeXB6cEWLKGCKa3t22Gr6Z3YiAkYLaHDY,159
|
|
56
58
|
utg_base/u_services/constants.py,sha256=T7lGhP9Xg2LwqALlTdA9etQJ68KmPm5713x26NUMW3Y,149
|
|
@@ -68,6 +70,6 @@ utg_base/utils/sql.py,sha256=rqIWcSjdjIMszdRnsnhV5TTYB8W17RPOujIQA9rKC_Y,762
|
|
|
68
70
|
utg_base/utils/string.py,sha256=ATwIo9uLa00p85h_NjRYLcjRs8o3KSGF7s2yhTg5GiA,1073
|
|
69
71
|
utg_base/utils/thread.py,sha256=4RqRnwtyHymY-dNcuPrMSTamE2V7wCMVfzzyIb0P4TI,2191
|
|
70
72
|
utg_base/utils/translation.py,sha256=GxJHUt0iar_0E7RWBPbeLFQ4DhgXBjffHCmxfKyjFtk,463
|
|
71
|
-
utg_base-1.
|
|
72
|
-
utg_base-1.
|
|
73
|
-
utg_base-1.
|
|
73
|
+
utg_base-1.13.1.dist-info/METADATA,sha256=ooe4mp1NlzWiplg5BpyZqymbZ5AzcOsBNjo1gQ5SHqY,917
|
|
74
|
+
utg_base-1.13.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
75
|
+
utg_base-1.13.1.dist-info/RECORD,,
|
|
File without changes
|