Skip to content

Commit

Permalink
delete and changeParentId endpoints emplemented
Browse files Browse the repository at this point in the history
Signed-off-by: TomFitzpatrick <[email protected]>
  • Loading branch information
Tom-Fitzpatrick committed Jun 26, 2024
1 parent ce0f07e commit e2441b7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import net.corda.libs.permissions.endpoints.v1.group.types.GroupContentResponseT
import net.corda.libs.permissions.endpoints.v1.group.types.GroupResponseType
import net.corda.libs.permissions.manager.request.AddRoleToGroupRequestDto
import net.corda.libs.permissions.manager.request.ChangeGroupParentIdDto
import net.corda.libs.permissions.manager.request.DeleteGroupRequestDto
import net.corda.libs.permissions.manager.request.RemoveRoleFromGroupRequestDto
import net.corda.libs.platform.PlatformInfoProvider
import net.corda.permissions.management.PermissionManagementService
Expand Down Expand Up @@ -93,7 +94,13 @@ class GroupEndpointImpl @Activate constructor(
}

override fun deleteGroup(groupId: String): ResponseEntity<GroupResponseType> {
throw NotImplementedError("Not implemented yet")
val principal = getRestThreadLocalContext()

val groupResponseDto = withPermissionManager(permissionManagementService.permissionManager, logger) {
deleteGroup(DeleteGroupRequestDto(principal, groupId))
}

return ResponseEntity.deleted(groupResponseDto.convertToEndpointType())
}

private fun getRestThreadLocalContext(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Suppress("TooManyFunctions")

package net.corda.libs.permissions.endpoints.v1.converter

import net.corda.libs.permissions.endpoints.v1.group.types.CreateGroupType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ interface PermissionManagementCache : Lifecycle {
fun getGroup(groupId: String): Group?
fun getRole(roleId: String): Role?
fun getPermission(permissionId: String): Permission?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import net.corda.data.permissions.Group
import net.corda.data.permissions.management.PermissionManagementRequest
import net.corda.data.permissions.management.PermissionManagementResponse
import net.corda.data.permissions.management.group.AddRoleToGroupRequest
import net.corda.data.permissions.management.group.ChangeGroupParentIdRequest
import net.corda.data.permissions.management.group.CreateGroupRequest
import net.corda.data.permissions.management.group.DeleteGroupRequest
import net.corda.data.permissions.management.group.RemoveRoleFromGroupRequest
import net.corda.data.permissions.management.user.AddRoleToUserRequest
import net.corda.libs.configuration.SmartConfig
import net.corda.libs.permissions.management.cache.PermissionManagementCache
import net.corda.libs.permissions.manager.PermissionGroupManager
Expand All @@ -15,6 +16,7 @@ import net.corda.libs.permissions.manager.impl.converter.convertToResponseDto
import net.corda.libs.permissions.manager.request.AddRoleToGroupRequestDto
import net.corda.libs.permissions.manager.request.ChangeGroupParentIdDto
import net.corda.libs.permissions.manager.request.CreateGroupRequestDto
import net.corda.libs.permissions.manager.request.DeleteGroupRequestDto
import net.corda.libs.permissions.manager.request.RemoveRoleFromGroupRequestDto
import net.corda.libs.permissions.manager.response.GroupContentResponseDto
import net.corda.libs.permissions.manager.response.GroupResponseDto
Expand Down Expand Up @@ -48,7 +50,19 @@ class PermissionGroupManagerImpl(
}

override fun changeParentGroup(changeGroupParentIdDto: ChangeGroupParentIdDto): GroupResponseDto {
throw NotImplementedError("Not implemented yet")
val result = sendPermissionWriteRequest<Group>(
rpcSender,
writerTimeout,
PermissionManagementRequest(
changeGroupParentIdDto.requestedBy,
null,
ChangeGroupParentIdRequest(
changeGroupParentIdDto.groupId,
changeGroupParentIdDto.newParentGroupId,
)
)
)
return result.convertToResponseDto()
}

override fun addRoleToGroup(addRoleToGroupRequestDto: AddRoleToGroupRequestDto): GroupResponseDto {
Expand All @@ -57,7 +71,7 @@ class PermissionGroupManagerImpl(
writerTimeout,
PermissionManagementRequest(
addRoleToGroupRequestDto.requestedBy,
"cluster",
null,
AddRoleToGroupRequest(
addRoleToGroupRequestDto.groupId,
addRoleToGroupRequestDto.roleId,
Expand All @@ -72,8 +86,8 @@ class PermissionGroupManagerImpl(
rpcSender,
writerTimeout,
PermissionManagementRequest(
"cluster",
"cluster",
removeRoleFromGroupRequestDto.requestedBy,
null,
RemoveRoleFromGroupRequest(
removeRoleFromGroupRequestDto.groupId,
removeRoleFromGroupRequestDto.roleId,
Expand Down Expand Up @@ -102,4 +116,17 @@ class PermissionGroupManagerImpl(
subgroups
)
}

override fun deleteGroup(deleteGroupRequestDto: DeleteGroupRequestDto): GroupResponseDto {
val result = sendPermissionWriteRequest<Group>(
rpcSender,
writerTimeout,
PermissionManagementRequest(
deleteGroupRequestDto.requestedBy,
null,
DeleteGroupRequest(deleteGroupRequestDto.groupId)
)
)
return result.convertToResponseDto()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package net.corda.libs.permissions.manager
import net.corda.libs.permissions.manager.request.AddRoleToGroupRequestDto
import net.corda.libs.permissions.manager.request.ChangeGroupParentIdDto
import net.corda.libs.permissions.manager.request.CreateGroupRequestDto
import net.corda.libs.permissions.manager.request.CreateUserRequestDto
import net.corda.libs.permissions.manager.request.DeleteGroupRequestDto
import net.corda.libs.permissions.manager.request.RemoveRoleFromGroupRequestDto
import net.corda.libs.permissions.manager.response.GroupContentResponseDto
import net.corda.libs.permissions.manager.response.GroupResponseDto
import net.corda.libs.permissions.manager.response.UserResponseDto

/**
* The [PermissionGroupManager] provides functionality for managing groups within the permission system.
Expand Down Expand Up @@ -37,4 +36,9 @@ interface PermissionGroupManager {
* Get a group in the RBAC Permission System identified by `GroupId`.
*/
fun getGroupContent(groupId: String): GroupContentResponseDto?
}

/**
* Delete a group in the RBAC Permission System identified by `GroupId`.
*/
fun deleteGroup(deleteGroupRequestDto: DeleteGroupRequestDto): GroupResponseDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.corda.libs.permissions.manager.request

class DeleteGroupRequestDto(
val requestedBy: String,
val groupId: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ data class GroupContentResponseDto(
val roleAssociations: List<RoleAssociationResponseDto>,
val users: List<String>,
val subgroups: List<String>
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class GroupResponseDto(
val parentGroupId: String,
val properties: List<PropertyResponseDto>,
val roleAssociations: List<RoleAssociationResponseDto>
)
)

0 comments on commit e2441b7

Please sign in to comment.