Skip to content

Commit

Permalink
CORE-20721: Allow RBAC group parentGroupId to be nullable (#6269)
Browse files Browse the repository at this point in the history
* Allow parentGroupId to be nullable
* Update swaggerBaseline
* Fix IllegalArgumentException when deleting a group
* Update tests
* Remove duplicate clusterBuilder function
  • Loading branch information
BenYip123 authored Jul 9, 2024
1 parent 9bb7304 commit 0e8629c
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GroupEndpointImpl @Activate constructor(
return ResponseEntity.created(createGroupResult.convertToEndpointType())
}

override fun changeParentGroup(groupId: String, newParentGroupId: String): ResponseEntity<GroupResponseType> {
override fun changeParentGroup(groupId: String, newParentGroupId: String?): ResponseEntity<GroupResponseType> {
val principal = getRestThreadLocalContext()

val groupResponseDto = withPermissionManager(permissionManagementService.permissionManager, logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface GroupEndpoint : RestResource {
@RestPathParameter(description = "ID of the group to change parent.")
groupId: String,
@RestPathParameter(description = "New parent group ID.")
newParentGroupId: String
newParentGroupId: String?
): ResponseEntity<GroupResponseType>

@HttpPUT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class GroupContentResponseType(
/**
* ID of the parent group.
*/
val parentGroupId: String,
val parentGroupId: String?,

/**
* Group properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ data class ChangeGroupParentIdDto(
/**
* ID of the new parent Group.
*/
val newParentGroupId: String
val newParentGroupId: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class GroupContentResponseDto(
val id: String,
val lastUpdatedTimestamp: Instant,
val groupName: String,
val parentGroupId: String,
val parentGroupId: String?,
val properties: List<PropertyResponseDto>,
val roleAssociations: List<RoleAssociationResponseDto>,
val users: Set<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class GroupResponseDto(
val lastUpdatedTimestamp: Instant,
val version: Int,
val groupName: String,
val parentGroupId: String,
val parentGroupId: String?,
val properties: List<PropertyResponseDto>,
val roleAssociations: List<RoleAssociationResponseDto>
)
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class EntityValidationUtil(private val entityManager: EntityManager) {
WHERE ${Group::parentGroup.name}.${Group::id.name} = :groupId
""".trimIndent()

val numSubgroups = entityManager.createQuery(subgroupsQuery, Long::class.java)
val numSubgroups = entityManager.createQuery(subgroupsQuery, Long::class.javaObjectType)
.setParameter("groupId", groupId)
.singleResult

Expand All @@ -100,7 +100,7 @@ class EntityValidationUtil(private val entityManager: EntityManager) {
WHERE ${User::parentGroup.name}.${Group::id.name} = :groupId
""".trimIndent()

val numUsers = entityManager.createQuery(usersQuery, Long::class.java)
val numUsers = entityManager.createQuery(usersQuery, Long::class.javaObjectType)
.setParameter("groupId", groupId)
.singleResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class GroupWriterImplTest {
val group = Group("groupId", Instant.now(), "groupName", null)

val query = mock<TypedQuery<Long>>()
whenever(entityManager.createQuery(any(), eq(Long::class.java))).thenReturn(query)
whenever(entityManager.createQuery(any(), eq(Long::class.javaObjectType))).thenReturn(query)
whenever(query.setParameter(any<String>(), any<String>())).thenReturn(query)
whenever(query.singleResult).thenReturn(0)

Expand Down Expand Up @@ -389,7 +389,7 @@ class GroupWriterImplTest {
group.roleGroupAssociations.add(assoc)

val query = mock<TypedQuery<Long>>()
whenever(entityManager.createQuery(any(), eq(Long::class.java))).thenReturn(query)
whenever(entityManager.createQuery(any(), eq(Long::class.javaObjectType))).thenReturn(query)
whenever(query.setParameter(any<String>(), any<String>())).thenReturn(query)
whenever(query.singleResult).thenReturn(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class EntityValidationUtilTest {
on { id }.thenReturn(groupId)
}
val query = mock<TypedQuery<Long>>()
whenever(entityManager.createQuery(any(), eq(Long::class.java))).thenReturn(query)
whenever(entityManager.createQuery(any(), eq(Long::class.javaObjectType))).thenReturn(query)
whenever(query.setParameter("groupId", groupId)).thenReturn(query)
whenever(query.singleResult).thenReturn(0L)

Expand All @@ -255,7 +255,7 @@ class EntityValidationUtilTest {
on { id }.thenReturn(groupId)
}
val query = mock<TypedQuery<Long>>()
whenever(entityManager.createQuery(any(), eq(Long::class.java))).thenReturn(query)
whenever(entityManager.createQuery(any(), eq(Long::class.javaObjectType))).thenReturn(query)
whenever(query.setParameter("groupId", groupId)).thenReturn(query)
whenever(query.singleResult).thenReturn(1L)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@
"schema" : {
"type" : "string",
"description" : "New parent group ID.",
"nullable" : false,
"nullable" : true,
"example" : "string"
}
} ],
Expand Down Expand Up @@ -4979,7 +4979,7 @@
}
},
"GroupContentResponseType" : {
"required" : [ "id", "name", "parentGroupId", "properties", "roleAssociations", "subgroups", "updateTimestamp", "users" ],
"required" : [ "id", "name", "properties", "roleAssociations", "subgroups", "updateTimestamp", "users" ],
"type" : "object",
"properties" : {
"id" : {
Expand All @@ -4994,7 +4994,7 @@
},
"parentGroupId" : {
"type" : "string",
"nullable" : false,
"nullable" : true,
"example" : "string"
},
"properties" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class ClusterBuilder(clusterInfo: ClusterInfo, val REST_API_VERSION_PATH: String

@Suppress("unused")
// This method is used to change the parent group of an existing RBAC group
fun changeParentGroup(groupId: String, newParentGroupId: String): SimpleResponse {
fun changeParentGroup(groupId: String, newParentGroupId: String?): SimpleResponse {
return initialClient.put("/api/$REST_API_VERSION_PATH/group/$groupId/parent/changeParentId/$newParentGroupId", "")
}

Expand All @@ -814,12 +814,6 @@ class ClusterBuilder(clusterInfo: ClusterInfo, val REST_API_VERSION_PATH: String
return initialClient.delete("/api/$REST_API_VERSION_PATH/group/$groupId/role/$roleId")
}

@Suppress("unused")
// This method is used to get the content of an existing RBAC group
fun getGroupContent(groupId: String): SimpleResponse {
return initialClient.get("/api/$REST_API_VERSION_PATH/group/$groupId")
}

/** Start a flow */
fun flowStart(
holdingIdentityShortHash: String,
Expand Down

0 comments on commit 0e8629c

Please sign in to comment.