Add warning about bound resource when removing a user
The resource will be unbound if the user confirm the removal. FEA: ItEr76S27ResourceBinding
This commit is contained in:
parent
a751b266b4
commit
9d7b1754b4
2 changed files with 27 additions and 0 deletions
|
|
@ -254,6 +254,23 @@ public class UserCRUDController extends BaseCRUDController<User> implements
|
|||
return userModel.getUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean beforeDeleting(User user) {
|
||||
Worker worker = user.getWorker();
|
||||
if (worker != null) {
|
||||
try {
|
||||
return Messagebox
|
||||
.show(_("User is bound to resource \"{0}\" and it will be unbound. Do you want to continue with user removal?",
|
||||
worker.getShortDescription()),
|
||||
_("Confirm remove user"), Messagebox.YES
|
||||
| Messagebox.NO, Messagebox.QUESTION) == Messagebox.YES;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(User user) throws InstanceNotFoundException {
|
||||
userModel.confirmRemove(user);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import org.libreplan.business.common.Configuration;
|
|||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.common.exceptions.ValidationException;
|
||||
import org.libreplan.business.resources.daos.IWorkerDAO;
|
||||
import org.libreplan.business.resources.entities.Worker;
|
||||
import org.libreplan.business.users.daos.IUserDAO;
|
||||
import org.libreplan.business.users.entities.Profile;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
|
|
@ -62,6 +64,9 @@ public class UserModel implements IUserModel {
|
|||
@Autowired
|
||||
private IDBPasswordEncoderService dbPasswordEncoderService;
|
||||
|
||||
@Autowired
|
||||
private IWorkerDAO workerDAO;
|
||||
|
||||
private User user;
|
||||
|
||||
private String clearNewPassword;
|
||||
|
|
@ -223,6 +228,11 @@ public class UserModel implements IUserModel {
|
|||
@Override
|
||||
@Transactional
|
||||
public void confirmRemove(User user) throws InstanceNotFoundException {
|
||||
Worker worker = user.getWorker();
|
||||
if (worker != null) {
|
||||
worker.setUser(null);
|
||||
workerDAO.save(worker);
|
||||
}
|
||||
userDAO.remove(user);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue