|
11 | 11 | use Chamilo\CoreBundle\Entity\ResourceNode; |
12 | 12 | use Chamilo\CoreBundle\Entity\ResourceRight; |
13 | 13 | use Chamilo\CoreBundle\Entity\Session; |
| 14 | +use Chamilo\CoreBundle\Helpers\ResourceAclHelper; |
14 | 15 | use Chamilo\CoreBundle\Settings\SettingsManager; |
15 | 16 | use Chamilo\CourseBundle\Entity\CDocument; |
16 | 17 | use Chamilo\CourseBundle\Entity\CGroup; |
@@ -51,7 +52,8 @@ public function __construct( |
51 | 52 | private Security $security, |
52 | 53 | private RequestStack $requestStack, |
53 | 54 | private SettingsManager $settingsManager, |
54 | | - private EntityManagerInterface $entityManager |
| 55 | + private EntityManagerInterface $entityManager, |
| 56 | + private readonly ResourceAclHelper $resourceAclHelper, |
55 | 57 | ) {} |
56 | 58 |
|
57 | 59 | public static function getReaderMask(): int |
@@ -445,75 +447,7 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $ |
445 | 447 | $rights[] = $resourceRight; |
446 | 448 | } |
447 | 449 |
|
448 | | - // Asked mask |
449 | | - $mask = new MaskBuilder(); |
450 | | - $mask->add($attribute); |
451 | | - |
452 | | - $askedMask = (string) $mask->get(); |
453 | | - |
454 | | - // Creating roles |
455 | | - // @todo move this in a service |
456 | | - $anon = new GenericRole('IS_AUTHENTICATED_ANONYMOUSLY'); |
457 | | - $userRole = new GenericRole('ROLE_USER'); |
458 | | - $student = new GenericRole('ROLE_STUDENT'); |
459 | | - $teacher = new GenericRole('ROLE_TEACHER'); |
460 | | - $studentBoss = new GenericRole('ROLE_STUDENT_BOSS'); |
461 | | - |
462 | | - $currentStudent = new GenericRole(self::ROLE_CURRENT_COURSE_STUDENT); |
463 | | - $currentTeacher = new GenericRole(self::ROLE_CURRENT_COURSE_TEACHER); |
464 | | - |
465 | | - $currentStudentGroup = new GenericRole(self::ROLE_CURRENT_COURSE_GROUP_STUDENT); |
466 | | - $currentTeacherGroup = new GenericRole(self::ROLE_CURRENT_COURSE_GROUP_TEACHER); |
467 | | - |
468 | | - $currentStudentSession = new GenericRole(self::ROLE_CURRENT_COURSE_SESSION_STUDENT); |
469 | | - $currentTeacherSession = new GenericRole(self::ROLE_CURRENT_COURSE_SESSION_TEACHER); |
470 | | - |
471 | | - // Setting Simple ACL. |
472 | | - $acl = (new Acl()) |
473 | | - ->addRole($anon) |
474 | | - ->addRole($userRole) |
475 | | - ->addRole($student) |
476 | | - ->addRole($teacher) |
477 | | - ->addRole($studentBoss) |
478 | | - |
479 | | - ->addRole($currentStudent) |
480 | | - ->addRole($currentTeacher, self::ROLE_CURRENT_COURSE_STUDENT) |
481 | | - |
482 | | - ->addRole($currentStudentSession) |
483 | | - ->addRole($currentTeacherSession, self::ROLE_CURRENT_COURSE_SESSION_STUDENT) |
484 | | - |
485 | | - ->addRole($currentStudentGroup) |
486 | | - ->addRole($currentTeacherGroup, self::ROLE_CURRENT_COURSE_GROUP_STUDENT) |
487 | | - ; |
488 | | - |
489 | | - // Add a security resource. |
490 | | - $linkId = (string) $link->getId(); |
491 | | - $acl->addResource(new GenericResource($linkId)); |
492 | | - |
493 | | - // Check all the right this link has. |
494 | | - // Set rights from the ResourceRight. |
495 | | - foreach ($rights as $right) { |
496 | | - $acl->allow($right->getRole(), null, (string) $right->getMask()); |
497 | | - } |
498 | | - |
499 | | - // Anons can see. |
500 | | - if ($allowAnonsToView) { |
501 | | - $acl->allow($anon, null, (string) self::getReaderMask()); |
502 | | - } |
503 | | - |
504 | | - if ($token instanceof NullToken) { |
505 | | - return $acl->isAllowed('IS_AUTHENTICATED_ANONYMOUSLY', $linkId, $askedMask); |
506 | | - } |
507 | | - |
508 | | - $roles = $user instanceof UserInterface ? $user->getRoles() : []; |
509 | | - |
510 | | - foreach ($roles as $role) { |
511 | | - if ($acl->isAllowed($role, $linkId, $askedMask)) { |
512 | | - return true; |
513 | | - } |
514 | | - } |
515 | | - |
516 | | - return false; |
| 450 | + return $this->resourceAclHelper->isAllowed($attribute, $link, $rights, $allowAnonsToView); |
517 | 451 | } |
518 | 452 |
|
519 | 453 | private function isBlogResource(ResourceNode $node): bool |
|
0 commit comments