Added a GlobalExceptionHandler to handle UserNotFoundException and RoleTransferRequiredException exceptions globally.
Admin Role Assignment:
Introduced a new /admin/assign-role endpoint to allow current admins to assign the admin role to other users.
POST /admin/assign-role endpoint requires a JSON payload with the newAdminUserName to assign admin rights to a specified user.
Role Transfer Enforcement for User Deletion:
Updated the deleteByUserName method in the UserService class to enforce role transfer if the user being deleted is the last remaining admin. This ensures that there is always at least one admin in the system.
Throws a RoleTransferRequiredException if only one admin exists, requiring a role transfer before deletion.
Additional Changes:
Updated UserRepository with a new method for counting users with a specific role.
If there are any improvements or additional considerations, please let me know. Thank you!
This pull request includes several enhancements:
Global Exception Handling:
GlobalExceptionHandler
to handleUserNotFoundException
andRoleTransferRequiredException
exceptions globally.Admin Role Assignment:
/admin/assign-role
endpoint to allow current admins to assign the admin role to other users.POST /admin/assign-role
endpoint requires a JSON payload with thenewAdminUserName
to assign admin rights to a specified user.Role Transfer Enforcement for User Deletion:
deleteByUserName
method in theUserService
class to enforce role transfer if the user being deleted is the last remaining admin. This ensures that there is always at least one admin in the system.RoleTransferRequiredException
if only one admin exists, requiring a role transfer before deletion.Additional Changes:
UserRepository
with a new method for counting users with a specific role.If there are any improvements or additional considerations, please let me know. Thank you!