prohibit banning admins
This commit is contained in:
parent
a8480602c9
commit
141369cdec
@ -0,0 +1,7 @@
|
||||
package com.example.nto.service.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
public class CantBanAnAdminException extends RuntimeException {}
|
@ -9,10 +9,7 @@ import com.example.nto.repository.CodeRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.repository.EntryRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import com.example.nto.service.exception.CodeNotFoundException;
|
||||
import com.example.nto.service.exception.EmployeeBannedException;
|
||||
import com.example.nto.service.exception.EmployeeNotFoundException;
|
||||
import com.example.nto.service.exception.NotAnAdminException;
|
||||
import com.example.nto.service.exception.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -81,6 +78,10 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
@Override
|
||||
public void banEmployee(String login) {
|
||||
employeeExists(login);
|
||||
var e = getEmployee(login);
|
||||
if (e.getRole() == EmployeeRoleType.ADMIN) {
|
||||
throw new CantBanAnAdminException();
|
||||
}
|
||||
var employee = getEmployee(login);
|
||||
employee.setIsBanned(true);
|
||||
employeeRepository.save(employee);
|
||||
|
Loading…
x
Reference in New Issue
Block a user