@@ -0,0 +1,1644 @@
+from django.dispatch import receiver%0Afrom django.db.models.signals import post_save%0Afrom guardian.shortcuts import assign_perm%0Afrom django.conf import settings%0A%0Afrom grandchallenge.annotations.models import (%0A    MeasurementAnnotation,%0A    BooleanClassificationAnnotation,%0A    IntegerClassificationAnnotation,%0A    PolygonAnnotationSet,%0A    LandmarkAnnotationSet,%0A    ETDRSGridAnnotation,%0A    CoordinateListAnnotation,%0A    SinglePolygonAnnotation,%0A    SingleLandmarkAnnotation,%0A)%0A%0A%0A@receiver(post_save, sender=MeasurementAnnotation)%0A@receiver(post_save, sender=BooleanClassificationAnnotation)%0A@receiver(post_save, sender=IntegerClassificationAnnotation)%0A@receiver(post_save, sender=PolygonAnnotationSet)%0A@receiver(post_save, sender=LandmarkAnnotationSet)%0A@receiver(post_save, sender=ETDRSGridAnnotation)%0A@receiver(post_save, sender=CoordinateListAnnotation)%0A@receiver(post_save, sender=SinglePolygonAnnotation)%0A@receiver(post_save, sender=SingleLandmarkAnnotation)%0Adef annotation_post_save(sender, instance, created):%0A    %22%22%22%0A    Set object level permissions for grader that belongs to retina_graders group after saving%0A    of new annotation%0A    %22%22%22%0A    if not created:%0A        return%0A%0A    model_name = sender.__name__.lower()%0A    if model_name.startswith(%22single%22):%0A        owner = instance.annotation_set.grader%0A    else:%0A        owner = instance.grader%0A%0A    if not owner.groups.filter(name=settings.RETINA_GRADERS_GROUP_NAME).exists():%0A        return%0A%0A    for permission_type in (%22view%22, %22add%22, %22change%22, %22delete%22):%0A        permission_name = f%22annotation.%7Bpermission_type%7D_%7Bmodel_name%7D%22%0A        assign_perm(permission_name, owner, instance)%0A

Add post_save signal for annotations to add correct object level permissions