django-restit 4.2.128__py3-none-any.whl → 4.2.130__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- account/models/member.py +7 -0
- {django_restit-4.2.128.dist-info → django_restit-4.2.130.dist-info}/METADATA +1 -1
- {django_restit-4.2.128.dist-info → django_restit-4.2.130.dist-info}/RECORD +8 -7
- rest/__init__.py +1 -1
- wiki/migrations/0003_page_perms.py +18 -0
- wiki/models/page.py +41 -2
- {django_restit-4.2.128.dist-info → django_restit-4.2.130.dist-info}/LICENSE.md +0 -0
- {django_restit-4.2.128.dist-info → django_restit-4.2.130.dist-info}/WHEEL +0 -0
account/models/member.py
CHANGED
@@ -10,6 +10,7 @@ import time
|
|
10
10
|
import re
|
11
11
|
import hashlib
|
12
12
|
import uuid
|
13
|
+
from objict import objict
|
13
14
|
|
14
15
|
from auditlog.models import PersistentLog
|
15
16
|
from sessionlog.models import SessionLog
|
@@ -387,6 +388,12 @@ class Member(User, RestModel, MetaDataModel):
|
|
387
388
|
return False
|
388
389
|
return self.getProperty(perm, 0, "permissions", bool)
|
389
390
|
|
391
|
+
def getPermissions(self):
|
392
|
+
return objict.fromdict(self.getProperties("permissions"))
|
393
|
+
|
394
|
+
def listPermissions(self):
|
395
|
+
return [k for k, v in self.getProperties("permissions").items() if v in [1, "1"]]
|
396
|
+
|
390
397
|
def hasGroupPerm(self, group, perm):
|
391
398
|
if group is None:
|
392
399
|
return False
|
@@ -30,7 +30,7 @@ account/models/device.py,sha256=0AFeLMGk4im4KZVd3eGSyRbK4eQEXiFM2cdY8GUzihs,5934
|
|
30
30
|
account/models/feeds.py,sha256=vI7fG4ASY1M0Zjke24RdnfDcuWeATl_yR_25jPmT64g,2011
|
31
31
|
account/models/group.py,sha256=KnLj0cOJBg1JYo33wL-7NehD4_PCsLyEjLdX6GZJZAo,22308
|
32
32
|
account/models/legacy.py,sha256=zYdtv4LC0ooxPVqWM-uToPwV-lYWQLorSE6p6yn1xDw,2720
|
33
|
-
account/models/member.py,sha256=
|
33
|
+
account/models/member.py,sha256=7JCf7HULo_CLqKLGbHFvFOVYSkKbVkDuUPjq0C1u2Ak,54450
|
34
34
|
account/models/membership.py,sha256=90EpAhOsGaqphDAkONP6j_qQ0OWSRaQsI8H7E7fgMkE,9249
|
35
35
|
account/models/notify.py,sha256=TOkuVBLAsbzT58FOxII_G3Cj_IDQx16vyehyEsNrDcY,15306
|
36
36
|
account/models/passkeys.py,sha256=TJxITUi4DT4_1tW2K7ZlOcRjJuMVl2NtKz7pKQU8-Tw,1516
|
@@ -376,7 +376,7 @@ pushit/utils.py,sha256=IeTCGa-164nmB1jIsK1lu1O1QzUhS3BKfuXHGjCW-ck,2121
|
|
376
376
|
rest/.gitignore,sha256=TbEvWRMnAiajCTOdhiNrd9eeCAaIjRp9PRjE_VkMM5g,118
|
377
377
|
rest/README.md,sha256=V3ETc-cJu8PZIbKr9xSe_pA4JEUpC8Dhw4bQeVCDJPw,5460
|
378
378
|
rest/RemoteEvents.py,sha256=nL46U7AuxIrlw2JunphR1tsXyqi-ep_gD9CYGpYbNgE,72
|
379
|
-
rest/__init__.py,sha256=
|
379
|
+
rest/__init__.py,sha256=SVzE--w6i3jhZDS773pK0TONhXDz7k3o4fmQrPAa99w,122
|
380
380
|
rest/arc4.py,sha256=y644IbF1ec--e4cUJ3KEYsewTCITK0gmlwa5mJruFC0,1967
|
381
381
|
rest/cache.py,sha256=1Qg0rkaCJCaVP0-l5hZg2CIblTdeBSlj_0fP6vlKUpU,83
|
382
382
|
rest/crypto/__init__.py,sha256=Tl0U11rgj1eBYqd6OXJ2_XSdNLumW_JkBZnaJqI6Ldw,72
|
@@ -481,10 +481,11 @@ telephony/rpc.py,sha256=PXPDFvgoXkCKlfMzIbt6lYZPay3fcveNj2X4Pjby7p4,3473
|
|
481
481
|
wiki/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
482
482
|
wiki/migrations/0001_initial.py,sha256=9jvUyjrbJrbDilRnwzQUPhPV8Xi_olEPBk_N0nycvM0,3606
|
483
483
|
wiki/migrations/0002_alter_pagemedia_entry.py,sha256=9CUnfvBmj0D4akCkux7HFuXgw9B9avE8V-iMCm5cjds,485
|
484
|
+
wiki/migrations/0003_page_perms.py,sha256=qJBLI7t5mgiDTKCR9qhticmbhgo2KKYq7WbHaxH1Ykw,423
|
484
485
|
wiki/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
485
486
|
wiki/models/__init__.py,sha256=jE-9r_Hqpyo7ysKu9BschXOn5Zg34wUt894GwJpxA28,132
|
486
487
|
wiki/models/faq.py,sha256=nvcEFerllQKT61kIYlasvZzRKwpXyfmQpiqkpHP1V1o,1745
|
487
|
-
wiki/models/page.py,sha256=
|
488
|
+
wiki/models/page.py,sha256=06wyZsDX57B-d_wZhSNcrNAOv-ERHlKveJ15MZc9haQ,8751
|
488
489
|
wiki/models/revision.py,sha256=St5-vz8SGvogsDL6jTWqHLE23PS5mp9iA0DUt3hWTsU,729
|
489
490
|
wiki/periodic.py,sha256=t-UgXJIug-OLslJM_r03-5WrNKj39TxrvfuNFjVAhDs,334
|
490
491
|
wiki/renderers/__init__.py,sha256=lLEoJvjU3ezXwBGcjleKk_kMyNeMD9MpfBlEiKayEiM,461
|
@@ -511,7 +512,7 @@ ws4redis/servers/uwsgi.py,sha256=VyhoCI1DnVFqBiJYHoxqn5Idlf6uJPHvfBKgkjs34mo,172
|
|
511
512
|
ws4redis/settings.py,sha256=K0yBiLUuY81iDM4Yr-k8hbvjn5VVHu5zQhmMK8Dtz0s,1536
|
512
513
|
ws4redis/utf8validator.py,sha256=S0OlfjeGRP75aO6CzZsF4oTjRQAgR17OWE9rgZdMBZA,5122
|
513
514
|
ws4redis/websocket.py,sha256=R0TUyPsoVRD7Y_oU7w2I6NL4fPwiz5Vl94-fUkZgLHA,14848
|
514
|
-
django_restit-4.2.
|
515
|
-
django_restit-4.2.
|
516
|
-
django_restit-4.2.
|
517
|
-
django_restit-4.2.
|
515
|
+
django_restit-4.2.130.dist-info/LICENSE.md,sha256=VHN4hhEeVOoFjtG-5fVv4jesA4SWi0Z-KgOzzN6a1ps,1068
|
516
|
+
django_restit-4.2.130.dist-info/METADATA,sha256=9xgoIJG_Or13Bbw9zbbFb5sByRnWrAdkF2pKjC_0jTU,7663
|
517
|
+
django_restit-4.2.130.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
518
|
+
django_restit-4.2.130.dist-info/RECORD,,
|
rest/__init__.py
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Generated by Django 4.2.11 on 2024-08-13 04:11
|
2
|
+
|
3
|
+
from django.db import migrations, models
|
4
|
+
|
5
|
+
|
6
|
+
class Migration(migrations.Migration):
|
7
|
+
|
8
|
+
dependencies = [
|
9
|
+
('wiki', '0002_alter_pagemedia_entry'),
|
10
|
+
]
|
11
|
+
|
12
|
+
operations = [
|
13
|
+
migrations.AddField(
|
14
|
+
model_name='page',
|
15
|
+
name='perms',
|
16
|
+
field=models.CharField(db_index=True, default=None, max_length=255, null=True),
|
17
|
+
),
|
18
|
+
]
|
wiki/models/page.py
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
from django.db import models as dm
|
2
2
|
from rest import models as rm
|
3
|
+
from rest import settings
|
4
|
+
from rest import helpers as rh
|
3
5
|
from medialib import models as medialib
|
4
6
|
import re
|
5
7
|
import mistune
|
6
8
|
from wiki.renderers import WikiRenderer
|
7
9
|
from wiki.renderers.mistune import task_list
|
8
10
|
|
11
|
+
WIKI_PAGE_VIEW_PERMS = settings.get("WIKI_PAGE_VIEW_PERMS", ["view_wiki", "edit_wiki"])
|
12
|
+
WIKI_PAGE_EDIT_PERMS = settings.get("WIKI_PAGE_EDIT_PERMS", ["edit_wiki"])
|
13
|
+
|
14
|
+
|
9
15
|
class Page(dm.Model, rm.RestModel, rm.MetaDataModel):
|
10
16
|
"""
|
11
17
|
Blog (a collection of articles)
|
@@ -14,7 +20,8 @@ class Page(dm.Model, rm.RestModel, rm.MetaDataModel):
|
|
14
20
|
SEARCH_FIELDS = ["title", "body"]
|
15
21
|
SEARCH_TERMS = ["title", "body"]
|
16
22
|
QUERY_FIELDS = ["all_fields", "parent__path"]
|
17
|
-
VIEW_PERMS =
|
23
|
+
VIEW_PERMS = WIKI_PAGE_VIEW_PERMS
|
24
|
+
EDIT_PERMS = WIKI_PAGE_EDIT_PERMS
|
18
25
|
UNIQUE_LOOKUP = ["path"]
|
19
26
|
DEFAULT_SORT = "-order"
|
20
27
|
CAN_DELETE = True
|
@@ -30,6 +37,7 @@ class Page(dm.Model, rm.RestModel, rm.MetaDataModel):
|
|
30
37
|
"order",
|
31
38
|
"path",
|
32
39
|
"slug",
|
40
|
+
"perms"
|
33
41
|
],
|
34
42
|
},
|
35
43
|
"default": {
|
@@ -103,6 +111,7 @@ class Page(dm.Model, rm.RestModel, rm.MetaDataModel):
|
|
103
111
|
title = dm.CharField(max_length=255)
|
104
112
|
path = dm.CharField(max_length=255, db_index=True)
|
105
113
|
slug = dm.SlugField(db_index=True)
|
114
|
+
perms = dm.CharField(max_length=255, db_index=True, null=True, default=None)
|
106
115
|
|
107
116
|
body = dm.TextField(blank=True)
|
108
117
|
|
@@ -144,6 +153,35 @@ class Page(dm.Model, rm.RestModel, rm.MetaDataModel):
|
|
144
153
|
if qset.count():
|
145
154
|
self.slug = f"{sanitized_slug}_{qset.count()+1}"
|
146
155
|
|
156
|
+
def on_rest_can_get(self, request):
|
157
|
+
if request is None:
|
158
|
+
return True
|
159
|
+
if self.perms:
|
160
|
+
perms = [p.strip() for p in self.perms.split(',')]
|
161
|
+
elif self.parent and self.parent.perms:
|
162
|
+
perms = [p.strip() for p in self.parent.perms.split(',')]
|
163
|
+
else:
|
164
|
+
perms = getattr(self.RestMeta, "VIEW_PERMS", None)
|
165
|
+
if perms:
|
166
|
+
if "public" in perms:
|
167
|
+
return True
|
168
|
+
if "owner" in perms and self.checkIsOwner(request.member):
|
169
|
+
return True
|
170
|
+
# we need to check if this user has permission
|
171
|
+
group_field = "group"
|
172
|
+
status, error, code = rh.requestHasPerms(request, perms, getattr(self, group_field, None))
|
173
|
+
if not status:
|
174
|
+
return False
|
175
|
+
return True
|
176
|
+
|
177
|
+
@classmethod
|
178
|
+
def on_rest_list_ready(cls, request, qset=None):
|
179
|
+
out = []
|
180
|
+
for page in qset:
|
181
|
+
if page.on_rest_can_get(request):
|
182
|
+
out.append(page)
|
183
|
+
return out
|
184
|
+
|
147
185
|
def on_rest_pre_save(self, request):
|
148
186
|
if not self.slug:
|
149
187
|
self.set_slug(self.title)
|
@@ -206,7 +244,8 @@ class PageMetaData(rm.MetaDataBase):
|
|
206
244
|
|
207
245
|
class PageMedia(dm.Model, rm.RestModel):
|
208
246
|
class RestMeta:
|
209
|
-
VIEW_PERMS =
|
247
|
+
VIEW_PERMS = WIKI_PAGE_VIEW_PERMS
|
248
|
+
EDIT_PERMS = WIKI_PAGE_EDIT_PERMS
|
210
249
|
GRAPHS = {
|
211
250
|
"basic": {
|
212
251
|
"graphs": {
|
File without changes
|
File without changes
|