forked from 0x2620/pandora
canSeeNotes
This commit is contained in:
parent
485cca69b0
commit
eaaf76e149
4 changed files with 13 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
"canSeeDebugMenu": {"admin": true},
|
||||
"canSeeFiles": {"staff": true, "admin": true},
|
||||
"canSeeItem": {"guest": 2, "member": 2, "friend": 3, "staff": 4, "admin": 4},
|
||||
"canSeeNotes": {"staff": true, "admin": true},
|
||||
"canSeeExtraItemViews": {"friend": true, "staff": true, "admin": true}
|
||||
},
|
||||
/*
|
||||
|
|
|
@ -159,6 +159,8 @@ class Item(models.Model):
|
|||
upload_to=lambda i, x: i.path('torrent.torrent'))
|
||||
stream_info = fields.DictField(default={}, editable=False)
|
||||
|
||||
notes = models.TextField(default='')
|
||||
|
||||
#stream related fields
|
||||
stream_aspect = models.FloatField(default=4/3)
|
||||
|
||||
|
|
|
@ -395,6 +395,9 @@ def get(request):
|
|||
info['layers'] = item.get_layers(request.user)
|
||||
if data['keys'] and 'files' in data['keys']:
|
||||
info['files'] = item.get_files(request.user)
|
||||
if not data['keys'] or 'notes' in data['keys'] \
|
||||
and request.user.get_profile().capability('canSeeNotes'):
|
||||
info['notes'] = item.notes
|
||||
response['data'] = info
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
|
@ -438,6 +441,10 @@ def editItem(request):
|
|||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||
if item.editable(request.user):
|
||||
response = json_response(status=200, text='ok')
|
||||
if 'notes' in data:
|
||||
if request.user.get_profile().capability('canSeeNotes'):
|
||||
item.notes = data['notes']
|
||||
del data['notes']
|
||||
item.edit(data)
|
||||
else:
|
||||
response = json_response(status=403, text='permissino denied')
|
||||
|
|
|
@ -42,6 +42,9 @@ class UserProfile(models.Model):
|
|||
def get_level(self):
|
||||
return settings.CONFIG['userLevels'][self.level]
|
||||
|
||||
def capability(self, capability):
|
||||
return settings.CONFIG['capabilities'][capability].get(self.get_level()) == True
|
||||
|
||||
def user_post_save(sender, instance, **kwargs):
|
||||
profile, new = UserProfile.objects.get_or_create(user=instance)
|
||||
|
||||
|
|
Loading…
Reference in a new issue