Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3ca2fe2c

Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)

Changed that user with ADMIN rights can not be removed

re #9755

Zobrazit rozdíly:

backend/src/main/java/cz/zcu/kiv/backendapi/user/UserServiceImpl.java
93 93
    //TODO maybe check if user is not deleting himself - or it might be ok
94 94
    @Override
95 95
    public void deleteUser(String username) {
96
        if (!userRepository.existsById(username)) {
96
        UserEntity userEntity = userRepository.findByEmail(username).orElseThrow(() -> {
97 97
            log.error(String.format(USER_NOT_FOUND, username));
98 98
            throw new UsernameNotFoundException(String.format(USER_NOT_FOUND, username));
99
        });
100
        if (userEntity.isAdmin()) {
101
            log.error("User with ADMIN rights can not be deleted");
102
            throw new ApiRequestException("User with ADMIN rights can not be deleted", HttpStatus.BAD_REQUEST);
99 103
        }
100
        userRepository.deleteById(username);
104
        userRepository.delete(userEntity);
101 105
    }
102 106

  
103 107
    @Override

Také k dispozici: Unified diff