Skip to content

Commit

Permalink
Updating comments permissions so they can be used the same way for As…
Browse files Browse the repository at this point in the history
…signments.
  • Loading branch information
Martin Krulis committed Mar 29, 2020
1 parent a841842 commit 78d3906
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions app/V1Module/security/Policies/CommentPermissionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}
}
1 change: 1 addition & 0 deletions app/config/permissions.neon
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ permissions:
or:
- comment.isAuthor
- comment.isSupervisorInGroupOfCommentedSolution
- comment.isSupervisorInGroupOfCommentedAssignment

- allow: true # TODO
role: student
Expand Down

0 comments on commit 78d3906

Please sign in to comment.