forked from 0x2620/pandora
group permissions for documents
This commit is contained in:
parent
008ba18d5d
commit
ed977686d1
1 changed files with 8 additions and 0 deletions
|
@ -27,6 +27,7 @@ from annotation.models import Annotation
|
||||||
from archive.extract import resize_image
|
from archive.extract import resize_image
|
||||||
from archive.chunk import save_chunk
|
from archive.chunk import save_chunk
|
||||||
from user.models import Group
|
from user.models import Group
|
||||||
|
from user.utils import update_groups
|
||||||
|
|
||||||
from . import managers
|
from . import managers
|
||||||
from . import utils
|
from . import utils
|
||||||
|
@ -334,6 +335,7 @@ class Document(models.Model, FulltextMixin):
|
||||||
if not user or user.is_anonymous():
|
if not user or user.is_anonymous():
|
||||||
return False
|
return False
|
||||||
if self.user == user or \
|
if self.user == user or \
|
||||||
|
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
|
||||||
user.is_staff or \
|
user.is_staff or \
|
||||||
user.profile.capability('canEditDocuments') is True or \
|
user.profile.capability('canEditDocuments') is True or \
|
||||||
(item and item.editable(user)):
|
(item and item.editable(user)):
|
||||||
|
@ -347,6 +349,9 @@ class Document(models.Model, FulltextMixin):
|
||||||
p.description = ox.sanitize_html(data['description'])
|
p.description = ox.sanitize_html(data['description'])
|
||||||
p.save()
|
p.save()
|
||||||
else:
|
else:
|
||||||
|
if 'groups' in data:
|
||||||
|
groups = data.pop('groups')
|
||||||
|
update_groups(self, groups)
|
||||||
for key in data:
|
for key in data:
|
||||||
k = list(filter(lambda i: i['id'] == key, settings.CONFIG['documentKeys']))
|
k = list(filter(lambda i: i['id'] == key, settings.CONFIG['documentKeys']))
|
||||||
ktype = k and k[0].get('type') or ''
|
ktype = k and k[0].get('type') or ''
|
||||||
|
@ -436,6 +441,7 @@ class Document(models.Model, FulltextMixin):
|
||||||
'matches',
|
'matches',
|
||||||
'size',
|
'size',
|
||||||
'user',
|
'user',
|
||||||
|
'groups',
|
||||||
'referenced',
|
'referenced',
|
||||||
]
|
]
|
||||||
if self.extension in ('html', 'txt'):
|
if self.extension in ('html', 'txt'):
|
||||||
|
@ -455,6 +461,8 @@ class Document(models.Model, FulltextMixin):
|
||||||
response[key] = self.editable(user)
|
response[key] = self.editable(user)
|
||||||
elif key == 'user':
|
elif key == 'user':
|
||||||
response[key] = self.user.username
|
response[key] = self.user.username
|
||||||
|
elif key == 'groups':
|
||||||
|
response[key] = [g.name for g in self.groups.all()]
|
||||||
elif key == 'accessed':
|
elif key == 'accessed':
|
||||||
response[key] = self.accessed.aggregate(Max('access'))['access__max']
|
response[key] = self.accessed.aggregate(Max('access'))['access__max']
|
||||||
elif key == 'timesaccessed':
|
elif key == 'timesaccessed':
|
||||||
|
|
Loading…
Reference in a new issue