diff --git a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeController.kt b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeController.kt index d5363b913..804786851 100644 --- a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeController.kt +++ b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeController.kt @@ -234,10 +234,9 @@ class HankeController( featureFlags.ensureEnabled(Feature.HANKE_EDITING) logger.info { "Updating Hanke: ${hanke.toLogString()}" } - val existingHanke = hankeService.findHankeOrThrow(hankeTunnus) - validateUpdatable(existing = existingHanke, updated = hanke, hankeTunnus) existingHanke.verifyUserAuthorization(currentUserId(), PermissionCode.EDIT) + validateUpdatable(hanke, hankeTunnus) val updatedHanke = hankeService.updateHanke(hanke) logger.info { "Updated hanke ${updatedHanke.hankeTunnus}." } @@ -305,14 +304,10 @@ class HankeController( } } - private fun validateUpdatable(existing: Hanke, updated: Hanke, hankeTunnusFromPath: String) { - val tunnusMatch = - listOf(existing.hankeTunnus, updated.hankeTunnus).all { it == hankeTunnusFromPath } - - if (!tunnusMatch) { + private fun validateUpdatable(hankeUpdate: Hanke, hankeTunnusFromPath: String) { + if (hankeUpdate.hankeTunnus != hankeTunnusFromPath) { throw HankeArgumentException( - "Hanketunnus mismatch. (Existing=${existing.hankeTunnus}, Updated=${updated.hankeTunnus}, " + - "Path=$hankeTunnusFromPath)" + "Hanketunnus mismatch. (In payload=${hankeUpdate.hankeTunnus}, In path=$hankeTunnusFromPath)" ) } } diff --git a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeServiceImpl.kt b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeServiceImpl.kt index 88c92c36b..0304d2208 100644 --- a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeServiceImpl.kt +++ b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/HankeServiceImpl.kt @@ -156,7 +156,7 @@ open class HankeServiceImpl( postProcessAndSaveLogging(loggingEntryHolder, savedHankeEntity, userId) return createHankeDomainObjectFromEntity(savedHankeEntity).also { - initAccessForCreatedHanke(it, savedHankeEntity.perustaja, userId) + initAccessForCreatedHanke(it, perustaja, userId) hankeLoggingService.logCreate(it, userId) } } @@ -244,16 +244,10 @@ open class HankeServiceImpl( !applicationService.isStillPending(it) } - private fun initAccessForCreatedHanke( - hanke: Hanke, - perustaja: PerustajaEntity?, - userId: String - ) { + private fun initAccessForCreatedHanke(hanke: Hanke, perustaja: Perustaja?, userId: String) { val hankeId = hanke.id!! val permissionAll = permissionService.setPermission(hankeId, userId, Role.KAIKKI_OIKEUDET) - perustaja?.let { - hankeKayttajaService.addHankeFounder(hankeId, it.toDomainObject(), permissionAll) - } + perustaja?.let { hankeKayttajaService.addHankeFounder(hankeId, it, permissionAll) } hankeKayttajaService.saveNewTokensFromHanke(hanke) } diff --git a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/permissions/HankeKayttajaService.kt b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/permissions/HankeKayttajaService.kt index 5dff5d073..1576604a3 100644 --- a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/permissions/HankeKayttajaService.kt +++ b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/permissions/HankeKayttajaService.kt @@ -51,7 +51,7 @@ class HankeKayttajaService( @Transactional fun addHankeFounder(hankeId: Int, founder: Perustaja, permissionEntity: PermissionEntity) { - logger.info { "Saving token for Hanke perustaja." } + logger.info { "Saving user for Hanke perustaja." } saveUser( HankeKayttajaEntity( hankeId = hankeId,