From 0f713715f50f19153b9988cd16254ca752bde8f1 Mon Sep 17 00:00:00 2001 From: Patrick Schauer Date: Thu, 9 Jan 2025 14:19:50 +0100 Subject: [PATCH] chore: code review suggestions --- .../de/sovity/authorityportal/web/UiResourceImpl.kt | 2 +- .../OrganizationDeletionApiService.kt | 1 - .../web/services/OrganizationDeletionService.kt | 4 +--- .../web/services/UserDeletionService.kt | 13 ++++++------- .../organization-delete-dialog.component.html | 8 ++++---- .../user-delete-dialog.component.html | 8 ++++---- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/UiResourceImpl.kt b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/UiResourceImpl.kt index 0c87f497a..168caf02a 100644 --- a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/UiResourceImpl.kt +++ b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/UiResourceImpl.kt @@ -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 @@ -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) diff --git a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/organizationmanagement/OrganizationDeletionApiService.kt b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/organizationmanagement/OrganizationDeletionApiService.kt index f61d010b5..8c4d910d1 100644 --- a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/organizationmanagement/OrganizationDeletionApiService.kt +++ b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/organizationmanagement/OrganizationDeletionApiService.kt @@ -30,7 +30,6 @@ class OrganizationDeletionApiService( fun deleteOrganizationAndDependencies(organizationId: String, adminUserId: String): IdResponse { organizationDeletionService.deleteOrganizationAndDependencies(organizationId, adminUserId) - return IdResponse(organizationId, timeUtils.now()) } } diff --git a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/OrganizationDeletionService.kt b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/OrganizationDeletionService.kt index 182e2f495..9e5422ab5 100644 --- a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/OrganizationDeletionService.kt +++ b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/OrganizationDeletionService.kt @@ -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) { diff --git a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/UserDeletionService.kt b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/UserDeletionService.kt index 808925037..973b14683 100644 --- a/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/UserDeletionService.kt +++ b/authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/services/UserDeletionService.kt @@ -38,9 +38,8 @@ class UserDeletionService( val isLastParticipantAdmin = participantAdmins.singleOrNull()?.userId == userId val isOrganizationCreator = organization.createdBy == userId - var possibleCreatorSuccessors = listOf() - if (!isLastParticipantAdmin && isOrganizationCreator) { - possibleCreatorSuccessors = participantAdmins + val possibleCreatorSuccessors = if (!isLastParticipantAdmin && isOrganizationCreator) { + participantAdmins .filter { it.userId != userId } .map { PossibleCreatorSuccessor( @@ -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( @@ -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. " + diff --git a/authority-portal-frontend/src/app/shared/business/organization-delete-dialog/organization-delete-dialog.component.html b/authority-portal-frontend/src/app/shared/business/organization-delete-dialog/organization-delete-dialog.component.html index 260e7b5a4..249b47d8b 100644 --- a/authority-portal-frontend/src/app/shared/business/organization-delete-dialog/organization-delete-dialog.component.html +++ b/authority-portal-frontend/src/app/shared/business/organization-delete-dialog/organization-delete-dialog.component.html @@ -12,7 +12,7 @@
-

The organization cannot be deleted.

+

This organization cannot be deleted.

.

- 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.

-

Are you sure, you want to proceed?

+

Are you sure you want to proceed?

diff --git a/authority-portal-frontend/src/app/shared/business/user-delete-dialog/user-delete-dialog.component.html b/authority-portal-frontend/src/app/shared/business/user-delete-dialog/user-delete-dialog.component.html index 81974683f..1772d8525 100644 --- a/authority-portal-frontend/src/app/shared/business/user-delete-dialog/user-delete-dialog.component.html +++ b/authority-portal-frontend/src/app/shared/business/user-delete-dialog/user-delete-dialog.component.html @@ -12,7 +12,7 @@
-

The user cannot be deleted.

+

This user cannot be deleted.

.

- 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.

-

Are you sure, you want to proceed?

+

Are you sure you want to proceed?