ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilTestAccess Class Reference
+ Collaboration diagram for ilTestAccess:

Public Member Functions

 getAccess ()
 
 setAccess (ilAccessHandler $access)
 
 getRefId ()
 
 checkCorrectionsAccess ()
 
 checkScoreParticipantsAccess ()
 
 checkManageParticipantsAccess ()
 
 checkParticipantsResultsAccess ()
 
 checkOtherParticipantsLearningProgressAccess ()
 
 checkResultsAccessForActiveId (int $active_id, int $test_id)
 
 checkScoreParticipantsAccessForActiveId (int $active_id, int $test_id)
 
 isParticipantAllowed (int $obj_id, int $user_id)
 

Protected Member Functions

 checkAccessForActiveId (Closure $access_filter, int $active_id, int $test_id)
 

Protected Attributes

ilAccessHandler $access
 
ilDBInterface $db
 
ilLanguage $lng
 
MainSettingsDatabaseRepository $main_settings_repository
 
ilTestParticipantAccessFilterFactory $participant_access_filter
 
ParticipantRepository $participant_repository
 

Private Member Functions

 isParticipantExplicitelyAllowedByIndividualIPRange (?Participant $participant, string $ip)
 
 isIpAllowedToAccessTest (string $ip, SettingsAccess $access_settings)
 
 isIpTypeOf (int $ip_type_flag, string $ip, string $range_start, string $range_end)
 
 isIpv4Between (string $ip, string $range_start, string $range_end)
 
 isIpv6Between (string $ip, string $range_start, string $range_end)
 

Detailed Description

Definition at line 36 of file class.ilTestAccess.php.

Member Function Documentation

◆ checkAccessForActiveId()

ilTestAccess::checkAccessForActiveId ( Closure  $access_filter,
int  $active_id,
int  $test_id 
)
protected

Definition at line 164 of file class.ilTestAccess.php.

References ILIAS\Repository\lng().

Referenced by checkResultsAccessForActiveId(), and checkScoreParticipantsAccessForActiveId().

164  : bool
165  {
166  $participantData = new ilTestParticipantData($this->db, $this->lng);
167  $participantData->setActiveIdsFilter([$active_id]);
168  $participantData->setParticipantAccessFilter($access_filter);
169  $participantData->load($test_id);
170 
171  return in_array($active_id, $participantData->getActiveIds());
172  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkCorrectionsAccess()

ilTestAccess::checkCorrectionsAccess ( )
Returns
bool

Definition at line 77 of file class.ilTestAccess.php.

References getAccess(), and getRefId().

77  : bool
78  {
79  return $this->getAccess()->checkAccess('write', '', $this->getRefId());
80  }
+ Here is the call graph for this function:

◆ checkManageParticipantsAccess()

ilTestAccess::checkManageParticipantsAccess ( )
Returns
bool

Definition at line 105 of file class.ilTestAccess.php.

References getAccess(), getRefId(), and ilOrgUnitOperation\OP_MANAGE_PARTICIPANTS.

105  : bool
106  {
107  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
108  return true;
109  }
110 
111  if (!$this->getAccess()->checkAccess('read', '', $this->getRefId())) {
112  return false;
113  }
114 
115  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_MANAGE_PARTICIPANTS, $this->getRefId())) {
116  return true;
117  }
118 
119  return false;
120  }
+ Here is the call graph for this function:

◆ checkOtherParticipantsLearningProgressAccess()

ilTestAccess::checkOtherParticipantsLearningProgressAccess ( )

Definition at line 147 of file class.ilTestAccess.php.

References getAccess(), getRefId(), and ilOrgUnitOperation\OP_READ_LEARNING_PROGRESS.

147  : bool
148  {
149  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
150  return true;
151  }
152 
153  if ($this->getAccess()->checkRbacOrPositionPermissionAccess(
154  'read_learning_progress',
156  $this->getRefId()
157  )) {
158  return true;
159  }
160 
161  return false;
162  }
+ Here is the call graph for this function:

◆ checkParticipantsResultsAccess()

ilTestAccess::checkParticipantsResultsAccess ( )

Definition at line 122 of file class.ilTestAccess.php.

References getAccess(), getRefId(), ilOrgUnitOperation\OP_ACCESS_RESULTS, and ilOrgUnitOperation\OP_MANAGE_PARTICIPANTS.

122  : bool
123  {
124  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
125  return true;
126  }
127 
128  if ($this->getAccess()->checkAccess('tst_results', '', $this->getRefId())) {
129  return true;
130  }
131 
132  if (!$this->getAccess()->checkAccess('read', '', $this->getRefId())) {
133  return false;
134  }
135 
136  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_MANAGE_PARTICIPANTS, $this->getRefId())) {
137  return true;
138  }
139 
140  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_ACCESS_RESULTS, $this->getRefId())) {
141  return true;
142  }
143 
144  return false;
145  }
+ Here is the call graph for this function:

◆ checkResultsAccessForActiveId()

ilTestAccess::checkResultsAccessForActiveId ( int  $active_id,
int  $test_id 
)

Definition at line 174 of file class.ilTestAccess.php.

References checkAccessForActiveId(), and getRefId().

174  : bool
175  {
176  $access_filter = $this->participant_access_filter->getAccessResultsUserFilter($this->getRefId());
177  return $this->checkAccessForActiveId($access_filter, $active_id, $test_id);
178  }
checkAccessForActiveId(Closure $access_filter, int $active_id, int $test_id)
+ Here is the call graph for this function:

◆ checkScoreParticipantsAccess()

ilTestAccess::checkScoreParticipantsAccess ( )
Returns
bool

Definition at line 85 of file class.ilTestAccess.php.

References getAccess(), getRefId(), and ilOrgUnitOperation\OP_SCORE_PARTICIPANTS.

85  : bool
86  {
87  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
88  return true;
89  }
90 
91  if (!$this->getAccess()->checkAccess('read', '', $this->getRefId())) {
92  return false;
93  }
94 
95  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_SCORE_PARTICIPANTS, $this->getRefId())) {
96  return true;
97  }
98 
99  return false;
100  }
+ Here is the call graph for this function:

◆ checkScoreParticipantsAccessForActiveId()

ilTestAccess::checkScoreParticipantsAccessForActiveId ( int  $active_id,
int  $test_id 
)

Definition at line 180 of file class.ilTestAccess.php.

References checkAccessForActiveId(), and getRefId().

180  : bool
181  {
182  $access_filter = $this->participant_access_filter->getScoreParticipantsUserFilter($this->getRefId());
183  return $this->checkAccessForActiveId($access_filter, $active_id, $test_id);
184  }
checkAccessForActiveId(Closure $access_filter, int $active_id, int $test_id)
+ Here is the call graph for this function:

◆ getAccess()

ilTestAccess::getAccess ( )

Definition at line 59 of file class.ilTestAccess.php.

References $access.

Referenced by checkCorrectionsAccess(), checkManageParticipantsAccess(), checkOtherParticipantsLearningProgressAccess(), checkParticipantsResultsAccess(), and checkScoreParticipantsAccess().

60  {
61  return $this->access;
62  }
ilAccessHandler $access
+ Here is the caller graph for this function:

◆ getRefId()

◆ isIpAllowedToAccessTest()

ilTestAccess::isIpAllowedToAccessTest ( string  $ip,
SettingsAccess  $access_settings 
)
private

Definition at line 249 of file class.ilTestAccess.php.

References ILIAS\Test\Settings\MainSettings\SettingsAccess\getIpRangeFrom(), ILIAS\Test\Settings\MainSettings\SettingsAccess\getIpRangeTo(), ILIAS\Test\Settings\MainSettings\SettingsAccess\isIpRangeEnabled(), isIpTypeOf(), isIpv4Between(), and isIpv6Between().

Referenced by isParticipantAllowed().

252  : bool {
253  if (!$access_settings->isIpRangeEnabled()) {
254  return true;
255  }
256 
257  $range_start = $access_settings->getIpRangeFrom();
258  $range_end = $access_settings->getIpRangeTo();
259 
260  if ($this->isIpTypeOf(FILTER_FLAG_IPV4, $ip, $range_start, $range_end)) {
261  return $this->isIpv4Between($ip, $range_start, $range_end);
262  }
263 
264  if ($this->isIpTypeOf(FILTER_FLAG_IPV6, $ip, $range_start, $range_end)) {
265  return $this->isIpv6Between($ip, $range_start, $range_end);
266  }
267 
268  return false;
269  }
isIpTypeOf(int $ip_type_flag, string $ip, string $range_start, string $range_end)
isIpv4Between(string $ip, string $range_start, string $range_end)
isIpv6Between(string $ip, string $range_start, string $range_end)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIpTypeOf()

ilTestAccess::isIpTypeOf ( int  $ip_type_flag,
string  $ip,
string  $range_start,
string  $range_end 
)
private

Definition at line 271 of file class.ilTestAccess.php.

Referenced by isIpAllowedToAccessTest(), and isParticipantExplicitelyAllowedByIndividualIPRange().

271  : bool
272  {
273  return filter_var($ip, FILTER_VALIDATE_IP, $ip_type_flag) !== false
274  && filter_var($range_start, FILTER_VALIDATE_IP, $ip_type_flag) !== false
275  && filter_var($range_end, FILTER_VALIDATE_IP, $ip_type_flag) !== false;
276  }
+ Here is the caller graph for this function:

◆ isIpv4Between()

ilTestAccess::isIpv4Between ( string  $ip,
string  $range_start,
string  $range_end 
)
private

Definition at line 278 of file class.ilTestAccess.php.

Referenced by isIpAllowedToAccessTest(), and isParticipantExplicitelyAllowedByIndividualIPRange().

278  : bool
279  {
280  return ip2long($range_start) <= ip2long($ip)
281  && ip2long($ip) <= ip2long($range_end);
282  }
+ Here is the caller graph for this function:

◆ isIpv6Between()

ilTestAccess::isIpv6Between ( string  $ip,
string  $range_start,
string  $range_end 
)
private

Definition at line 284 of file class.ilTestAccess.php.

Referenced by isIpAllowedToAccessTest(), and isParticipantExplicitelyAllowedByIndividualIPRange().

284  : bool
285  {
286  return bin2hex(inet_pton($range_start)) <= bin2hex(inet_pton($ip))
287  && bin2hex(inet_pton($ip)) <= bin2hex(inet_pton($range_end));
288  }
+ Here is the caller graph for this function:

◆ isParticipantAllowed()

ilTestAccess::isParticipantAllowed ( int  $obj_id,
int  $user_id 
)

Definition at line 186 of file class.ilTestAccess.php.

References $_SERVER, Vendor\Package\$e, ilObjTest\_getTestIDFromObjectID(), ilObject\_lookupObjId(), getRefId(), isIpAllowedToAccessTest(), and isParticipantExplicitelyAllowedByIndividualIPRange().

187  {
188  try {
189  $access_settings = $this->main_settings_repository->getForObjFi($obj_id)
190  ->getAccessSettings();
191  } catch (\Exception $e) {
192  return ParticipantAccess::BROKEN_TEST;
193  }
194 
195  $participant = $this->participant_repository->getParticipantByUserId(
198  ),
199  $user_id
200  );
201 
202  if ($access_settings->getFixedParticipants()
203  && ($participant === null || !$participant->isInvitedParticipant())) {
204  return ParticipantAccess::NOT_INVITED;
205  }
206 
207  $ip = $_SERVER['REMOTE_ADDR'];
208 
209  $allowed_individual = $this->isParticipantExplicitelyAllowedByIndividualIPRange($participant, $ip);
210  if ($allowed_individual === false) {
211  return ParticipantAccess::INDIVIDUAL_CLIENT_IP_MISMATCH;
212  }
213 
214 
215  if ($allowed_individual === true
216  || !$access_settings->isIpRangeEnabled()) {
217  return ParticipantAccess::ALLOWED;
218  }
219 
220  if (!$this->isIpAllowedToAccessTest($ip, $access_settings)) {
221  return ParticipantAccess::TEST_LEVEL_CLIENT_IP_MISMATCH;
222  }
223 
224  return ParticipantAccess::ALLOWED;
225  }
static _lookupObjId(int $ref_id)
isParticipantExplicitelyAllowedByIndividualIPRange(?Participant $participant, string $ip)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id.
isIpAllowedToAccessTest(string $ip, SettingsAccess $access_settings)
+ Here is the call graph for this function:

◆ isParticipantExplicitelyAllowedByIndividualIPRange()

ilTestAccess::isParticipantExplicitelyAllowedByIndividualIPRange ( ?Participant  $participant,
string  $ip 
)
private

Definition at line 227 of file class.ilTestAccess.php.

References ILIAS\Test\Participants\Participant\getClientIpFrom(), ILIAS\Test\Participants\Participant\getClientIpTo(), isIpTypeOf(), isIpv4Between(), and isIpv6Between().

Referenced by isParticipantAllowed().

230  : ?bool {
231  $range_start = $participant?->getClientIpFrom();
232  $range_end = $participant?->getClientIpTo();
233 
234  if ($range_start === null && $range_end === null) {
235  return null;
236  }
237 
238  if ($this->isIpTypeOf(FILTER_FLAG_IPV4, $ip, $range_start, $range_end)) {
239  return $this->isIpv4Between($ip, $range_start, $range_end);
240  }
241 
242  if ($this->isIpTypeOf(FILTER_FLAG_IPV6, $ip, $range_start, $range_end)) {
243  return $this->isIpv6Between($ip, $range_start, $range_end);
244  }
245 
246  return false;
247  }
isIpTypeOf(int $ip_type_flag, string $ip, string $range_start, string $range_end)
isIpv4Between(string $ip, string $range_start, string $range_end)
isIpv6Between(string $ip, string $range_start, string $range_end)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAccess()

ilTestAccess::setAccess ( ilAccessHandler  $access)

Definition at line 64 of file class.ilTestAccess.php.

References $access, and ILIAS\Repository\access().

65  {
66  $this->access = $access;
67  }
ilAccessHandler $access
+ Here is the call graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilTestAccess::$access
protected

Definition at line 38 of file class.ilTestAccess.php.

Referenced by getAccess(), and setAccess().

◆ $db

ilDBInterface ilTestAccess::$db
protected

Definition at line 39 of file class.ilTestAccess.php.

◆ $lng

ilLanguage ilTestAccess::$lng
protected

Definition at line 40 of file class.ilTestAccess.php.

◆ $main_settings_repository

MainSettingsDatabaseRepository ilTestAccess::$main_settings_repository
protected

Definition at line 41 of file class.ilTestAccess.php.

◆ $participant_access_filter

ilTestParticipantAccessFilterFactory ilTestAccess::$participant_access_filter
protected

Definition at line 43 of file class.ilTestAccess.php.

◆ $participant_repository

ParticipantRepository ilTestAccess::$participant_repository
protected

Definition at line 44 of file class.ilTestAccess.php.


The documentation for this class was generated from the following file: