diff --git a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/V2ImportControllerAddFilesTest.kt b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/V2ImportControllerAddFilesTest.kt index c60bfe83fd..856d60c8d5 100644 --- a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/V2ImportControllerAddFilesTest.kt +++ b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/V2ImportControllerAddFilesTest.kt @@ -348,6 +348,23 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/" } } + @Test + fun `import gets deleted after namespaces feature is toggled`() { + val base = dbPopulator.createBase() + + performImport(projectId = base.project.id, listOf("simple.json" to simpleJson)) + .andIsOk + + assertThat(importService.getAllByProject(base.project.id)).isNotEmpty() + + val project = projectService.get(base.project.id) + project.useNamespaces = !project.useNamespaces + projectService.save(project) + commitTransaction() + + assertThat(importService.getAllByProject(project.id)).isEmpty() + } + private fun validateSavedJsonImportData( project: Project, userAccount: UserAccount, diff --git a/backend/data/src/main/kotlin/io/tolgee/model/Project.kt b/backend/data/src/main/kotlin/io/tolgee/model/Project.kt index 63938bfc71..abf7c25a32 100644 --- a/backend/data/src/main/kotlin/io/tolgee/model/Project.kt +++ b/backend/data/src/main/kotlin/io/tolgee/model/Project.kt @@ -126,6 +126,7 @@ class Project( override var icuPlaceholders: Boolean = true @ColumnDefault("false") + @ActivityLoggedProp var useNamespaces: Boolean = false @ColumnDefault("0") diff --git a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/ImportService.kt b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/ImportService.kt index 0d456bbc9b..59069ef5f2 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/ImportService.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/ImportService.kt @@ -12,6 +12,7 @@ import io.tolgee.dtos.dataImport.ImportAddFilesParams import io.tolgee.dtos.dataImport.ImportFileDto import io.tolgee.dtos.request.SingleStepImportRequest import io.tolgee.events.OnImportSoftDeleted +import io.tolgee.events.OnProjectActivityEvent import io.tolgee.exceptions.BadRequestException import io.tolgee.exceptions.ErrorResponseBody import io.tolgee.exceptions.ImportConflictNotResolvedException @@ -19,21 +20,13 @@ import io.tolgee.exceptions.NotFoundException import io.tolgee.model.Language import io.tolgee.model.Project import io.tolgee.model.UserAccount -import io.tolgee.model.dataImport.Import -import io.tolgee.model.dataImport.ImportFile -import io.tolgee.model.dataImport.ImportKey -import io.tolgee.model.dataImport.ImportLanguage -import io.tolgee.model.dataImport.ImportTranslation +import io.tolgee.model.dataImport.* import io.tolgee.model.dataImport.issues.ImportFileIssue import io.tolgee.model.dataImport.issues.ImportFileIssueParam import io.tolgee.model.views.ImportFileIssueView import io.tolgee.model.views.ImportLanguageView import io.tolgee.model.views.ImportTranslationView -import io.tolgee.repository.dataImport.ImportFileRepository -import io.tolgee.repository.dataImport.ImportKeyRepository -import io.tolgee.repository.dataImport.ImportLanguageRepository -import io.tolgee.repository.dataImport.ImportRepository -import io.tolgee.repository.dataImport.ImportTranslationRepository +import io.tolgee.repository.dataImport.* import io.tolgee.repository.dataImport.issues.ImportFileIssueParamRepository import io.tolgee.repository.dataImport.issues.ImportFileIssueRepository import io.tolgee.service.dataImport.status.ImportApplicationStatus @@ -41,6 +34,7 @@ import io.tolgee.util.getSafeNamespace import jakarta.persistence.EntityManager import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Lazy +import org.springframework.context.event.EventListener import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable import org.springframework.jdbc.core.JdbcTemplate @@ -413,6 +407,20 @@ class ImportService( dataManager.resetCollisionsBetweenFiles(language, null) } + @EventListener + fun deleteExistingImportsOnUseNamespacesModification(event: OnProjectActivityEvent) { + val modifiedProjects = event.modifiedEntities[Project::class] + + modifiedProjects + ?.values + ?.filter { project -> project.modifications.containsKey("useNamespaces") } + ?.forEach { project -> + getAllByProject(project.entityId).forEach { import -> + deleteImport(import) + } + } + } + fun findTranslation(translationId: Long): ImportTranslation? { return importTranslationRepository.findById(translationId).orElse(null) }