Skip to content

Commit

Permalink
- Restore "MapLayersJSONArraySerializerField"
Browse files Browse the repository at this point in the history
(cherry picked from commit a1e6dd6)
  • Loading branch information
afabiani committed Dec 1, 2020
1 parent 0d61749 commit 205ed97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion mapstore2_adapter/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def to_representation(self, value):
return attributes


class MapLayersJSONArraySerializerField(serializers.Field):

def to_internal_value(self, data):
return data

def to_representation(self, value):
if value:
from geonode.maps.models import Map
from geonode.maps.api.serializers import MapLayerSerializer
map = Map.objects.get(id=value)
return MapLayerSerializer(embed=True, many=True).to_representation(map.layers)


class UserSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
Expand All @@ -72,6 +85,8 @@ class Meta:
class MapStoreResourceSerializer(serializers.HyperlinkedModelSerializer):
user = serializers.CharField(source='user.username',
read_only=True)
layers = MapLayersJSONArraySerializerField(source='id',
read_only=True)

def __init__(self, *args, **kwargs):
# Instantiate the superclass normally
Expand All @@ -84,4 +99,4 @@ def __init__(self, *args, **kwargs):

class Meta:
model = MapStoreResource
fields = ('id', 'user', 'name', 'creation_date', 'last_update')
fields = ('id', 'user', 'layers', 'name', 'creation_date', 'last_update')
3 changes: 2 additions & 1 deletion mapstore2_adapter/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser, IsAuthenticated, IsAuthenticatedOrReadOnly # noqa
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
from geonode.base.api.permissions import IsOwnerOrReadOnly

from .models import MapStoreResource
from .serializers import (UserSerializer,
Expand All @@ -40,7 +41,7 @@ class MapStoreResourceViewSet(viewsets.ModelViewSet):
""" Only Authenticate User perform CRUD Operations on Respective Data
"""
authentication_classes = [SessionAuthentication, BasicAuthentication, OAuth2Authentication]
permission_classes = [IsAuthenticatedOrReadOnly, ]
permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
model = MapStoreResource
serializer_class = MapStoreResourceSerializer

Expand Down

0 comments on commit 205ed97

Please sign in to comment.