From 55f3cd2172d6134ce3ae3d87103d352cb34e595a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 24 Aug 2020 15:21:10 +0200 Subject: [PATCH] Internal: Validate resource, format code --- src/CoreBundle/Controller/ResourceController.php | 5 ++--- src/CoreBundle/Repository/IllustrationRepository.php | 1 + .../Resources/views/Resource/info_details.html.twig | 6 ++++-- src/CoreBundle/Traits/ControllerTrait.php | 4 ++-- src/CoreBundle/Traits/ResourceControllerTrait.php | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index e18bd51b53..51f0d73cc3 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -623,9 +623,9 @@ class ResourceController extends AbstractResourceController implements CourseCon /** @var AbstractResource $resource */ $resource = $repository->getResourceFromResourceNode($nodeId); - $resourceNode = $resource->getResourceNode(); - $this->denyAccessUnlessValidResource($resource); + + $resourceNode = $resource->getResourceNode(); $this->setBreadCrumb($request, $resourceNode); $this->denyAccessUnlessGranted( @@ -701,7 +701,6 @@ class ResourceController extends AbstractResourceController implements CourseCon /** @var AbstractResource $resource */ $resource = $repository->getResourceFromResourceNode($id); - $this->denyAccessUnlessValidResource($resource); $resourceNode = $resource->getResourceNode(); diff --git a/src/CoreBundle/Repository/IllustrationRepository.php b/src/CoreBundle/Repository/IllustrationRepository.php index 55232cc03f..0a5850918c 100644 --- a/src/CoreBundle/Repository/IllustrationRepository.php +++ b/src/CoreBundle/Repository/IllustrationRepository.php @@ -155,6 +155,7 @@ final class IllustrationRepository extends ResourceRepository implements GridInt 'tool' => $node->getResourceType()->getTool(), 'type' => $node->getResourceType()->getName(), ]; + if (!empty($filter)) { $params['filter'] = $filter; } diff --git a/src/CoreBundle/Resources/views/Resource/info_details.html.twig b/src/CoreBundle/Resources/views/Resource/info_details.html.twig index 9d80c9f391..920658e9d1 100644 --- a/src/CoreBundle/Resources/views/Resource/info_details.html.twig +++ b/src/CoreBundle/Resources/views/Resource/info_details.html.twig @@ -14,7 +14,9 @@ {% endif %}
{{ 'Created at' | trans }}
- moment('{{ resource.resourceNode.createdAt | date("Y-m-d H:i:s") }}').fromNow(); + {{ resource.resourceNode.createdAt | date_to_time_ago }}
@@ -22,7 +24,7 @@
{{ resource.resourceNode.updatedAt | date_to_time_ago }}
{{ 'Author' | trans }}
-{#
{{ resource.resourceNode.creator }}
#} +
{{ resource.resourceNode.creator }}
{# Show where the file was added#} {# {% if resource.resourceNode.resourceLinks %}#} diff --git a/src/CoreBundle/Traits/ControllerTrait.php b/src/CoreBundle/Traits/ControllerTrait.php index 46335f09e9..e158cc0346 100644 --- a/src/CoreBundle/Traits/ControllerTrait.php +++ b/src/CoreBundle/Traits/ControllerTrait.php @@ -4,12 +4,11 @@ namespace Chamilo\CoreBundle\Traits; -//use Chamilo\CoreBundle\Block\BreadcrumbBlockService; use Chamilo\CoreBundle\Component\Utils\Glide; use Chamilo\CoreBundle\Manager\SettingsManager; use Chamilo\CoreBundle\Repository\IllustrationRepository; use Chamilo\CoreBundle\Repository\ResourceFactory; -use Chamilo\CourseBundle\Repository\CAttendanceRepository; +use Chamilo\CourseBundle\Repository\CAnnouncementRepository; use Chamilo\CourseBundle\Repository\CDocumentRepository; use Knp\Menu\FactoryInterface as MenuFactoryInterface; use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory; @@ -31,6 +30,7 @@ trait ControllerTrait $services[] = IllustrationRepository::class; $services[] = CDocumentRepository::class; + $services[] = CAnnouncementRepository::class; /*$services[] = CAttendanceRepository::class; $services[] = CDocumentRepository::class; diff --git a/src/CoreBundle/Traits/ResourceControllerTrait.php b/src/CoreBundle/Traits/ResourceControllerTrait.php index 43bde844ea..62baffb16c 100644 --- a/src/CoreBundle/Traits/ResourceControllerTrait.php +++ b/src/CoreBundle/Traits/ResourceControllerTrait.php @@ -36,7 +36,7 @@ trait ResourceControllerTrait return $this->container->get($name); } - public function denyAccessUnlessValidResource(AbstractResource $resource) + public function denyAccessUnlessValidResource(AbstractResource $resource = null) { if (null === $resource) { throw new EntityNotFoundException($this->trans('Resource doesn\'t exists.'));