From e3a8cc6b019a4761da8dace48678281db8d647b9 Mon Sep 17 00:00:00 2001 From: James Ward Date: Thu, 23 Apr 2026 02:34:05 -0400 Subject: [PATCH] fix(api): omit UserDto.ageRestriction instead of returning null Closes: 2296 --- .../gotson/komga/interfaces/api/rest/UserController.kt | 10 ++++++---- .../gotson/komga/interfaces/api/rest/dto/UserDto.kt | 2 ++ .../komga/interfaces/api/rest/UserControllerTest.kt | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/UserController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/UserController.kt index 06336243..1b5be42d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/UserController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/UserController.kt @@ -112,10 +112,12 @@ class UserController( restrictions = ContentRestrictions( ageRestriction = - if (ageRestriction == null || ageRestriction.restriction == AllowExcludeDto.NONE) - null - else - AgeRestriction(ageRestriction.age, ageRestriction.restriction.toDomain()), + ageRestriction.let { + if (it == null || it.restriction == AllowExcludeDto.NONE) + null + else + AgeRestriction(it.age, it.restriction.toDomain()) + }, labelsAllow = labelsAllow ?: emptySet(), labelsExclude = labelsExclude ?: emptySet(), ), diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/UserDto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/UserDto.kt index ee425a30..026f9776 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/UserDto.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/UserDto.kt @@ -1,10 +1,12 @@ package org.gotson.komga.interfaces.api.rest.dto +import com.fasterxml.jackson.annotation.JsonInclude import org.gotson.komga.domain.model.AgeRestriction import org.gotson.komga.domain.model.AllowExclude import org.gotson.komga.domain.model.KomgaUser import org.gotson.komga.infrastructure.security.KomgaPrincipal +@JsonInclude(JsonInclude.Include.NON_NULL) data class UserDto( val id: String, val email: String, diff --git a/komga/src/test/kotlin/org/gotson/komga/interfaces/api/rest/UserControllerTest.kt b/komga/src/test/kotlin/org/gotson/komga/interfaces/api/rest/UserControllerTest.kt index 3e39faf0..55d74e1b 100644 --- a/komga/src/test/kotlin/org/gotson/komga/interfaces/api/rest/UserControllerTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/interfaces/api/rest/UserControllerTest.kt @@ -113,7 +113,7 @@ class UserControllerTest( jsonPath("$.sharedLibrariesId") { doesNotExist() } jsonPath("$.labelsAllow") { isEmpty() } jsonPath("$.labelsExclude") { isEmpty() } - jsonPath("$.ageRestriction") { isEmpty() } + jsonPath("$.ageRestriction") { doesNotExist() } } } }