mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 02:14:31 +02:00
Allow to delete users while keeping log entries.
This commit is contained in:
parent
dae4e38256
commit
a0f934169c
4 changed files with 102 additions and 14 deletions
|
@ -157,18 +157,6 @@ class UserController extends AdminPages\BaseAdminController
|
|||
return $this->_new($request, $em, $importer, $entity);
|
||||
}
|
||||
|
||||
protected function deleteCheck(AbstractNamedDBElement $entity): bool
|
||||
{
|
||||
if ($entity instanceof User) {
|
||||
//TODO: Find a better solution
|
||||
$this->addFlash('error', 'Currently it is not possible to delete a user, as this would break the log... This will be implemented later...');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="user_delete", methods={"DELETE"}, requirements={"id"="\d+"})
|
||||
*/
|
||||
|
|
|
@ -188,10 +188,19 @@ class LogDataTable implements DataTableTypeInterface
|
|||
'render' => function ($value, AbstractLogEntry $context) {
|
||||
$user = $context->getUser();
|
||||
|
||||
//If user was deleted, show the info from the username field
|
||||
if ($user === null) {
|
||||
return sprintf(
|
||||
'@%s [%s]',
|
||||
htmlentities($context->getUsername()),
|
||||
$this->translator->trans('log.target_deleted'),
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
$this->urlGenerator->generate('user_info', ['id' => $user->getID()]),
|
||||
$user->getFullName(true)
|
||||
htmlentities($user->getFullName(true))
|
||||
);
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -143,10 +143,16 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
|
||||
/** @var User The user which has caused this log entry
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", fetch="EAGER")
|
||||
* @ORM\JoinColumn(name="id_user", nullable=false)
|
||||
* @ORM\JoinColumn(name="id_user", nullable=true, onDelete="SET NULL")
|
||||
*/
|
||||
protected ?User $user = null;
|
||||
|
||||
/**
|
||||
* @var string The username of the user which has caused this log entry (shown if the user is deleted)
|
||||
* @ORM\Column(type="string", nullable=false)
|
||||
*/
|
||||
protected string $username = '';
|
||||
|
||||
/** @var DateTime The datetime the event associated with this log entry has occured
|
||||
* @ORM\Column(type="datetime", name="datetime")
|
||||
*/
|
||||
|
@ -203,9 +209,22 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
{
|
||||
$this->user = $user;
|
||||
|
||||
//Save the username for later use
|
||||
$this->username = $user->getUsername();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retuns the username of the user that caused the event (useful if the user was deleted).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp when the event that caused this log entry happened.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue