canSeeNotes

This commit is contained in:
j 2011-10-22 14:42:45 +02:00
parent 485cca69b0
commit eaaf76e149
4 changed files with 13 additions and 0 deletions

View file

@ -21,6 +21,7 @@
"canSeeDebugMenu": {"admin": true}, "canSeeDebugMenu": {"admin": true},
"canSeeFiles": {"staff": true, "admin": true}, "canSeeFiles": {"staff": true, "admin": true},
"canSeeItem": {"guest": 2, "member": 2, "friend": 3, "staff": 4, "admin": 4}, "canSeeItem": {"guest": 2, "member": 2, "friend": 3, "staff": 4, "admin": 4},
"canSeeNotes": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"friend": true, "staff": true, "admin": true} "canSeeExtraItemViews": {"friend": true, "staff": true, "admin": true}
}, },
/* /*

View file

@ -159,6 +159,8 @@ class Item(models.Model):
upload_to=lambda i, x: i.path('torrent.torrent')) upload_to=lambda i, x: i.path('torrent.torrent'))
stream_info = fields.DictField(default={}, editable=False) stream_info = fields.DictField(default={}, editable=False)
notes = models.TextField(default='')
#stream related fields #stream related fields
stream_aspect = models.FloatField(default=4/3) stream_aspect = models.FloatField(default=4/3)

View file

@ -395,6 +395,9 @@ def get(request):
info['layers'] = item.get_layers(request.user) info['layers'] = item.get_layers(request.user)
if data['keys'] and 'files' in data['keys']: if data['keys'] and 'files' in data['keys']:
info['files'] = item.get_files(request.user) 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 response['data'] = info
else: else:
response = json_response(status=403, text='permission denied') 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']) item = get_object_or_404_json(models.Item, itemId=data['id'])
if item.editable(request.user): if item.editable(request.user):
response = json_response(status=200, text='ok') 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) item.edit(data)
else: else:
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')

View file

@ -42,6 +42,9 @@ class UserProfile(models.Model):
def get_level(self): def get_level(self):
return settings.CONFIG['userLevels'][self.level] 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): def user_post_save(sender, instance, **kwargs):
profile, new = UserProfile.objects.get_or_create(user=instance) profile, new = UserProfile.objects.get_or_create(user=instance)