Skip to content

Commit

Permalink
Stopped Company Members from deleting their account.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugi-Games committed Oct 24, 2024
1 parent 22284fd commit fb57c2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main/java/com/MeetMate/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public ResponseEntity<?> deleteUser(@RequestHeader(name = "Authorization") Strin
if (tc == EntityNotFoundException.class)
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("message: " + t.getMessage());

if (tc == IllegalAccessException.class)
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("message: " + t.getMessage());

return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("type: " + tc + "\nmessage: " + t.getMessage());
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/MeetMate/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ public RefreshResponse refreshAccessToken(String refreshToken) {
}

@Transactional
public void deleteUser(String token) {
public void deleteUser(String token) throws IllegalAccessException {
String email = jwtService.extractUserEmail(token);
User user = userRepository
.findUserByEmail(email)
.orElseThrow(() -> new EntityNotFoundException("User does not exist."));
if (user.getRole() == UserRole.COMPANY_OWNER
|| user.getRole() == UserRole.COMPANY_MEMBER)
throw new IllegalAccessException("Company owners and members cannot delete their accounts");

userRepository.deleteByEmail(email);
}
Expand Down

0 comments on commit fb57c2d

Please sign in to comment.