Skip to content
Snippets Groups Projects
Verified Commit f3384681 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

fix: simplify logic allowing to update fields

parent 02a82096
No related branches found
No related tags found
No related merge requests found
Pipeline #7364 passed
......@@ -381,21 +381,18 @@ class HostSerializer(serializers.ModelSerializer):
raise exceptions.PermissionDenied(detail="You are not allowed to update this host.")
# Only users with edit permissions are allowed to edit these fields
if (
biography := validated_data.get("biography")
) and "biography" not in user_edit_permissions:
if "biography" in validated_data and "biography" not in user_edit_permissions:
raise exceptions.PermissionDenied(
detail="You are not allowed to edit the host’s biography."
)
else:
instance.biography = biography
if (name := validated_data.get("name")) and "name" not in user_edit_permissions:
if "name" in validated_data and "name" not in user_edit_permissions:
raise exceptions.PermissionDenied(
detail="You are not allowed to edit the host’s name."
)
else:
instance.name = name
instance.biography = validated_data.get("biography", instance.biography)
instance.name = validated_data.get("name", instance.name)
# Only update these fields if the user is privileged, ignore otherwise
if user_is_privileged:
......@@ -606,30 +603,27 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
raise exceptions.PermissionDenied(detail="You are not allowed to update this show.")
# Only users with edit permissions are allowed to update these fields
if (
description := validated_data.get("description")
) and "description" not in user_edit_permissions:
if "description" in validated_data and "description" not in user_edit_permissions:
raise exceptions.PermissionDenied(
detail="You are not allowed to edit the show’s description."
)
else:
instance.description = description
if (name := validated_data.get("name")) and "name" not in user_edit_permissions:
if "name" in validated_data and "name" not in user_edit_permissions:
raise exceptions.PermissionDenied(
detail="You are not allowed to edit the show’s name."
)
else:
instance.name = name
if (
short_description := validated_data.get("short_description")
) and "short_description" not in user_edit_permissions:
"short_description" in validated_data
and "short_description" not in user_edit_permissions
):
raise exceptions.PermissionDenied(
detail="You are not allowed to edit the show’s short description."
)
else:
instance.short_description = short_description
instance.description = validated_data.get("description", instance.description)
instance.name = validated_data.get("name", instance.name)
instance.short_description = validated_data.get("name", instance.name)
# Only update these fields if the user is privileged, ignore otherwise
if user_is_privileged:
......@@ -642,7 +636,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
"funding_category_id", instance.funding_category
)
instance.image = validated_data.get("image_id", instance.image)
instance.internal_note = validated_data.get("interna_note", instance.internal_note)
instance.internal_note = validated_data.get("internal_note", instance.internal_note)
instance.is_active = validated_data.get("is_active", instance.is_active)
instance.is_public = validated_data.get("is_public", instance.is_public)
instance.logo = validated_data.get("logo", instance.logo)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment