ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilObjEmployeeTalkAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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',
76 'lang_var' => 'show',
77 'default' => true,
78 ]
79 ];
80
81 return $commands;
82 }
83
84 public static function _isOffline($obj_id): bool
85 {
86 return false;
87 }
88
89 public static function _checkGoto($target): bool
90 {
91 $access = new self();
92
93 $t_arr = explode('_', $target);
94 if ($t_arr[0] !== 'etal' || ((int) $t_arr[1]) <= 0) {
95 return false;
96 }
97 if ($access->canRead(intval($t_arr[1]))) {
98 return true;
99 }
100
101 return false;
102 }
103
115 public function canCreate(?ilObjUser $talkParticipant = null): bool
116 {
117 try {
118 $currentUserId = $this->getCurrentUsersId();
119
120 // Root has always full access
121 if ($currentUserId === 6) {
122 return true;
123 }
124
125 // Talks are never editable if the position rights are not active, because the talks don't use RBAC
126 if (!$this->talkPositionSettings->isActive()) {
127 return false;
128 }
129
130 $positions = $this->ua->getPositionsOfUserId($currentUserId);
131
132 // If we don't have a user just check if the current user has the right in any position to create a new talk
133 if ($talkParticipant === null) {
134 foreach ($positions as $position) {
135 // Check if the position has any relevant position rights
136 $permissionSet = ilOrgUnitPermissionQueries::getTemplateSetForContextName(ilObjEmployeeTalk::TYPE, strval($position->getId() ?? 0));
137 $isAbleToExecuteOperation = array_reduce($permissionSet->getOperations(), function (bool $prev, ilOrgUnitOperation $it) {
138 return $prev || $it->getOperationString() === EmployeeTalkPositionAccessLevel::CREATE;
139 }, false);
140
141 // If the position has no rights check the next one
142 if (!$isAbleToExecuteOperation) {
143 continue;
144 }
145
146 return true;
147 }
148
149 // The current user was not in a position with create etal position rights
150 return false;
151 }
152
153 // Validate authority and position rights over the given participant
154 return $this->hasAuthorityAndOperationPermissionOverUser($talkParticipant, EmployeeTalkPositionAccessLevel::CREATE);
155 } catch (\Exception $ex) {
156 return false;
157 }
158 }
159
160 public function hasPermissionToReadUnownedTalksOfUser(int $userId): bool
161 {
162 try {
163 return $this->hasAuthorityAndOperationPermissionOverUser(new ilObjUser($userId), EmployeeTalkPositionAccessLevel::VIEW);
164 } catch (\Exception $ex) {
165 return false;
166 }
167 }
168
169 public function canRead(int $refId): bool
170 {
171 return $this->isPermittedToExecuteOperation($refId, EmployeeTalkPositionAccessLevel::VIEW);
172 }
173
174 public function canEditTalkLockStatus(int $refId): bool
175 {
176 $currentUserId = $this->getCurrentUsersId();
177
178 // Root has always full access
179 if ($currentUserId === 6) {
180 return true;
181 }
182
183 $talk = new ilObjEmployeeTalk($refId);
184 return $talk->getOwner() === $currentUserId;
185 }
186
191 public function canEdit(int $refId): bool
192 {
193 return $this->isPermittedToExecuteOperation($refId, EmployeeTalkPositionAccessLevel::EDIT);
194 }
195
200 public function canDelete(int $refId): bool
201 {
202 $talk = new ilObjEmployeeTalk($refId);
203 $user = $this->getCurrentUsersId();
204 if (
205 $user === $talk->getOwner() &&
206 $this->container->access()->checkAccess('read', '', ilObjTalkTemplateAdministration::getRootRefId())
207 ) {
208 return true;
209 }
210 // global admins can delete
211 if ($this->container->rbac()->review()->isAssigned(
212 $user,
214 )) {
215 return true;
216 }
217 return false;
218 }
219
220 private function isPermittedToExecuteOperation(int $refId, string $operation): bool
221 {
222 $currentUserId = $this->getCurrentUsersId();
223
224 // Root has always full access
225 if ($currentUserId === 6) {
226 return true;
227 }
228
229 // Talks are never editable if the position rights are not active, because the talks don't use RBAC
230 if (!$this->talkPositionSettings->isActive()) {
231 return false;
232 }
233
234 $talk = new ilObjEmployeeTalk($refId);
235 $series = $talk->getParent();
236 $hasAuthority = $this->hasAuthorityAndOperationPermissionOverUser(new ilObjUser($talk->getData()->getEmployee()), $operation);
237 $data = $talk->getData();
238 $seriesSettings = $this->seriesSettingsRepository->readEmployeeTalkSerieSettings($series->getId());
239 $canExecuteOperation = $this->orgUnitAccess->checkPositionAccess($operation, $refId);
240 $isOwner = $talk->getOwner() === $currentUserId;
241
242 if ($isOwner) {
243 return true;
244 }
245
246 if ($currentUserId === $data->getEmployee()) {
247 // The Employee can never edit their own talks
248 if ($operation !== EmployeeTalkPositionAccessLevel::VIEW) {
249 return false;
250 }
251
252 // The Employee can always read their own talks
253 return true;
254 }
255
256 //Only owner can edit talks with enabled write lock
257 if ($seriesSettings->isLockedEditing() && $operation === EmployeeTalkPositionAccessLevel::EDIT) {
258 return false;
259 }
260
261 // Has no authority over the employee
262 if (!$hasAuthority) {
263 return false;
264 }
265
266 // Has Authority and is permitted to execute the given permission
267 if ($canExecuteOperation) {
268 return true;
269 }
270
271 // Has authority but no permission
272 return false;
273 }
274
280 public function isTalkReadonlyByCurrentUser(int $ref_id): bool
281 {
282 return !$this->canEdit($ref_id);
283 }
284
288 private function getCurrentUsersId(): int
289 {
290 return $this->container->user()->getId();
291 }
292
293 private function hasAuthorityAndOperationPermissionOverUser(ilObjUser $user, string $operation): bool
294 {
295 $myStaffAccess = ilMyStaffAccess::getInstance();
296 $currentUserId = $this->getCurrentUsersId();
297 $userId = $user->getId();
298
302 $managedOrgUnitUsersOfUserByPosition = $myStaffAccess->getUsersForUserPerPosition($currentUserId);
303
304 foreach ($managedOrgUnitUsersOfUserByPosition as $position => $managedOrgUnitUserByPosition) {
305 // Check if the position has any relevant position rights
307 $isAbleToExecuteOperation = array_reduce($permissionSet->getOperations(), function (bool $prev, ilOrgUnitOperation $it) use ($operation) {
308 return $prev || $it->getOperationString() === $operation;
309 }, false);
310
311 if (!$isAbleToExecuteOperation) {
312 continue;
313 }
314
315 foreach ($managedOrgUnitUserByPosition as $managedOrgUnitUser) {
316 if (intval($managedOrgUnitUser) === $userId) {
317 return true;
318 }
319 }
320 }
321
322 return false;
323 }
324}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
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.
Class ilObjectAccess.
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...
Class ilOrgUnitUserAssignmentQueries.
const SYSTEM_ROLE_ID
Definition: constants.php:29
$ref_id
Definition: ltiauth.php:66
$GLOBALS["DIC"]
Definition: wac.php:54
$refId
Definition: xapitoken.php:56