forked from 0x2620/pandora
permissions add/edit annotations
This commit is contained in:
parent
b3dded73a6
commit
f23340ddbb
2 changed files with 14 additions and 12 deletions
|
@ -39,7 +39,7 @@ class Annotation(models.Model):
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
if user.is_authenticated():
|
if user.is_authenticated():
|
||||||
if user.is_staff or \
|
if user.get_profile().capability('canEditAnnotations') or \
|
||||||
self.user == user or \
|
self.user == user or \
|
||||||
user.groups.filter(id__in=self.groups.all()).count() > 0:
|
user.groups.filter(id__in=self.groups.all()).count() > 0:
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -131,17 +131,19 @@ def addAnnotation(request):
|
||||||
|
|
||||||
item = get_object_or_404_json(Item, itemId=data['item'])
|
item = get_object_or_404_json(Item, itemId=data['item'])
|
||||||
|
|
||||||
#FIXME: check that layer is a valid layer id
|
layer_id = data['layer']
|
||||||
layer = data['layer']
|
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0]
|
||||||
|
if layer['canAddAnnotations'].get(request.user.get_profile().get_level()):
|
||||||
annotation = models.Annotation(
|
annotation = models.Annotation(
|
||||||
item=item,
|
item=item,
|
||||||
layer=layer,
|
layer=layer_id,
|
||||||
user=request.user,
|
user=request.user,
|
||||||
start=float(data['in']), end=float(data['out']),
|
start=float(data['in']), end=float(data['out']),
|
||||||
value=data['value'])
|
value=data['value'])
|
||||||
annotation.save()
|
annotation.save()
|
||||||
response = json_response(annotation.json())
|
response = json_response(annotation.json())
|
||||||
|
else:
|
||||||
|
response = json_response(status=403, text='permission denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(addAnnotation, cache=False)
|
actions.register(addAnnotation, cache=False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue