Skip to content

Commit 1c24f60

Browse files
committed
Change query behind findAllDatasets when you're a Platform.Admin
- Rename repository method from findByOrganizationIdNoSecurity to findByOrganizationId - Remove unnecessarily parenthesis in query
1 parent 57b5f1b commit 1c24f60

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,32 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
366366
assertEquals(numberOfDatasets - expectedPageSize, datasetList.size)
367367
}
368368

369+
@Test
370+
fun `test find All Datasets as Platform Admin with returned datasetID lists`() {
371+
organizationSaved = organizationApiService.registerOrganization(organization)
372+
val numberOfDatasets = 500
373+
val datasetIdListCreated = mutableListOf<String>()
374+
IntRange(1, numberOfDatasets).forEach {
375+
datasetIdListCreated.add(
376+
datasetApiService
377+
.createDataset(
378+
organizationSaved.id!!, makeDatasetWithRole("d-dataset-$it", "dataset-$it"))
379+
.id!!)
380+
}
381+
logger.info("Change current user...")
382+
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
383+
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.admin"
384+
every { getCurrentAuthenticatedRoles(any()) } returns listOf(ROLE_PLATFORM_ADMIN)
385+
386+
logger.info("should find all datasets and assert there are $numberOfDatasets")
387+
val datasetList = datasetApiService.findAllDatasets(organizationSaved.id!!, null, null)
388+
assertEquals(numberOfDatasets, datasetList.size)
389+
390+
val datasetIdListRetrieved = datasetList.map { it.id }
391+
assertTrue(datasetIdListCreated.containsAll(datasetIdListRetrieved))
392+
assertTrue(datasetIdListRetrieved.containsAll(datasetIdListCreated))
393+
}
394+
369395
@Test
370396
fun `test find All Datasets as Organization User`() {
371397
organizationSaved = organizationApiService.registerOrganization(organization)

dataset/src/main/kotlin/com/cosmotech/dataset/repository/DatasetRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ interface DatasetRepository : RedisDocumentRepository<Dataset, String> {
2727
pageRequest: PageRequest
2828
): Page<Dataset>
2929

30-
@Query("(@organizationId:{\$organizationId})")
31-
fun findByOrganizationIdNoSecurity(
30+
@Query("@organizationId:{\$organizationId}")
31+
fun findByOrganizationId(
3232
@Sanitize @Param("organizationId") organizationId: String,
3333
pageRequest: PageRequest
3434
): Page<Dataset>

dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class DatasetServiceImpl(
155155
val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties)
156156
datasetRepository.findByOrganizationId(organizationId, currentUser, it).toList()
157157
} else {
158-
datasetRepository.findByOrganizationIdNoSecurity(organizationId, it).toList()
158+
datasetRepository.findByOrganizationId(organizationId, it).toList()
159159
}
160160
}
161161
} else {
@@ -164,7 +164,7 @@ class DatasetServiceImpl(
164164
val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties)
165165
datasetRepository.findByOrganizationId(organizationId, currentUser, pageable).toList()
166166
} else {
167-
datasetRepository.findByOrganizationIdNoSecurity(organizationId, pageable).toList()
167+
datasetRepository.findByOrganizationId(organizationId, pageable).toList()
168168
}
169169
}
170170
result.forEach { it.security = updateSecurityVisibility(it).security }
@@ -1142,7 +1142,7 @@ class DatasetServiceImpl(
11421142
do {
11431143
val datasetList =
11441144
datasetRepository
1145-
.findByOrganizationIdNoSecurity(organizationUnregistered.organizationId, pageable)
1145+
.findByOrganizationId(organizationUnregistered.organizationId, pageable)
11461146
.toList()
11471147
datasetRepository.deleteAll(datasetList)
11481148
pageable = pageable.next()

dataset/src/test/kotlin/com/cosmotech/dataset/service/DatasetServiceImplTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ class DatasetServiceImplTests {
104104
@Test
105105
fun `findAllDatasets should return empty list when no dataset exists`() {
106106
every { organizationService.getVerifiedOrganization(ORGANIZATION_ID) } returns Organization()
107-
every { datasetRepository.findByOrganizationIdNoSecurity(any(), any<PageRequest>()) } returns
108-
Page.empty()
107+
every { datasetRepository.findByOrganizationId(any(), any<PageRequest>()) } returns Page.empty()
109108

110109
val result = datasetService.findAllDatasets(ORGANIZATION_ID, null, null)
111110
assertEquals(emptyList(), result)

0 commit comments

Comments
 (0)