Skip to content

Commit

Permalink
chore: code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddseL committed Jan 9, 2025
1 parent d6b7f08 commit 0f71371
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import io.quarkus.arc.Lock
import jakarta.annotation.security.PermitAll
import jakarta.enterprise.context.ApplicationScoped
import jakarta.transaction.Transactional
import jakarta.ws.rs.PathParam

@PermitAll
@ApplicationScoped
Expand Down Expand Up @@ -531,6 +530,7 @@ class UiResourceImpl(
return componentStatusApiService.getComponentsStatusForOrganizationId(environmentId, loggedInUser.organizationId!!)
}

@Transactional
override fun checkOrganizationDeletion(organizationId: String): OrganizationDeletionCheck {
authUtils.requiresRole(Roles.UserRoles.AUTHORITY_ADMIN)
return organizationDeletionApiService.checkOrganizationDeletion(organizationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class OrganizationDeletionApiService(

fun deleteOrganizationAndDependencies(organizationId: String, adminUserId: String): IdResponse {
organizationDeletionService.deleteOrganizationAndDependencies(organizationId, adminUserId)

return IdResponse(organizationId, timeUtils.now())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ class OrganizationDeletionService(
) {

fun checkOrganizationDeletion(organizationId: String): OrganizationDeletionCheck {
val organizationDeletionCheck = OrganizationDeletionCheck(
return OrganizationDeletionCheck(
organizationId = organizationId,
canBeDeleted = !hasLastAuthorityAdmins(organizationId)
)

return organizationDeletionCheck
}

fun deleteOrganizationAndDependencies(organizationId: String, adminUserId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ class UserDeletionService(
val isLastParticipantAdmin = participantAdmins.singleOrNull()?.userId == userId
val isOrganizationCreator = organization.createdBy == userId

var possibleCreatorSuccessors = listOf<PossibleCreatorSuccessor>()
if (!isLastParticipantAdmin && isOrganizationCreator) {
possibleCreatorSuccessors = participantAdmins
val possibleCreatorSuccessors = if (!isLastParticipantAdmin && isOrganizationCreator) {
participantAdmins
.filter { it.userId != userId }
.map {
PossibleCreatorSuccessor(
Expand All @@ -49,17 +48,17 @@ class UserDeletionService(
lastName = it.lastName
)
}
} else {
emptyList()
}

val userDeletionCheck = UserDeletionCheck(
return UserDeletionCheck(
userId = userId,
canBeDeleted = !isLastAuthorityAdmin,
isLastParticipantAdmin = isLastParticipantAdmin,
isOrganizationCreator = isOrganizationCreator,
possibleCreatorSuccessors = possibleCreatorSuccessors
)

return userDeletionCheck
}

fun deleteUserAndHandleDependencies(
Expand All @@ -74,9 +73,9 @@ class UserDeletionService(
}
connectorService.updateConnectorsCreator(organization.createdBy, userId)
centralComponentService.updateCentralComponentsCreator(organization.createdBy, userId)
keycloakService.deleteUser(userId)
userService.deleteInvitationReference(userId)
userService.deleteUser(userId)
keycloakService.deleteUser(userId)

Log.info(
"User deleted. Ownership of connectors and central components handed over to organization creator. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div *ngIf="modalData.isReady" class="px-4 py-3 confirmation-dialog-prose">
<div *ngIf="!modalData.data.canBeDeleted" class="space-y-1">
<p>The organization cannot be deleted.</p>
<p>This organization cannot be deleted.</p>
</div>
<div
*ngIf="modalData.data.canBeDeleted"
Expand All @@ -23,10 +23,10 @@
>.
</p>
<p>
This will result in deleting the whole organization, including all of
its users, connectors and central components.
This will result in deleting irreversible the whole organization,
including all of its users, connectors and central components.
</p>
<p>Are you sure, you want to proceed?</p>
<p>Are you sure you want to proceed?</p>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div *ngIf="modalData.isReady" class="px-4 py-3 confirmation-dialog-prose">
<div *ngIf="!modalData.data.canBeDeleted" class="space-y-1">
<p>The user cannot be deleted.</p>
<p>This user cannot be deleted.</p>
</div>
<div
*ngIf="modalData.data.canBeDeleted && isLastParticipantAdmin"
Expand All @@ -23,10 +23,10 @@
>.
</p>
<p>
This will result in deleting the whole organization, including all of
its users, connectors and central components.
This will result in irreversibly deleting the whole organization,
including all of its users, connectors and central components.
</p>
<p>Are you sure, you want to proceed?</p>
<p>Are you sure you want to proceed?</p>
</div>
<div *ngIf="modalData.data.canBeDeleted && !isLastParticipantAdmin">
<div *ngIf="isOrganizationCreator" class="space-y-1">
Expand Down

0 comments on commit 0f71371

Please sign in to comment.