@@ -397,6 +397,48 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
397397 assertEquals(0 , datasetList.size)
398398 }
399399
400+ @Test
401+ fun `PROD-12947 - test find All Datasets as Organization User` () {
402+ organizationSaved = organizationApiService.registerOrganization(organization)
403+
404+ // Create a dataset that current user should not see because he does not have permission to
405+ val numberOfDatasets = 200
406+ IntRange (1 , numberOfDatasets).forEach {
407+ datasetApiService.createDataset(
408+ organizationSaved.id!! ,
409+ makeDatasetWithRole(
410+ organizationId
= organizationSaved.id
!! , userName
= " [email protected] " ))
411+ }
412+
413+ // Explicitly set connected user information
414+ every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
415+ every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns " test.user"
416+ every { getCurrentAuthenticatedRoles(any()) } returns listOf (ROLE_ORGANIZATION_USER )
417+
418+ logger.info(" should not find a dataset because of lake of permission" )
419+ var datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , null , null )
420+ assertEquals(0 , datasetList.size)
421+
422+ // Create a dataset that current user should not see because it has been created under another
423+ // organization
424+ val newOrganization = organizationApiService.registerOrganization(makeOrganizationWithRole())
425+ val datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization =
426+ datasetApiService.createDataset(
427+ newOrganization.id!! , makeDatasetWithRole(organizationId = newOrganization.id!! ))
428+ assertNotNull(datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization)
429+ logger.info(
430+ " should not find a dataset because:" +
431+ " one was created with no permission assigned " +
432+ " one was created in another organization" )
433+ datasetList = datasetApiService.findAllDatasets(organizationSaved.id!! , null , null )
434+ assertEquals(0 , datasetList.size)
435+
436+ logger.info(" should find only one dataset" )
437+ datasetList = datasetApiService.findAllDatasets(newOrganization.id!! , null , null )
438+ assertEquals(1 , datasetList.size)
439+ assertEquals(datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization, datasetList[0 ])
440+ }
441+
400442 @Test
401443 fun `test find All Datasets with different pagination params` () {
402444 organizationSaved = organizationApiService.registerOrganization(organization)
0 commit comments