Error:
When clicking the "Update" button while running the tut-react-and-spring-data-rest/security project, the Data is not updated. This is because the Manager is not correctly mapped to the Employee.
Solution (proposed):
Add HandleBeforeSave in class com.greglturnquist.payroll.SpringDataRestEventHandler.java
Add method
@HandleBeforeSave public void applyUserInformationBeforeSave(Employee employee) { String name = SecurityContextHolder.getContext().getAuthentication().getName(); Manager manager = this.managerRepository.findByName(name); if (manager == null) { Manager newManager = new Manager(); newManager.setName(name); newManager.setRoles(new String[]{"ROLE_MANAGER"}); manager = this.managerRepository.save(newManager); } employee.setManager(manager); }
Since there is so much repeated code, an advanced refactoring would be to have a single method adding the manager to Employee for both @HandleBeforeSave and @HandleBeforeCreate.
Error: When clicking the "Update" button while running the tut-react-and-spring-data-rest/security project, the Data is not updated. This is because the Manager is not correctly mapped to the Employee.
Solution (proposed): Add HandleBeforeSave in class com.greglturnquist.payroll.SpringDataRestEventHandler.java Add method
@HandleBeforeSave public void applyUserInformationBeforeSave(Employee employee) { String name = SecurityContextHolder.getContext().getAuthentication().getName(); Manager manager = this.managerRepository.findByName(name); if (manager == null) { Manager newManager = new Manager(); newManager.setName(name); newManager.setRoles(new String[]{"ROLE_MANAGER"}); manager = this.managerRepository.save(newManager); } employee.setManager(manager); }
Since there is so much repeated code, an advanced refactoring would be to have a single method adding the manager to Employee for both @HandleBeforeSave and @HandleBeforeCreate.
thanks