|
|
@ -33,8 +33,8 @@ class ResourceNodeVoter extends Voter |
|
|
|
public const ROLE_CURRENT_COURSE_STUDENT = 'ROLE_CURRENT_COURSE_STUDENT'; |
|
|
|
public const ROLE_CURRENT_COURSE_STUDENT = 'ROLE_CURRENT_COURSE_STUDENT'; |
|
|
|
public const ROLE_CURRENT_COURSE_GROUP_TEACHER = 'ROLE_CURRENT_COURSE_GROUP_TEACHER'; |
|
|
|
public const ROLE_CURRENT_COURSE_GROUP_TEACHER = 'ROLE_CURRENT_COURSE_GROUP_TEACHER'; |
|
|
|
public const ROLE_CURRENT_COURSE_GROUP_STUDENT = 'ROLE_CURRENT_COURSE_GROUP_STUDENT'; |
|
|
|
public const ROLE_CURRENT_COURSE_GROUP_STUDENT = 'ROLE_CURRENT_COURSE_GROUP_STUDENT'; |
|
|
|
public const ROLE_CURRENT_SESSION_COURSE_TEACHER = 'ROLE_CURRENT_SESSION_COURSE_TEACHER'; |
|
|
|
public const ROLE_CURRENT_COURSE_SESSION_TEACHER = 'ROLE_CURRENT_COURSE_SESSION_TEACHER'; |
|
|
|
public const ROLE_CURRENT_SESSION_COURSE_STUDENT = 'ROLE_CURRENT_SESSION_COURSE_STUDENT'; |
|
|
|
public const ROLE_CURRENT_COURSE_SESSION_STUDENT = 'ROLE_CURRENT_COURSE_SESSION_STUDENT'; |
|
|
|
|
|
|
|
|
|
|
|
private $requestStack; |
|
|
|
private $requestStack; |
|
|
|
private $security; |
|
|
|
private $security; |
|
|
@ -93,10 +93,9 @@ class ResourceNodeVoter extends Voter |
|
|
|
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
|
|
|
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
|
|
|
{ |
|
|
|
{ |
|
|
|
error_log('resourceNode voteOnAttribute'); |
|
|
|
error_log('resourceNode voteOnAttribute'); |
|
|
|
$user = $token->getUser(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure there is a user object (i.e. that the user is logged in) |
|
|
|
// Make sure there is a user object (i.e. that the user is logged in) |
|
|
|
// Update. No, anons can enter a node depending in the visibility. |
|
|
|
// Update. No, anons can enter a node depending in the visibility. |
|
|
|
|
|
|
|
// $user = $token->getUser(); |
|
|
|
/*if (!$user instanceof UserInterface) { |
|
|
|
/*if (!$user instanceof UserInterface) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
@ -127,6 +126,7 @@ class ResourceNodeVoter extends Voter |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user = $token->getUser(); |
|
|
|
// Check if I'm the owner. |
|
|
|
// Check if I'm the owner. |
|
|
|
$creator = $resourceNode->getCreator(); |
|
|
|
$creator = $resourceNode->getCreator(); |
|
|
|
if ($creator instanceof UserInterface && |
|
|
|
if ($creator instanceof UserInterface && |
|
|
@ -144,14 +144,14 @@ class ResourceNodeVoter extends Voter |
|
|
|
$groupId = (int) $request->get('gid'); |
|
|
|
$groupId = (int) $request->get('gid'); |
|
|
|
|
|
|
|
|
|
|
|
$links = $resourceNode->getResourceLinks(); |
|
|
|
$links = $resourceNode->getResourceLinks(); |
|
|
|
$linkFound = 0; |
|
|
|
|
|
|
|
//$courseManager = $this->entityManager->getRepository(Course::class); |
|
|
|
//$courseManager = $this->entityManager->getRepository(Course::class); |
|
|
|
//$sessionManager = $this->entityManager->getRepository(Session::class); |
|
|
|
//$sessionManager = $this->entityManager->getRepository(Session::class); |
|
|
|
|
|
|
|
|
|
|
|
$course = null; |
|
|
|
$linkFound = 0; |
|
|
|
$link = null; |
|
|
|
$link = null; |
|
|
|
$case = 0; |
|
|
|
|
|
|
|
// @todo implement view, edit, delete. |
|
|
|
// @todo implement view, edit, delete. |
|
|
|
|
|
|
|
/** @var ResourceLink $link */ |
|
|
|
foreach ($links as $link) { |
|
|
|
foreach ($links as $link) { |
|
|
|
// Block access if visibility is deleted. Creator and admin have already access. |
|
|
|
// Block access if visibility is deleted. Creator and admin have already access. |
|
|
|
if (ResourceLink::VISIBILITY_DELETED === $link->getVisibility()) { |
|
|
|
if (ResourceLink::VISIBILITY_DELETED === $link->getVisibility()) { |
|
|
@ -241,9 +241,9 @@ class ResourceNodeVoter extends Voter |
|
|
|
break; |
|
|
|
break; |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |
|
|
|
//var_dump($linkFound, $link->getId()); exit; |
|
|
|
//var_dump($linkFound, $link->getId(), $link->getVisibility()); exit; |
|
|
|
|
|
|
|
|
|
|
|
// No link was found or not available. |
|
|
|
// No link was found. |
|
|
|
if (0 === $linkFound) { |
|
|
|
if (0 === $linkFound) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -253,7 +253,7 @@ class ResourceNodeVoter extends Voter |
|
|
|
$allowAnonsToSee = false; |
|
|
|
$allowAnonsToSee = false; |
|
|
|
$rights = []; |
|
|
|
$rights = []; |
|
|
|
if ($rightFromResourceLink->count() > 0) { |
|
|
|
if ($rightFromResourceLink->count() > 0) { |
|
|
|
// Taken rights from the link |
|
|
|
// Taken rights from the link. |
|
|
|
$rights = $rightFromResourceLink; |
|
|
|
$rights = $rightFromResourceLink; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Taken the rights from the default tool |
|
|
|
// Taken the rights from the default tool |
|
|
@ -267,8 +267,8 @@ class ResourceNodeVoter extends Voter |
|
|
|
$readerMask = self::getReaderMask(); |
|
|
|
$readerMask = self::getReaderMask(); |
|
|
|
$editorMask = self::getEditorMask(); |
|
|
|
$editorMask = self::getEditorMask(); |
|
|
|
|
|
|
|
|
|
|
|
if ($courseId) { |
|
|
|
if ($courseId && $link->hasCourse() && $link->getCourse()->getId() === $courseId) { |
|
|
|
// If is teacher. |
|
|
|
// If teacher. |
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_TEACHER)) { |
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_TEACHER)) { |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
@ -277,7 +277,7 @@ class ResourceNodeVoter extends Voter |
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If is student. |
|
|
|
// If student. |
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_STUDENT) && |
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_STUDENT) && |
|
|
|
ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility() |
|
|
|
ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility() |
|
|
|
) { |
|
|
|
) { |
|
|
@ -289,7 +289,9 @@ class ResourceNodeVoter extends Voter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// For everyone. |
|
|
|
// For everyone. |
|
|
|
if (ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility() && $link->getCourse()->isPublic()) { |
|
|
|
if (ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility() && |
|
|
|
|
|
|
|
$link->getCourse()->isPublic() |
|
|
|
|
|
|
|
) { |
|
|
|
$allowAnonsToSee = true; |
|
|
|
$allowAnonsToSee = true; |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
@ -300,36 +302,44 @@ class ResourceNodeVoter extends Voter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($groupId)) { |
|
|
|
if (!empty($groupId)) { |
|
|
|
|
|
|
|
/*var_dump($groupId); |
|
|
|
|
|
|
|
foreach ($user->getRoles() as $role) { |
|
|
|
|
|
|
|
var_dump($role); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_GROUP_TEACHER)) { |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
|
->setMask($editorMask) |
|
|
|
->setMask($editorMask) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_GROUP_TEACHER) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_GROUP_TEACHER); |
|
|
|
; |
|
|
|
|
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_GROUP_STUDENT)) { |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
|
->setMask($readerMask) |
|
|
|
->setMask($readerMask) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_GROUP_STUDENT) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_GROUP_STUDENT); |
|
|
|
; |
|
|
|
|
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($sessionId)) { |
|
|
|
if (!empty($sessionId)) { |
|
|
|
|
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_SESSION_TEACHER)) { |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
|
->setMask($editorMask) |
|
|
|
->setMask($editorMask) |
|
|
|
->setRole(self::ROLE_CURRENT_SESSION_COURSE_TEACHER) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_SESSION_TEACHER); |
|
|
|
; |
|
|
|
|
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->security->isGranted(self::ROLE_CURRENT_COURSE_SESSION_STUDENT)) { |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight = new ResourceRight(); |
|
|
|
$resourceRight |
|
|
|
$resourceRight |
|
|
|
->setMask($readerMask) |
|
|
|
->setMask($readerMask) |
|
|
|
->setRole(self::ROLE_CURRENT_SESSION_COURSE_STUDENT) |
|
|
|
->setRole(self::ROLE_CURRENT_COURSE_SESSION_STUDENT); |
|
|
|
; |
|
|
|
|
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($rights) && ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility()) { |
|
|
|
if (empty($rights) && ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility()) { |
|
|
|
// Give just read access. |
|
|
|
// Give just read access. |
|
|
@ -341,7 +351,7 @@ class ResourceNodeVoter extends Voter |
|
|
|
$rights[] = $resourceRight; |
|
|
|
$rights[] = $resourceRight; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//exit; |
|
|
|
//var_dump($allowAnonsToSee); |
|
|
|
//var_dump($allowAnonsToSee); |
|
|
|
/*foreach ($rights as $right) { |
|
|
|
/*foreach ($rights as $right) { |
|
|
|
var_dump($right->getRole()); |
|
|
|
var_dump($right->getRole()); |
|
|
@ -367,8 +377,8 @@ class ResourceNodeVoter extends Voter |
|
|
|
$currentStudentGroup = new Role(self::ROLE_CURRENT_COURSE_GROUP_STUDENT); |
|
|
|
$currentStudentGroup = new Role(self::ROLE_CURRENT_COURSE_GROUP_STUDENT); |
|
|
|
$currentTeacherGroup = new Role(self::ROLE_CURRENT_COURSE_GROUP_TEACHER); |
|
|
|
$currentTeacherGroup = new Role(self::ROLE_CURRENT_COURSE_GROUP_TEACHER); |
|
|
|
|
|
|
|
|
|
|
|
$currentStudentSession = new Role(self::ROLE_CURRENT_SESSION_COURSE_STUDENT); |
|
|
|
$currentStudentSession = new Role(self::ROLE_CURRENT_COURSE_SESSION_STUDENT); |
|
|
|
$currentTeacherSession = new Role(self::ROLE_CURRENT_SESSION_COURSE_TEACHER); |
|
|
|
$currentTeacherSession = new Role(self::ROLE_CURRENT_COURSE_SESSION_TEACHER); |
|
|
|
|
|
|
|
|
|
|
|
$superAdmin = new Role('ROLE_SUPER_ADMIN'); |
|
|
|
$superAdmin = new Role('ROLE_SUPER_ADMIN'); |
|
|
|
$admin = new Role('ROLE_ADMIN'); |
|
|
|
$admin = new Role('ROLE_ADMIN'); |
|
|
@ -385,7 +395,7 @@ class ResourceNodeVoter extends Voter |
|
|
|
->addRole($currentTeacher, self::ROLE_CURRENT_COURSE_STUDENT) |
|
|
|
->addRole($currentTeacher, self::ROLE_CURRENT_COURSE_STUDENT) |
|
|
|
|
|
|
|
|
|
|
|
->addRole($currentStudentSession) |
|
|
|
->addRole($currentStudentSession) |
|
|
|
->addRole($currentTeacherSession, self::ROLE_CURRENT_SESSION_COURSE_STUDENT) |
|
|
|
->addRole($currentTeacherSession, self::ROLE_CURRENT_COURSE_SESSION_STUDENT) |
|
|
|
|
|
|
|
|
|
|
|
->addRole($currentStudentGroup) |
|
|
|
->addRole($currentStudentGroup) |
|
|
|
->addRole($currentTeacherGroup, self::ROLE_CURRENT_COURSE_GROUP_STUDENT) |
|
|
|
->addRole($currentTeacherGroup, self::ROLE_CURRENT_COURSE_GROUP_STUDENT) |
|
|
|