Skip to content

Commit ff022c8

Browse files
committed
Implementing necessary changes in ACL group-lock checks.
1 parent da7afd8 commit ff022c8

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

app/V1Module/security/Policies/AssignmentSolutionPermissionPolicy.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Model\Entity\AssignmentSolution;
66
use App\Model\Entity\GroupMembership;
7+
use App\Model\GroupExamLockType;
78
use App\Security\Identity;
89

910
class AssignmentSolutionPermissionPolicy extends BasePermissionPolicy implements IPermissionPolicy
@@ -107,17 +108,38 @@ public function userIsNotLockedElsewhere(Identity $identity, AssignmentSolution
107108
}
108109

109110
/**
110-
* Current user is either not locked at all, or locked to this group, or the current lock is not strict.
111+
* Current user is either not locked at all, or locked to this group (where the solution is),
112+
* or the current lock type allows (read-only) access to this solution.
111113
*/
112-
public function userIsNotLockedElsewhereStrictly(Identity $identity, AssignmentSolution $solution): bool
114+
public function userGroupLockTypeAllowsReadAccess(Identity $identity, AssignmentSolution $solution): bool
113115
{
114116
$user = $identity->getUserData();
115117
$group = $solution->getAssignment()?->getGroup();
116118
if ($user === null || $group === null) {
117119
return false;
118120
}
119121

120-
return !$user->isGroupLocked() || $user->getGroupLock()->getId() === $group->getId()
121-
|| !$user->isGroupLockStrict();
122+
if (!$user->isGroupLocked() || $user->getGroupLock()->getId() === $group->getId()) {
123+
return true;
124+
}
125+
126+
$lockType = $user->getGroupLockType();
127+
if ($lockType === null || $lockType === GroupExamLockType::Visible) {
128+
return true;
129+
}
130+
131+
if ($lockType === GroupExamLockType::Restricted) {
132+
return false; // a shortcut (false is also at the end)
133+
}
134+
135+
if ($lockType === GroupExamLockType::Accepted) {
136+
return $solution->isAccepted();
137+
}
138+
139+
if ($lockType === GroupExamLockType::Reviewed) {
140+
return $solution->isAccepted() || $solution->isReviewed();
141+
}
142+
143+
return false;
122144
}
123145
}

app/config/permissions.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ permissions:
612612
- viewReview
613613
conditions:
614614
- assignmentSolution.isAuthor
615-
- assignmentSolution.userIsNotLockedElsewhereStrictly
615+
- assignmentSolution.userGroupLockTypeAllowsReadAccess
616616

617617
- allow: true
618618
role: student
@@ -633,7 +633,7 @@ permissions:
633633
conditions:
634634
- assignmentSolution.areEvaluationDetailsPublic
635635
- assignmentSolution.isAuthor
636-
- assignmentSolution.userIsNotLockedElsewhereStrictly
636+
- assignmentSolution.userGroupLockTypeAllowsReadAccess
637637

638638
- allow: true
639639
role: student
@@ -644,7 +644,7 @@ permissions:
644644
- assignmentSolution.areEvaluationDetailsPublic
645645
- assignmentSolution.areMeasuredValuesPublic
646646
- assignmentSolution.isAuthor
647-
- assignmentSolution.userIsNotLockedElsewhereStrictly
647+
- assignmentSolution.userGroupLockTypeAllowsReadAccess
648648

649649
- allow: true
650650
role: supervisor-student

0 commit comments

Comments
 (0)