Skip to content

Commit

Permalink
fix deleting reports between apps. Closes #497
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Mar 16, 2024
1 parent 426cc3c commit 7e74fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022-2023 Lukas Morawietz (https://github.com/F43nd1r)
* (C) Copyright 2022-2024 Lukas Morawietz (https://github.com/F43nd1r)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,19 +100,19 @@ class ReportRepository(
@Transactional
@PreAuthorize("hasEditPermission(#appId)")
fun delete(appId: AppId, reportId: String) {
jooq.deleteFrom(REPORT).where(REPORT.ID.eq(reportId)).execute()
jooq.deleteFrom(REPORT).where(REPORT.APP_ID.eq(appId), REPORT.ID.eq(reportId)).execute()
}

@Transactional
@PreAuthorize("hasEditPermission(#appId)")
fun deleteBefore(appId: AppId, instant: Instant) {
jooq.deleteFrom(REPORT).where(REPORT.DATE.lt(instant)).execute()
jooq.deleteFrom(REPORT).where(REPORT.APP_ID.eq(appId), REPORT.DATE.lt(instant)).execute()
}

@Transactional
@PreAuthorize("hasEditPermission(#appId)")
fun deleteBefore(appId: AppId, versionCode: Int) {
jooq.deleteFrom(REPORT).where(REPORT.VERSION_CODE.lt(versionCode)).execute()
jooq.deleteFrom(REPORT).where(REPORT.APP_ID.eq(appId), REPORT.VERSION_CODE.lt(versionCode)).execute()
}

@PreAuthorize("hasViewPermission(#appId)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,26 @@ internal class ReportRepositoryTest(

expectThat(reportRepository.get(appId, REPORT.ID)).containsExactlyInAnyOrder(keep1, keep2)
}

@Test
fun `should not delete reports of other apps by time`() {
val now = Instant.now()
val otherAppId = testDataBuilder.createApp()
val keep = testDataBuilder.createReport(otherAppId, date = now.minus(1, ChronoUnit.DAYS))
reportRepository.deleteBefore(appId, now)

expectThat(reportRepository.find(keep)).isNotNull()
}

@Test
fun `should not delete reports of other apps by version`() {
val otherAppId = testDataBuilder.createApp()
val version = testDataBuilder.createVersion(otherAppId, code = 1)
val keep = testDataBuilder.createReport(otherAppId, version = version)
reportRepository.deleteBefore(appId, 1)

expectThat(reportRepository.find(keep)).isNotNull()
}
}

@Nested
Expand Down

0 comments on commit 7e74fe6

Please sign in to comment.