Show user history in user info page.

This commit is contained in:
Jan Böhmer 2020-04-04 15:45:14 +02:00
parent fe958781ea
commit fca2ad9d99
3 changed files with 44 additions and 9 deletions

View file

@ -42,6 +42,7 @@ declare(strict_types=1);
namespace App\Controller; namespace App\Controller;
use App\DataTables\LogDataTable;
use App\Entity\Attachments\UserAttachment; use App\Entity\Attachments\UserAttachment;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Events\SecurityEvent; use App\Events\SecurityEvent;
@ -53,6 +54,7 @@ use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper; use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException; use InvalidArgumentException;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Component\Asset\Packages; use Symfony\Component\Asset\Packages;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -163,7 +165,7 @@ class UserController extends AdminPages\BaseAdminController
* *
* @return Response * @return Response
*/ */
public function userInfo(?User $user, Packages $packages): Response public function userInfo(?User $user, Packages $packages, Request $request, DataTableFactory $dataTableFactory): Response
{ {
//If no user id was passed, then we show info about the current user //If no user id was passed, then we show info about the current user
if (null === $user) { if (null === $user) {
@ -177,6 +179,21 @@ class UserController extends AdminPages\BaseAdminController
$this->denyAccessUnlessGranted('read', $user); $this->denyAccessUnlessGranted('read', $user);
} }
$table = $this->dataTableFactory->createFromType(
LogDataTable::class,
[
'filter_elements' => $user,
'mode' => 'element_history',
],
['pageLength' => 10]
)
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
if ($this->getParameter('use_gravatar')) { if ($this->getParameter('use_gravatar')) {
$avatar = $this->getGravatar($user->getEmail(), 200, 'identicon'); $avatar = $this->getGravatar($user->getEmail(), 200, 'identicon');
} else { } else {
@ -195,6 +212,7 @@ class UserController extends AdminPages\BaseAdminController
'user' => $user, 'user' => $user,
'avatar' => $avatar, 'avatar' => $avatar,
'form' => $builder->getForm()->createView(), 'form' => $builder->getForm()->createView(),
'datatable' => $table,
]); ]);
} }

View file

@ -66,6 +66,7 @@ use Omines\DataTablesBundle\Column\TextColumn;
use Omines\DataTablesBundle\DataTable; use Omines\DataTablesBundle\DataTable;
use Omines\DataTablesBundle\DataTableTypeInterface; use Omines\DataTablesBundle\DataTableTypeInterface;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
@ -98,6 +99,16 @@ class LogDataTable implements DataTableTypeInterface
'filter_elements' => [], 'filter_elements' => [],
]); ]);
$optionsResolver->setAllowedTypes('filter_elements', ['array', 'object']);
$optionsResolver->setAllowedTypes('mode', 'string');
$optionsResolver->setNormalizer('filter_elements', function (Options $options, $value) {
if (!is_array($value)) {
return [$value];
}
return $value;
});
$optionsResolver->setAllowedValues('mode', ['system_log', 'element_history', 'last_activity']); $optionsResolver->setAllowedValues('mode', ['system_log', 'element_history', 'last_activity']);
} }

View file

@ -72,4 +72,10 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="mt-2">
{% if datatable is defined and datatable is not null %}
{% include "LogSystem/_log_table.html.twig" %}
{% endif %}
</div>
{% endblock %} {% endblock %}