Skip to content

Commit 701a6db

Browse files
committed
Security: gate document template creation on course teacher role instead of resource node edit
1 parent 85a5a44 commit 701a6db

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/CoreBundle/Controller/TemplateController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
1515
use Chamilo\CoreBundle\Repository\SystemTemplateRepository;
1616
use Chamilo\CoreBundle\Repository\TemplatesRepository;
17+
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter;
1718
use Chamilo\CoreBundle\Settings\SettingsManager;
1819
use Chamilo\CourseBundle\Entity\CDocument;
1920
use Chamilo\CourseBundle\Repository\CDocumentRepository;
@@ -45,7 +46,12 @@ public function createDocumentTemplate(Request $request, EntityManagerInterface
4546
return $this->json(['error' => 'Document not found.'], Response::HTTP_NOT_FOUND);
4647
}
4748

48-
$this->denyAccessUnlessGranted('EDIT', $document->getResourceNode());
49+
$documentCourse = $document->getFirstResourceLink()?->getCourse();
50+
if (!$documentCourse instanceof Course) {
51+
throw $this->createAccessDeniedException();
52+
}
53+
54+
$this->denyAccessUnlessGranted(CourseVoter::EDIT, $documentCourse);
4955

5056
$user = $userHelper->getCurrent();
5157
$course = null;

0 commit comments

Comments
 (0)