ILIAS  release_8 Revision v8.24
class.ilObjEmployeeTalkAccess.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27
29{
30 private static ?self $instance = null;
33 private IlOrgUnitPositionAccess $orgUnitAccess;
37
38 public static function getInstance(): self
39 {
40 if (is_null(self::$instance)) {
41 self::$instance = new ilObjEmployeeTalkAccess();
42 }
43
44 return self::$instance;
45 }
46
47 public function __construct()
48 {
49 $this->container = $GLOBALS['DIC'];
50
53 $this->orgUnitAccess = new ilOrgUnitPositionAccess($this->container->access());
54 $this->talkPositionSettings = $this->set->getObjectPositionSettingsByType(ilObjEmployeeTalk::TYPE);
55 $this->seriesSettingsRepository = new IliasDBEmployeeTalkSeriesRepository($this->container->user(), $this->container->database());
56 }
57
70 public static function _getCommands(): array
71 {
72 $commands = [
73 [
74 'permission' => 'read',
75 'cmd' => ControlFlowCommand::DEFAULT,
76 'lang_var' => 'show',
77 'default' => true,
78 ]
79 ];
80
81 return $commands;
82 }
83
84 public static function _isOffline($a_obj_id): bool
85 {
86 return false;
87 }
88
94 public static function _checkGoto($a_target): bool
95 {
96 $access = new self();
97
98 $t_arr = explode('_', $a_target);
99 if ($t_arr[0] !== 'etal' || ((int) $t_arr[1]) <= 0) {
100 return false;
101 }
102 if ($access->canRead(intval($t_arr[1]))) {
103 return true;
104 }
105
106 return false;
107 }
108
120 public function canCreate(?ilObjUser $talkParticipant = null): bool
121 {
122 try {
123 $currentUserId = $this->getCurrentUsersId();
124
125 // Root has always full access
126 if ($currentUserId === 6) {
127 return true;
128 }
129
130 // Talks are never editable if the position rights are not active, because the talks don't use RBAC
131 if (!$this->talkPositionSettings->isActive()) {
132 return false;
133 }
134
135 $positions = $this->ua->getPositionsOfUserId($currentUserId);
136
137 // If we don't have a user just check if the current user has the right in any position to create a new talk
138 if ($talkParticipant === null) {
139 foreach ($positions as $position) {
140 // Check if the position has any relevant position rights
141 $permissionSet = ilOrgUnitPermissionQueries::getTemplateSetForContextName(ilObjEmployeeTalk::TYPE, strval($position->getId() ?? 0));
142 $isAbleToExecuteOperation = array_reduce($permissionSet->getOperations(), function (bool $prev, ilOrgUnitOperation $it) {
143 return $prev || $it->getOperationString() === EmployeeTalkPositionAccessLevel::CREATE;
144 }, false);
145
146 // If the position has no rights check the next one
147 if (!$isAbleToExecuteOperation) {
148 continue;
149 }
150
151 return true;
152 }
153
154 // The current user was not in a position with create etal position rights
155 return false;
156 }
157
158 // Validate authority and position rights over the given participant
159 return $this->hasAuthorityAndOperationPermissionOverUser($talkParticipant, EmployeeTalkPositionAccessLevel::CREATE);
160 } catch (\Exception $ex) {
161 return false;
162 }
163 }
164
165 public function hasPermissionToReadUnownedTalksOfUser(int $userId): bool
166 {
167 try {
168 return $this->hasAuthorityAndOperationPermissionOverUser(new ilObjUser($userId), EmployeeTalkPositionAccessLevel::VIEW);
169 } catch (\Exception $ex) {
170 return false;
171 }
172 }
173
174 public function canRead(int $refId): bool
175 {
176 return $this->isPermittedToExecuteOperation($refId, EmployeeTalkPositionAccessLevel::VIEW);
177 }
178
179 public function canEditTalkLockStatus(int $refId): bool
180 {
181 $currentUserId = $this->getCurrentUsersId();
182
183 // Root has always full access
184 if ($currentUserId === 6) {
185 return true;
186 }
187
188 $talk = new ilObjEmployeeTalk($refId);
189 return intval($talk->getOwner()) === $currentUserId;
190 }
191
196 public function canEdit(int $refId): bool
197 {
198 return $this->isPermittedToExecuteOperation($refId, EmployeeTalkPositionAccessLevel::EDIT);
199 }
200
205 public function canDelete(int $refId): bool
206 {
207 $talk = new ilObjEmployeeTalk($refId);
208 $user = $this->getCurrentUsersId();
209 if ($user === $talk->getOwner()) {
210 return true;
211 }
212 // global admins can delete
213 if ($this->container->rbac()->review()->isAssigned(
214 $user,
216 )) {
217 return true;
218 }
219 return false;
220 }
221
222 private function isPermittedToExecuteOperation(int $refId, string $operation): bool
223 {
224 $currentUserId = $this->getCurrentUsersId();
225
226 // Root has always full access
227 if ($currentUserId === 6) {
228 return true;
229 }
230
231 // Talks are never editable if the position rights are not active, because the talks don't use RBAC
232 if (!$this->talkPositionSettings->isActive()) {
233 return false;
234 }
235
236 $talk = new ilObjEmployeeTalk($refId);
237 $series = $talk->getParent();
238 $hasAuthority = $this->hasAuthorityAndOperationPermissionOverUser(new ilObjUser($talk->getData()->getEmployee()), $operation);
239 $data = $talk->getData();
240 $seriesSettings = $this->seriesSettingsRepository->readEmployeeTalkSerieSettings($series->getId());
241 $canExecuteOperation = $this->orgUnitAccess->checkPositionAccess($operation, $refId);
242 $isOwner = $talk->getOwner() === $currentUserId;
243
244 if ($isOwner) {
245 return true;
246 }
247
248 if ($currentUserId === $data->getEmployee()) {
249 // The Employee can never edit their own talks
250 if ($operation !== EmployeeTalkPositionAccessLevel::VIEW) {
251 return false;
252 }
253
254 // The Employee can always read their own talks
255 return true;
256 }
257
258 //Only owner can edit talks with enabled write lock
259 if ($seriesSettings->isLockedEditing() && $operation === EmployeeTalkPositionAccessLevel::EDIT) {
260 return false;
261 }
262
263 // Has no authority over the employee
264 if (!$hasAuthority) {
265 return false;
266 }
267
268 // Has Authority and is permitted to execute the given permission
269 if ($canExecuteOperation) {
270 return true;
271 }
272
273 // Has authority but no permission
274 return false;
275 }
276
282 public function isTalkReadonlyByCurrentUser(int $ref_id): bool
283 {
284 return !$this->canEdit($ref_id);
285 }
286
290 private function getCurrentUsersId(): int
291 {
292 return $this->container->user()->getId();
293 }
294
295 private function hasAuthorityAndOperationPermissionOverUser(ilObjUser $user, string $operation): bool
296 {
297 $myStaffAccess = ilMyStaffAccess::getInstance();
298 $currentUserId = $this->getCurrentUsersId();
299 $userId = $user->getId();
300
304 $managedOrgUnitUsersOfUserByPosition = $myStaffAccess->getUsersForUserPerPosition($currentUserId);
305
306 foreach ($managedOrgUnitUsersOfUserByPosition as $position => $managedOrgUnitUserByPosition) {
307 // Check if the position has any relevant position rights
309 $isAbleToExecuteOperation = array_reduce($permissionSet->getOperations(), function (bool $prev, ilOrgUnitOperation $it) use ($operation) {
310 return $prev || $it->getOperationString() === $operation;
311 }, false);
312
313 if (!$isAbleToExecuteOperation) {
314 continue;
315 }
316
317 foreach ($managedOrgUnitUserByPosition as $managedOrgUnitUser) {
318 if (intval($managedOrgUnitUser) === $userId) {
319 return true;
320 }
321 }
322 }
323
324 return false;
325 }
326}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
ilOrgUnitObjectTypePositionSetting $talkPositionSettings
IlOrgUnitPositionAccess $orgUnitAccess
IliasDBEmployeeTalkSeriesRepository $seriesSettingsRepository
canCreate(?ilObjUser $talkParticipant=null)
Checks if the user is allowed to create a new talks series.
ilOrgUnitUserAssignmentQueries $ua
isPermittedToExecuteOperation(int $refId, string $operation)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getTemplateSetForContextName(string $context_name, string $position_id, bool $editable=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SYSTEM_ROLE_ID
Definition: constants.php:29
$ref_id
Definition: ltiauth.php:67
$refId
Definition: xapitoken.php:58