|
4 | 4 |
|
5 | 5 | use App\Model\Entity\AssignmentSolution; |
6 | 6 | use App\Model\Entity\GroupMembership; |
| 7 | +use App\Model\GroupExamLockType; |
7 | 8 | use App\Security\Identity; |
8 | 9 |
|
9 | 10 | class AssignmentSolutionPermissionPolicy extends BasePermissionPolicy implements IPermissionPolicy |
@@ -107,17 +108,38 @@ public function userIsNotLockedElsewhere(Identity $identity, AssignmentSolution |
107 | 108 | } |
108 | 109 |
|
109 | 110 | /** |
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. |
111 | 113 | */ |
112 | | - public function userIsNotLockedElsewhereStrictly(Identity $identity, AssignmentSolution $solution): bool |
| 114 | + public function userGroupLockTypeAllowsReadAccess(Identity $identity, AssignmentSolution $solution): bool |
113 | 115 | { |
114 | 116 | $user = $identity->getUserData(); |
115 | 117 | $group = $solution->getAssignment()?->getGroup(); |
116 | 118 | if ($user === null || $group === null) { |
117 | 119 | return false; |
118 | 120 | } |
119 | 121 |
|
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; |
122 | 144 | } |
123 | 145 | } |
0 commit comments