a-n-u-p-01 / Journal-Rest-API

Open to contribute, improve your debug skill by contributing this project. Thank you!
6 stars 1 forks source link

Enhance User Management: Global Exception Handling, Admin Role Assignment, and Role Transfer Enforcement #5

Closed Guhapriya01 closed 1 week ago

Guhapriya01 commented 1 week ago

This pull request includes several enhancements:

  1. Global Exception Handling:

    • Added a GlobalExceptionHandler to handle UserNotFoundException and RoleTransferRequiredException exceptions globally.
  2. 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.
  3. 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:

If there are any improvements or additional considerations, please let me know. Thank you!