Skip to content

Change query behind findAllDatasets when you're a Platform.Admin #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,32 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
assertEquals(numberOfDatasets - expectedPageSize, datasetList.size)
}

@Test
fun `test find All Datasets as Platform Admin with returned datasetID lists`() {
organizationSaved = organizationApiService.registerOrganization(organization)
val numberOfDatasets = 500
val datasetIdListCreated = mutableListOf<String>()
IntRange(1, numberOfDatasets).forEach {
datasetIdListCreated.add(
datasetApiService
.createDataset(
organizationSaved.id!!, makeDatasetWithRole("d-dataset-$it", "dataset-$it"))
.id!!)
}
logger.info("Change current user...")
every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.admin"
every { getCurrentAuthenticatedRoles(any()) } returns listOf(ROLE_PLATFORM_ADMIN)

logger.info("should find all datasets and assert there are $numberOfDatasets")
val datasetList = datasetApiService.findAllDatasets(organizationSaved.id!!, null, null)
assertEquals(numberOfDatasets, datasetList.size)

val datasetIdListRetrieved = datasetList.map { it.id }
assertTrue(datasetIdListCreated.containsAll(datasetIdListRetrieved))
assertTrue(datasetIdListRetrieved.containsAll(datasetIdListCreated))
}

@Test
fun `test find All Datasets as Organization User`() {
organizationSaved = organizationApiService.registerOrganization(organization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface DatasetRepository : RedisDocumentRepository<Dataset, String> {
pageRequest: PageRequest
): Page<Dataset>

@Query("(@organizationId:{\$organizationId})")
fun findByOrganizationIdNoSecurity(
@Query("@organizationId:{\$organizationId}")
fun findByOrganizationId(
@Sanitize @Param("organizationId") organizationId: String,
pageRequest: PageRequest
): Page<Dataset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class DatasetServiceImpl(
val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties)
datasetRepository.findByOrganizationId(organizationId, currentUser, it).toList()
} else {
datasetRepository.findByOrganizationIdNoSecurity(organizationId, it).toList()
datasetRepository.findByOrganizationId(organizationId, it).toList()
}
}
} else {
Expand All @@ -164,7 +164,7 @@ class DatasetServiceImpl(
val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties)
datasetRepository.findByOrganizationId(organizationId, currentUser, pageable).toList()
} else {
datasetRepository.findByOrganizationIdNoSecurity(organizationId, pageable).toList()
datasetRepository.findByOrganizationId(organizationId, pageable).toList()
}
}
result.forEach { it.security = updateSecurityVisibility(it).security }
Expand Down Expand Up @@ -1142,7 +1142,7 @@ class DatasetServiceImpl(
do {
val datasetList =
datasetRepository
.findByOrganizationIdNoSecurity(organizationUnregistered.organizationId, pageable)
.findByOrganizationId(organizationUnregistered.organizationId, pageable)
.toList()
datasetRepository.deleteAll(datasetList)
pageable = pageable.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class DatasetServiceImplTests {
@Test
fun `findAllDatasets should return empty list when no dataset exists`() {
every { organizationService.getVerifiedOrganization(ORGANIZATION_ID) } returns Organization()
every { datasetRepository.findByOrganizationIdNoSecurity(any(), any<PageRequest>()) } returns
Page.empty()
every { datasetRepository.findByOrganizationId(any(), any<PageRequest>()) } returns Page.empty()

val result = datasetService.findAllDatasets(ORGANIZATION_ID, null, null)
assertEquals(emptyList(), result)
Expand Down
Loading