Skip to content

Commit 29e8780

Browse files
feat: add main dataset sharing on runner or scenario sharing
1 parent c1dc19c commit 29e8780

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
11671167
}
11681168

11691169
@Test
1170-
fun `when sharing a runner, the linked dataset default security should be set to at least viewer if the dataset isn't main`() {
1170+
fun `when sharing a runner, the linked dataset default security should be set to viewer if the dataset default security is none`() {
11711171
runnerSaved.datasetList!!.removeLast()
11721172
val linkedDatasets = mutableListOf<Dataset>()
11731173
listOf(ROLE_NONE, ROLE_VIEWER, ROLE_USER, ROLE_EDITOR, ROLE_ADMIN).forEach { role ->
@@ -1189,8 +1189,8 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
11891189
runnerApiService.setRunnerDefaultSecurity(
11901190
organizationSaved.id!!, workspaceSaved.id!!, runnerSaved.id!!, RunnerRole(ROLE_EDITOR))
11911191

1192-
// Only one result correspond, the dataset with default security none and main=false
1193-
verify(exactly = 1) { datasetApiService.updateDefaultSecurity(any(), any(), ROLE_VIEWER) }
1192+
// Only two result correspond, the datasets with default security none
1193+
verify(exactly = 2) { datasetApiService.updateDefaultSecurity(any(), any(), ROLE_VIEWER) }
11941194
}
11951195

11961196
@Test

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,19 +518,19 @@ class RunnerService(
518518
val linkedDataset =
519519
datasetApiService.findByOrganizationIdAndDatasetId(
520520
this.runner.organizationId!!, datasetId)
521-
if (linkedDataset!!.main == true) return@forEach
521+
if (datasetRole == ROLE_NONE && linkedDataset!!.main == true) return@forEach
522522
// If the dataset default security is different from none,
523523
// Then it's already viewer or higher and doesn't need to change
524-
if (datasetRole == ROLE_VIEWER && linkedDataset.security!!.default != ROLE_NONE)
524+
if (datasetRole == ROLE_VIEWER && linkedDataset!!.security!!.default != ROLE_NONE)
525525
return@forEach
526526
// If the dataset default security is different from viewer,
527527
// Then it's either already none or higher than viewer and doesn't need to change
528-
if (datasetRole == ROLE_NONE && linkedDataset.security!!.default != ROLE_VIEWER)
528+
if (datasetRole == ROLE_NONE && linkedDataset!!.security!!.default != ROLE_VIEWER)
529529
return@forEach
530530
// Filter on dataset copy (because we do not want to update main dataset as it can be shared
531531
// between runners)
532532
datasetApiService.updateDefaultSecurity(
533-
this.runner.organizationId!!, linkedDataset, datasetRole)
533+
this.runner.organizationId!!, linkedDataset!!, datasetRole)
534534
}
535535
}
536536
}

scenario/src/integrationTest/kotlin/com/cosmotech/scenario/service/ScenarioServiceIntegrationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
12611261
}
12621262

12631263
@Test
1264-
fun `when sharing a scenario, the linked dataset default security should be set to at least viewer if the dataset isn't main`() {
1264+
fun `when sharing a scenario, the linked dataset default security should be set to viewer if the dataset default security is none`() {
12651265
scenarioSaved.datasetList!!.removeLast()
12661266
val linkedDatasets = mutableListOf<Dataset>()
12671267
listOf(ROLE_NONE, ROLE_VIEWER, ROLE_USER, ROLE_EDITOR, ROLE_ADMIN).forEach { role ->
@@ -1283,8 +1283,8 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
12831283
scenarioApiService.setScenarioDefaultSecurity(
12841284
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!, ScenarioRole(ROLE_EDITOR))
12851285

1286-
// Only one result correspond, the dataset with default security none and main=false
1287-
verify(exactly = 1) { datasetApiService.updateDefaultSecurity(any(), any(), ROLE_VIEWER) }
1286+
// Only two result correspond, the datasets with default security none
1287+
verify(exactly = 2) { datasetApiService.updateDefaultSecurity(any(), any(), ROLE_VIEWER) }
12881288
}
12891289

12901290
@Test

scenario/src/main/kotlin/com/cosmotech/scenario/service/ScenarioServiceImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,13 +1169,13 @@ internal class ScenarioServiceImpl(
11691169
if (scenarioRole == ROLE_NONE) datasetRole = ROLE_NONE
11701170
scenario.datasetList!!.forEach { datasetId ->
11711171
val dataset = datasetService.findByOrganizationIdAndDatasetId(organizationId, datasetId)
1172-
if (dataset!!.main == true) return@forEach
1172+
if (datasetRole == ROLE_NONE && dataset!!.main == true) return@forEach
11731173
// We do not want to lower the default security if it's higher than viewer
1174-
if (datasetRole == ROLE_VIEWER && dataset.security!!.default != ROLE_NONE) return@forEach
1175-
if (datasetRole == ROLE_NONE && dataset.security!!.default != ROLE_VIEWER) return@forEach
1174+
if (datasetRole == ROLE_VIEWER && dataset!!.security!!.default != ROLE_NONE) return@forEach
1175+
if (datasetRole == ROLE_NONE && dataset!!.security!!.default != ROLE_VIEWER) return@forEach
11761176
// Filter on dataset copy (because we do not want to update main dataset as it can be shared
11771177
// between scenarios)
1178-
datasetService.updateDefaultSecurity(organizationId, dataset, datasetRole)
1178+
datasetService.updateDefaultSecurity(organizationId, dataset!!, datasetRole)
11791179
}
11801180
}
11811181

0 commit comments

Comments
 (0)