-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAssignmentSolutionPermissionPolicy.php
More file actions
123 lines (103 loc) · 3.9 KB
/
AssignmentSolutionPermissionPolicy.php
File metadata and controls
123 lines (103 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace App\Security\Policies;
use App\Model\Entity\AssignmentSolution;
use App\Model\Entity\GroupMembership;
use App\Security\Identity;
class AssignmentSolutionPermissionPolicy extends BasePermissionPolicy implements IPermissionPolicy
{
public function getAssociatedClass()
{
return AssignmentSolution::class;
}
public function isAdmin(Identity $identity, AssignmentSolution $solution)
{
$assignment = $solution->getAssignment();
if ($assignment === null) {
return false;
}
return $this->checkMinimalMembership(
$identity->getUserData(),
$assignment->getGroup(),
GroupMembership::TYPE_ADMIN
);
}
public function isSupervisorOrAdmin(Identity $identity, AssignmentSolution $solution)
{
$assignment = $solution->getAssignment();
if ($assignment === null) {
return false;
}
return $this->checkMinimalMembership(
$identity->getUserData(),
$assignment->getGroup(),
GroupMembership::TYPE_SUPERVISOR
);
}
public function isObserverOrBetter(Identity $identity, AssignmentSolution $solution)
{
$assignment = $solution->getAssignment();
if ($assignment === null) {
return false;
}
return $this->checkMinimalMembership(
$identity->getUserData(),
$assignment->getGroup(),
GroupMembership::TYPE_OBSERVER
);
}
public function isAuthor(Identity $identity, AssignmentSolution $solution)
{
$user = $identity->getUserData();
return $user !== null && $user === $solution->getSolution()->getAuthor();
}
public function areEvaluationDetailsPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewLimitRatios();
}
public function areMeasuredValuesPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewMeasuredValues();
}
public function areJudgeStdoutsPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewJudgeStdout();
}
public function areJudgeStderrsPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewJudgeStderr();
}
public function isInActiveGroup(Identity $identity, AssignmentSolution $solution)
{
$assignment = $solution->getAssignment();
if (!$assignment) {
return false;
}
$group = $assignment->getGroup();
return $group && !$group->isArchived(); // active = not deleted and not archived
}
/**
* Current user is either not locked at all, or locked in the group where the solution is.
*/
public function userIsNotLockedElsewhere(Identity $identity, AssignmentSolution $solution): bool
{
$user = $identity->getUserData();
$group = $solution->getAssignment()?->getGroup();
if ($user === null || $group === null) {
return false;
}
return !$user->isGroupLocked() || $user->getGroupLock()->getId() === $group->getId();
}
/**
* Current user is either not locked at all, or locked to this group, or the current lock is not strict.
*/
public function userIsNotLockedElsewhereStrictly(Identity $identity, AssignmentSolution $solution): bool
{
$user = $identity->getUserData();
$group = $solution->getAssignment()?->getGroup();
if ($user === null || $group === null) {
return false;
}
return !$user->isGroupLocked() || $user->getGroupLock()->getId() === $group->getId()
|| !$user->isGroupLockStrict();
}
}