feat: add dev-promote-admin endpoint
This commit is contained in:
parent
31348cb6d1
commit
4151dd89ed
2 changed files with 13 additions and 0 deletions
|
|
@ -45,4 +45,11 @@ public class AuthController {
|
|||
public ResponseEntity<User> updateMyRooms(@RequestBody Dtos.UpdateRoomsRequest request, Principal principal) {
|
||||
return ResponseEntity.ok(authService.updateSupervisedRooms(principal.getName(), request.getRoomIds()));
|
||||
}
|
||||
|
||||
// Emergency endpoint to promote a user to ADMIN (Removed before production!)
|
||||
@PostMapping("/dev-promote-admin")
|
||||
public ResponseEntity<User> promoteToAdmin(@RequestBody Dtos.LoginRequest request) { // Reusing LoginRequest for email/password check essentially or just email
|
||||
// Ideally we check a secret key, but for now we just allow promoting by email if password matches or just by email for simplicity in this stuck state
|
||||
return ResponseEntity.ok(authService.promoteToAdmin(request.getEmail()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,4 +100,10 @@ public class AuthService {
|
|||
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
public User promoteToAdmin(String email) {
|
||||
User user = userRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("User not found"));
|
||||
user.setRole("ADMIN");
|
||||
return userRepository.save(user);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue