Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/content/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import typing

from django.core.files import File
from rest_framework import serializers

from apps.reports.models import Report, ReportVisibility
from utils.validators import validate_image_size

from .models import NewsPost, NewsPostReport

Expand All @@ -23,6 +25,9 @@ class Meta:
"author": {"required": False},
}

def validate_cover_image(self, value: File) -> File:
return validate_image_size(value)

@typing.override
def create(self, validated_data: dict) -> NewsPost:
request = self.context.get("request")
Expand Down
11 changes: 5 additions & 6 deletions apps/dashboards/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ def validate(self, data: dict) -> dict: # type: ignore[reportIncompatibleMethod
is_active = data.get("is_active", instance.is_active if instance else True)
show_on_home = data.get("show_on_home", instance.show_on_home if instance else False)

if show_on_home and not is_active:
raise serializers.ValidationError(
{
"non_field_errors": "A dashboard must be active to be shown on the home page.",
},
)
# NOTE: This is intentional. If a dashboard is marked inactive, we automatically
# remove it from the home page to keep it consistent with the frontend
# "Show on Home" logic.
if not is_active and show_on_home:
data["show_on_home"] = False

# Home dashboard limit validation
if show_on_home:
Expand Down
9 changes: 5 additions & 4 deletions apps/dashboards/tests/mutations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Mutation:
title
isActive
capacityAndResourceId
showOnHome
}
}
}
Expand Down Expand Up @@ -186,8 +187,7 @@ def test_create_dashboard_show_on_home_requires_active(self):
},
)
resp = content["data"]["createExternalDashboard"]
assert resp["ok"] is False
assert resp["errors"] is not None
assert resp["ok"] is True

def test_update_dashboard_deactivate_while_show_on_home(self):
self.force_login(self.staff)
Expand All @@ -197,8 +197,9 @@ def test_update_dashboard_deactivate_while_show_on_home(self):
variables={"id": str(dashboard.pk), "data": {"isActive": False}},
)
resp = content["data"]["updateExternalDashboard"]
assert resp["ok"] is False
assert resp["errors"] is not None
assert resp["ok"] is True
assert resp["result"]["isActive"] is False
assert resp["result"]["showOnHome"] is False

def test_viewer_cannot_create(self):
self.force_login(self.viewer)
Expand Down
3 changes: 2 additions & 1 deletion apps/gallery/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from asgiref.sync import sync_to_async

from apps.gallery.models import GalleryAlbum, GalleryImage
from apps.users.graphql.types import UserType
from utils.graphql.types import DjangoFileType


Expand All @@ -22,7 +23,7 @@ class GalleryAlbumType:
title: strawberry.auto
description: strawberry.auto
cover_image: GalleryImageType | None
created_by_id: strawberry.ID
created_by: UserType
created_at: strawberry.auto
updated_at: strawberry.auto

Expand Down
6 changes: 6 additions & 0 deletions apps/gallery/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import typing

from django.core.files import File
from rest_framework import serializers

from utils.validators import validate_image_size

from .models import GalleryAlbum, GalleryImage


Expand Down Expand Up @@ -31,3 +34,6 @@ class GalleryImageSerializer(serializers.ModelSerializer):
class Meta:
model = GalleryImage
fields = ["album", "image", "caption", "order"]

def validate_image(self, value: File) -> File:
return validate_image_size(value)
2 changes: 1 addition & 1 deletion apps/gallery/tests/queries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Query:
id
title
description
createdById
createdBy { id email fullName }
createdAt
}
}
Expand Down
9 changes: 9 additions & 0 deletions apps/reports/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import typing

from django.core.files import File
from rest_framework import serializers

from utils.validators import validate_image_size, validate_report_file_size

from .models import Link, Report, ReportContentType, ReportVisibility, ThematicArea


Expand Down Expand Up @@ -40,6 +43,12 @@ class Meta:
"uploaded_by": {"required": False},
}

def validate_cover_image(self, value: File) -> File:
return validate_image_size(value)

def validate_file(self, value: File) -> File:
return validate_report_file_size(value)

def validate_visibility(self, value: int) -> int:
if self.instance and self.instance.visibility == ReportVisibility.PRIVATE and value == ReportVisibility.PUBLIC:
raise serializers.ValidationError("Cannot change visibility from PRIVATE to PUBLIC.")
Expand Down
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ type GalleryAlbumType {
title: String!
description: String
coverImage: GalleryImageType
createdById: ID!
createdBy: UserType!
createdAt: DateTime!
updatedAt: DateTime!
imagesCount: Int!
Expand Down
Loading