Commit 4fc37558 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Add custom VOEvent serializer for unauthenticated users

Based on "feedback" from the low-latency group, the p_astro
and other information which is in the VOEvent files will not be
made available through the API to unauthenticated users. I'm
not sure why.
parent d3ef5a17
......@@ -660,6 +660,37 @@ class SupereventVOEventSerializer(serializers.ModelSerializer):
return voevent
class SupereventVOEventSerializerExternal(serializers.ModelSerializer):
"""Read-only VOEvent serializer for non-internal users."""
# Read only fields
issuer = serializers.SlugRelatedField(slug_field='username',
read_only=True)
created = serializers.DateTimeField(format=settings.GRACE_STRFTIME_FORMAT,
read_only=True)
links = serializers.SerializerMethodField(read_only=True)
class Meta(SupereventVOEventSerializer.Meta):
fields = ('voevent_type', 'file_version', 'ivorn', 'created',
'issuer', 'filename', 'N', 'links')
def get_links(self, obj):
file_link = None
if obj.filename:
file_name = "{name},{version}".format(name=obj.filename,
version=obj.file_version)
file_link = api_reverse('superevents:superevent-file-detail',
args=[obj.superevent.superevent_id, file_name],
request=self.context.get('request', None))
link_dict = {
'self': api_reverse('superevents:superevent-voevent-detail',
args=[obj.superevent.superevent_id, obj.N],
request=self.context.get('request', None)),
'file': file_link,
}
return link_dict
class SupereventEMFootprintSerializer(serializers.ModelSerializer):
"""
Should be read-only; only used as a nester serializer within
......
......@@ -18,6 +18,7 @@ from core.http import check_and_serve_file
from core.vfile import VersionedFile, FileVersionError, FileVersionNameError
from events.models import Event, Label
from events.view_utils import reverse as gracedb_reverse
from ligoauth.utils import is_internal
from superevents.buildVOEvent import VOEventBuilderException
from superevents.models import Superevent, Log, Signoff
from superevents.utils import remove_tag_from_log, \
......@@ -34,11 +35,14 @@ from .permissions import SupereventModelPermissions, \
SupereventSignoffModelPermissions, SupereventSignoffTypeModelPermissions, \
SupereventSignoffTypeObjectPermissions, \
SupereventGroupObjectPermissionPermissions
from .serializers import SupereventSerializer, SupereventUpdateSerializer, \
SupereventEventSerializer, SupereventLabelSerializer, \
SupereventLogSerializer, SupereventLogTagSerializer, \
SupereventVOEventSerializer, SupereventEMObservationSerializer, \
SupereventSignoffSerializer, SupereventGroupObjectPermissionSerializer
from .serializers import (
SupereventSerializer, SupereventUpdateSerializer,
SupereventEventSerializer, SupereventLabelSerializer,
SupereventLogSerializer, SupereventLogTagSerializer,
SupereventVOEventSerializer, SupereventVOEventSerializerExternal,
SupereventEMObservationSerializer, SupereventSignoffSerializer,
SupereventGroupObjectPermissionSerializer
)
from .settings import SUPEREVENT_LOOKUP_URL_KWARG, SUPEREVENT_LOOKUP_REGEX
from .viewsets import SupereventNestedViewSet
from ..filters import DjangoObjectAndGlobalPermissionsFilter
......@@ -322,6 +326,12 @@ class SupereventVOEventViewSet(SafeCreateMixin, InheritDefaultPermissionsMixin,
lookup_field = 'N'
list_view_order_by = ('N',)
def get_serializer_class(self):
if is_internal(self.request.user):
return self.serializer_class
else:
return SupereventVOEventSerializerExternal
class SupereventEMObservationViewSet(SafeCreateMixin,
InheritDefaultPermissionsMixin, SupereventNestedViewSet):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment