Skip to content

Commit

Permalink
[Fixes #12594] Error when saing a new map
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Sep 23, 2024
1 parent 549be34 commit c3140e8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
logger = logging.getLogger(__name__)


# fixing up the publishing option based on user permissions
SETTINGS_MAPPING = {"is_approved": "can_approve", "is_published": "can_publish", "featured": "can_feature"}


def user_serializer():
import geonode.people.api.serializers as ser

Expand Down Expand Up @@ -735,6 +739,15 @@ def to_internal_value(self, data):
data = super(ResourceBaseSerializer, self).to_internal_value(data)
return data

def update(self, instance, validated_data):
user = self.context["request"].user
for field, user_action in SETTINGS_MAPPING.items():
if not getattr(user, user_action)(instance) and field in validated_data:
# in case the user does not have the perms to do the action
# we reset the default values
validated_data.pop(field, None)

Check warning on line 748 in geonode/base/api/serializers.py

View check run for this annotation

Codecov / codecov/patch

geonode/base/api/serializers.py#L748

Added line #L748 was not covered by tests
return super().update(instance, validated_data)

def save(self, **kwargs):
extent = self.validated_data.pop("extent", None)
instance = super().save(**kwargs)
Expand All @@ -752,11 +765,8 @@ def save(self, **kwargs):
raise InvalidResourceException("The standard bbox provided is invalid")
instance.set_bbox_polygon(coords, srid)

# fixing up the publishing option based on user permissions
MAPPING = {"is_approved": "can_approve", "is_published": "can_publish", "featured": "can_feature"}

user = self.context["request"].user
for field, user_action in MAPPING.items():
for field, user_action in SETTINGS_MAPPING.items():
if not getattr(user, user_action)(instance):
# in case the user does not have the perms to do the action
# we reset the default values
Expand Down

0 comments on commit c3140e8

Please sign in to comment.