Skip to content

Commit

Permalink
1415: Add USER_ENTITLEMENT_EXPIRED error
Browse files Browse the repository at this point in the history
  • Loading branch information
seluianova committed Oct 28, 2024
1 parent 775f035 commit 184ee6b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions administration/src/errors/DefaultErrorMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ const defaultErrorMap = (extensions?: ErrorExtensions): GraphQLErrorMessage => {
title:
'Wir konnten Ihre Angaben nicht im System finden. Bitte überprüfen Sie Ihre Angaben und versuchen Sie es erneut.',
}
case GraphQlExceptionCode.UserEntitlementExpired:
return {
title:
'Sie sind nicht mehr berechtigt einen KoblenzPass zu erstellen.',
}
case GraphQlExceptionCode.MailNotSent:
return {
title: `Email konnte nicht an ${extensions.recipient} gesendet werden.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import app.ehrenamtskarte.backend.exception.webservice.exceptions.InvalidInputEx
import app.ehrenamtskarte.backend.exception.webservice.exceptions.InvalidQrCodeSize
import app.ehrenamtskarte.backend.exception.webservice.exceptions.RegionNotActivatedForCardConfirmationMailException
import app.ehrenamtskarte.backend.exception.webservice.exceptions.RegionNotFoundException
import app.ehrenamtskarte.backend.exception.webservice.exceptions.UserEntitlementExpiredException
import app.ehrenamtskarte.backend.exception.webservice.exceptions.UserEntitlementNotFoundException
import app.ehrenamtskarte.backend.mail.Mailer
import app.ehrenamtskarte.backend.matomo.Matomo
Expand Down Expand Up @@ -146,9 +147,12 @@ class CardMutationService {
val userHash = Argon2IdHasher.hashKoblenzUserData(user)

val userEntitlements = transaction { UserEntitlementsRepository.findByUserHash(userHash.toByteArray()) }
if (userEntitlements == null || userEntitlements.revoked || userEntitlements.endDate.isBefore(LocalDate.now())) {
if (userEntitlements == null) {
throw UserEntitlementNotFoundException()
}
if (userEntitlements.revoked || userEntitlements.endDate.isBefore(LocalDate.now())) {
throw UserEntitlementExpiredException()
}

val updatedCardInfo = enrichCardInfo(
cardInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app.ehrenamtskarte.backend.exception.webservice.exceptions

import app.ehrenamtskarte.backend.exception.GraphQLBaseException
import app.ehrenamtskarte.backend.exception.webservice.schema.GraphQLExceptionCode

class UserEntitlementExpiredException : GraphQLBaseException(GraphQLExceptionCode.USER_ENTITLEMENT_EXPIRED)
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ enum class GraphQLExceptionCode {
REGION_NOT_FOUND,
REGION_NOT_ACTIVATED_FOR_APPLICATION,
REGION_NOT_ACTIVATED_CARD_CONFIRMATION_MAIL,
USER_ENTITLEMENT_NOT_FOUND
USER_ENTITLEMENT_NOT_FOUND,
USER_ENTITLEMENT_EXPIRED
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal class CreateCardFromSelfServiceTest : GraphqlApiTest() {
val jsonResponse = jacksonObjectMapper().readTree(responseBody)

jsonResponse.apply {
assertEquals("Error USER_ENTITLEMENT_NOT_FOUND occurred.", findValuesAsText("message").single())
assertEquals("Error USER_ENTITLEMENT_EXPIRED occurred.", findValuesAsText("message").single())
}

transaction {
Expand All @@ -140,7 +140,7 @@ internal class CreateCardFromSelfServiceTest : GraphqlApiTest() {
val jsonResponse = jacksonObjectMapper().readTree(responseBody)

jsonResponse.apply {
assertEquals("Error USER_ENTITLEMENT_NOT_FOUND occurred.", findPath("message").textValue())
assertEquals("Error USER_ENTITLEMENT_EXPIRED occurred.", findPath("message").textValue())
}

transaction {
Expand Down
1 change: 1 addition & 0 deletions specs/backend-api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ enum GraphQLExceptionCode {
REGION_NOT_ACTIVATED_CARD_CONFIRMATION_MAIL
REGION_NOT_ACTIVATED_FOR_APPLICATION
REGION_NOT_FOUND
USER_ENTITLEMENT_EXPIRED
USER_ENTITLEMENT_NOT_FOUND
}

Expand Down

0 comments on commit 184ee6b

Please sign in to comment.