Skip to content

Commit fa2c946

Browse files
Make test suites public/private again! (#1337)
* Make test suites public/private again! ### What's done: * Improved manageTestSuitePermissionsComponent to be able to manage test suite visibility * Moved PermissionManagerMode to separate file * Added endpoint to make a batch of test suites public/private Co-authored-by: Kirill Gevorkyan <26010098+kgevorkyan@users.noreply.github.com>
1 parent 629df69 commit fa2c946

6 files changed

Lines changed: 356 additions & 59 deletions

File tree

save-backend/backend-api-docs.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,105 @@
572572
]
573573
}
574574
},
575+
"/api/v1/test-suites/{ownerOrganizationName}/batch-change-visibility": {
576+
"post": {
577+
"tags": [
578+
"rights",
579+
"organizations",
580+
"test-suites"
581+
],
582+
"summary": "Make given test suites public or private.",
583+
"description": "Make given test suites public or private.",
584+
"operationId": "changeTestSuiteVisibilityBatch",
585+
"parameters": [
586+
{
587+
"name": "ownerOrganizationName",
588+
"in": "path",
589+
"description": "name of an organization-maintainer",
590+
"required": true,
591+
"schema": {
592+
"type": "string"
593+
}
594+
},
595+
{
596+
"name": "isPublic",
597+
"in": "query",
598+
"description": "flag to make test suite public or private",
599+
"required": true,
600+
"schema": {
601+
"type": "boolean"
602+
}
603+
},
604+
{
605+
"name": "X-Authorization-Source",
606+
"in": "header",
607+
"required": true,
608+
"example": "basic"
609+
}
610+
],
611+
"requestBody": {
612+
"content": {
613+
"application/json": {
614+
"schema": {
615+
"type": "array",
616+
"items": {
617+
"type": "integer",
618+
"format": "int64"
619+
}
620+
}
621+
}
622+
},
623+
"required": true
624+
},
625+
"responses": {
626+
"403": {
627+
"description": "Given organization has been forbidden to change given test suite visibility",
628+
"content": {
629+
"*/*": {
630+
"schema": {
631+
"type": "string"
632+
}
633+
}
634+
}
635+
},
636+
"200": {
637+
"description": "Visibility changed",
638+
"content": {
639+
"*/*": {
640+
"schema": {
641+
"type": "string"
642+
}
643+
}
644+
}
645+
},
646+
"404": {
647+
"description": "Test suite or organization-maintainer doesn\u0027t exist",
648+
"content": {
649+
"*/*": {
650+
"schema": {
651+
"type": "string"
652+
}
653+
}
654+
}
655+
},
656+
"401": {
657+
"description": "Unauthorized",
658+
"content": {
659+
"*/*": {
660+
"schema": {
661+
"type": "string"
662+
}
663+
}
664+
}
665+
}
666+
},
667+
"security": [
668+
{
669+
"basic": []
670+
}
671+
]
672+
}
673+
},
575674
"/api/v1/test-suites/{organizationName}/get-by-ids": {
576675
"post": {
577676
"tags": [

save-backend/src/main/kotlin/com/saveourtool/save/backend/controllers/LnkOrganizationTestSuiteController.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,50 @@ class LnkOrganizationTestSuiteController(
381381
)
382382
}
383383

384+
@PostMapping("/{ownerOrganizationName}/batch-change-visibility")
385+
@RequiresAuthorizationSourceHeader
386+
@PreAuthorize("permitAll()")
387+
@Operation(
388+
method = "POST",
389+
summary = "Make given test suites public or private.",
390+
description = "Make given test suites public or private.",
391+
)
392+
@Parameters(
393+
Parameter(name = "ownerOrganizationName", `in` = ParameterIn.PATH, description = "name of an organization-maintainer", required = true),
394+
Parameter(name = "isPublic", `in` = ParameterIn.QUERY, description = "flag to make test suite public or private", required = true),
395+
)
396+
@ApiResponse(responseCode = "200", description = "Visibility changed")
397+
@ApiResponse(responseCode = "403", description = "Given organization has been forbidden to change given test suite visibility")
398+
@ApiResponse(responseCode = "404", description = "Test suite or organization-maintainer doesn't exist")
399+
fun changeTestSuiteVisibilityBatch(
400+
@PathVariable ownerOrganizationName: String,
401+
@RequestParam isPublic: Boolean,
402+
@RequestBody testSuiteIds: List<Long>,
403+
authentication: Authentication,
404+
): Mono<StringResponse> = getOrganizationWithPermissions(ownerOrganizationName, Permission.WRITE, authentication)
405+
.zipWith(testSuitesService.findTestSuitesByIds(testSuiteIds).toMono())
406+
.map { (organizationMaintainer, testSuites) ->
407+
testSuites.filter { testSuite ->
408+
testSuitePermissionEvaluator.hasPermission(
409+
organizationMaintainer,
410+
testSuite,
411+
Permission.WRITE,
412+
authentication,
413+
)
414+
}
415+
}
416+
.map { testSuites ->
417+
testSuites.onEach {
418+
it.isPublic = isPublic
419+
}
420+
.also {
421+
testSuitesService.updateTestSuites(it)
422+
}
423+
ResponseEntity.ok(
424+
"Successfully made test suites ${if (isPublic) "public." else "private."}"
425+
)
426+
}
427+
384428
private fun getOrganizationIfParticipant(
385429
organizationName: String,
386430
authentication: Authentication?,

save-backend/src/main/kotlin/com/saveourtool/save/backend/service/TestSuitesService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ class TestSuitesService(
256256
dto.version
257257
).orNotFound { "TestSuite (name=${dto.name} in ${dto.source.name} with version ${dto.version}) not found" }
258258

259+
/**
260+
* @param testSuites list of test suites to be updated
261+
* @return saved [testSuites]
262+
*/
263+
fun updateTestSuites(testSuites: List<TestSuite>): List<TestSuite> = testSuiteRepository.saveAll(testSuites)
264+
259265
companion object {
260266
private val log = LoggerFactory.getLogger(TestSuitesService::class.java)
261267
}

0 commit comments

Comments
 (0)