allow to reassign timesheets from delete-user form (#2159)

This commit is contained in:
Kevin Papst
2020-12-03 22:52:58 +01:00
committed by GitHub
parent 4302ecd6ea
commit 0d2d40791a
6 changed files with 149 additions and 14 deletions

View File

@@ -16,7 +16,9 @@ use App\Export\Spreadsheet\UserExporter;
use App\Export\Spreadsheet\Writer\BinaryFileResponseWriter;
use App\Export\Spreadsheet\Writer\XlsxWriter;
use App\Form\Toolbar\UserToolbarForm;
use App\Form\Type\UserType;
use App\Form\UserCreateType;
use App\Repository\Query\UserFormTypeQuery;
use App\Repository\Query\UserQuery;
use App\Repository\TimesheetRepository;
use App\Repository\UserRepository;
@@ -167,6 +169,16 @@ final class UserController extends AbstractController
'data-msg-error' => 'action.delete.error',
]
])
->add('user', UserType::class, [
'query_builder' => function (UserRepository $repo) use ($userToDelete) {
$query = new UserFormTypeQuery();
$query->addUserToIgnore($userToDelete);
$query->setUser($this->getUser());
return $repo->getQueryBuilderForFormType($query);
},
'required' => false,
])
->setAction($this->generateUrl('admin_user_delete', ['id' => $userToDelete->getId()]))
->setMethod('POST')
->getForm();
@@ -174,23 +186,21 @@ final class UserController extends AbstractController
$deleteForm->handleRequest($request);
if ($deleteForm->isSubmitted() && $deleteForm->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($userToDelete);
$entityManager->flush();
$this->flashSuccess('action.delete.success');
try {
$this->getRepository()->deleteUser($userToDelete, $deleteForm->get('user')->getData());
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_user');
}
return $this->render(
'user/delete.html.twig',
[
'user' => $userToDelete,
'stats' => $stats,
'form' => $deleteForm->createView(),
]
);
return $this->render('user/delete.html.twig', [
'user' => $userToDelete,
'stats' => $stats,
'form' => $deleteForm->createView(),
]);
}
/**