diff --git a/backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/KeyController.kt b/backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/KeyController.kt index b23800ad9a..7f054e1fe7 100644 --- a/backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/KeyController.kt +++ b/backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/KeyController.kt @@ -103,7 +103,6 @@ class KeyController( @AccessWithAnyProjectPermission // key permissions are checked separately in method body @AccessWithApiKey - @Transactional fun complexEdit(@PathVariable id: Long, @RequestBody @Valid dto: ComplexEditKeyDto): KeyWithDataModel { return KeyComplexEditHelper(applicationContext, id, dto).doComplexUpdate() } diff --git a/backend/api/src/main/kotlin/io/tolgee/component/KeyComplexEditHelper.kt b/backend/api/src/main/kotlin/io/tolgee/component/KeyComplexEditHelper.kt index 606dee5d95..372e97f3d6 100644 --- a/backend/api/src/main/kotlin/io/tolgee/component/KeyComplexEditHelper.kt +++ b/backend/api/src/main/kotlin/io/tolgee/component/KeyComplexEditHelper.kt @@ -15,8 +15,10 @@ import io.tolgee.service.key.ScreenshotService import io.tolgee.service.key.TagService import io.tolgee.service.security.SecurityService import io.tolgee.service.translation.TranslationService +import io.tolgee.util.executeInNewTransaction import io.tolgee.util.getSafeNamespace import org.springframework.context.ApplicationContext +import org.springframework.transaction.PlatformTransactionManager import kotlin.properties.Delegates class KeyComplexEditHelper( @@ -34,6 +36,8 @@ class KeyComplexEditHelper( private val tagService: TagService = applicationContext.getBean(TagService::class.java) private val screenshotService: ScreenshotService = applicationContext.getBean(ScreenshotService::class.java) private val activityHolder: ActivityHolder = applicationContext.getBean(ActivityHolder::class.java) + private val transactionManager: PlatformTransactionManager = + applicationContext.getBean(PlatformTransactionManager::class.java) private lateinit var key: Key private var modifiedTranslations: Map? = null @@ -46,33 +50,35 @@ class KeyComplexEditHelper( private var isScreenshotAdded by Delegates.notNull() fun doComplexUpdate(): KeyWithDataModel { - prepareData() - prepareConditions() - setActivityHolder() - - if (modifiedTranslations != null && areTranslationsModified) { - projectHolder.projectEntity.checkTranslationsEditPermission() - securityService.checkLanguageTagPermissions(modifiedTranslations!!.keys, projectHolder.project.id) - translationService.setForKey(key, translations = modifiedTranslations!!) - } + return executeInNewTransaction(transactionManager = transactionManager) { + prepareData() + prepareConditions() + setActivityHolder() - if (dtoTags !== null && areTagsModified) { - key.project.checkKeysEditPermission() - tagService.updateTags(key, dtoTags) - } + if (modifiedTranslations != null && areTranslationsModified) { + projectHolder.projectEntity.checkTranslationsEditPermission() + securityService.checkLanguageTagPermissions(modifiedTranslations!!.keys, projectHolder.project.id) + translationService.setForKey(key, translations = modifiedTranslations!!) + } - if (isScreenshotAdded || isScreenshotDeleted) { - updateScreenshotsWithPermissionCheck(dto, key) - } + if (dtoTags !== null && areTagsModified) { + key.project.checkKeysEditPermission() + tagService.updateTags(key, dtoTags) + } - var edited = key + if (isScreenshotAdded || isScreenshotDeleted) { + updateScreenshotsWithPermissionCheck(dto, key) + } - if (isKeyModified) { - key.project.checkKeysEditPermission() - edited = keyService.edit(key, dto.name, dto.namespace) - } + var edited = key + + if (isKeyModified) { + key.project.checkKeysEditPermission() + edited = keyService.edit(key, dto.name, dto.namespace) + } - return keyWithDataModelAssembler.toModel(edited) + keyWithDataModelAssembler.toModel(edited) + } } private fun setActivityHolder() {