diff --git a/app/V1Module/security/Policies/CommentPermissionPolicy.php b/app/V1Module/security/Policies/CommentPermissionPolicy.php index 10a0d33b2..abc3b98da 100644 --- a/app/V1Module/security/Policies/CommentPermissionPolicy.php +++ b/app/V1Module/security/Policies/CommentPermissionPolicy.php @@ -2,21 +2,25 @@ namespace App\Security\Policies; +use App\Model\Entity\Assignment; use App\Model\Entity\AssignmentSolution; use App\Model\Entity\Comment; +use App\Model\Repository\Assignments; use App\Model\Repository\AssignmentSolutions; use App\Security\Identity; class CommentPermissionPolicy implements IPermissionPolicy { + private $assignments; private $assignmentSolutions; - public function __construct(AssignmentSolutions $assignmentSolutions) + public function __construct(Assignments $assignments, AssignmentSolutions $assignmentSolutions) { + $this->assignments = $assignments; $this->assignmentSolutions = $assignmentSolutions; } - function getAssociatedClass() + public function getAssociatedClass() { return Comment::class; } @@ -61,4 +65,22 @@ public function isSupervisorInGroupOfCommentedSolution(Identity $identity, Comme $group = $solution->getAssignment()->getGroup(); return $group && ($group->isSupervisorOf($user) || $group->isAdminOf($user)); } + + + public function isSupervisorInGroupOfCommentedAssignment(Identity $identity, Comment $comment) + { + $user = $identity->getUserData(); + if (!$user) { + return false; + } + + /** @var Assignment $assignment */ + $assignment = $this->assignments->get($comment->getCommentThread()->getId()); + if ($assignment === null) { + return false; + } + + $group = $assignment->getGroup(); + return $group && ($group->isSupervisorOf($user) || $group->isAdminOf($user)); + } } diff --git a/app/config/permissions.neon b/app/config/permissions.neon index 9a25b76cf..ea0a88114 100644 --- a/app/config/permissions.neon +++ b/app/config/permissions.neon @@ -429,6 +429,7 @@ permissions: or: - comment.isAuthor - comment.isSupervisorInGroupOfCommentedSolution + - comment.isSupervisorInGroupOfCommentedAssignment - allow: true # TODO role: student