ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
AccessManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 protected \ilTree $tree;
29 protected int $user_id;
30 protected int $ref_id;
31 protected \ilAccessHandler $access;
33
34 public function __construct(
37 ) {
38 $this->domain = $domain;
39 $this->access = $access;
40 $this->tree = $this->domain->repositoryTree();
41 }
42
43 protected function getCurrentUserId(int $user_id): int
44 {
45 if ($user_id > 0) {
46 return $user_id;
47 }
48 return $this->domain->user()->getId();
49 }
50
51 public function canManageObjects(
52 int $ref_id,
53 int $current_user = 0
54 ): bool {
55 $current_user = $this->getCurrentUserId($current_user);
56 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
57 }
58
59 public function canManageSettings(
60 int $ref_id,
61 int $current_user = 0
62 ): bool {
63 $current_user = $this->getCurrentUserId($current_user);
64 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
65 }
66
67 public function canManageParticipants(
68 int $ref_id,
69 int $current_user = 0
70 ): bool {
71 $current_user = $this->getCurrentUserId($current_user);
72 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
73 }
74
76 int $ref_id,
77 array $participant_ids
78 ): array {
79 return $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
80 'write',
81 'render',
82 $ref_id,
83 $participant_ids
84 );
85 }
86
87 public function canManageAllReservations(
88 int $ref_id,
89 int $current_user = 0
90 ): bool {
91 $current_user = $this->getCurrentUserId($current_user);
92 return $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
93 }
94
95 public function canManageOwnReservations(
96 int $ref_id,
97 int $current_user = 0
98 ): bool {
99 $current_user = $this->getCurrentUserId($current_user);
100 return $this->access->checkAccessOfUser($current_user, "manage_own_reservations", "", $ref_id) ||
101 $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
102 }
103
105 int $ref_id,
106 int $target_user,
107 int $current_user = 0
108 ): bool {
109 $current_user = $this->getCurrentUserId($current_user);
110 if ($target_user === $current_user) {
111 return $this->access->checkAccessOfUser($current_user, "manage_own_reservations", "", $ref_id) ||
112 $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
113 }
114 return $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
115 }
116
118 int $book_obj_id,
119 int $current_user = 0
120 ): bool {
121 $current_user = $this->getCurrentUserId($current_user);
122 return $this->hasPermissionOnAnyReference("manage_own_reservations", $current_user, $book_obj_id);
123 }
124
126 int $book_obj_id,
127 int $current_user = 0
128 ): bool {
129 $current_user = $this->getCurrentUserId($current_user);
130 return $this->hasPermissionOnAnyReference("manage_all_reservations", $current_user, $book_obj_id);
131 }
132
133 protected function hasPermissionOnAnyReference(
134 string $perm,
135 int $uid,
136 int $obj_id
137 ): bool {
138 $access = $this->access;
139 foreach (\ilObject::_getAllReferences($obj_id) as $ref_id) {
140 if ($access->checkAccessOfUser($uid, $perm, "", $ref_id)) {
141 return true;
142 }
143 }
144 return false;
145 }
146
147 public function getParentGroupCourse(int $ref_id): ?array
148 {
149 $tree = $this->tree;
150 if (($par_ref_id = $tree->checkForParentType($ref_id, "grp")) > 0) {
151 return [
152 "ref_id" => $par_ref_id,
153 "type" => "grp"
154 ];
155 }
156 if (($par_ref_id = $tree->checkForParentType($ref_id, "crs")) > 0) {
157 return [
158 "ref_id" => $par_ref_id,
159 "type" => "crs"
160 ];
161 }
162 return null;
163 }
164
165 public function canManageMembersOfParent(int $ref_id): bool
166 {
167 if (($parent = $this->getParentGroupCourse($ref_id)) !== null) {
168 return ($this->access->checkAccess("manage_members", "", (int) $parent["ref_id"])) ;
169 }
170 return false;
171 }
172
173 public function validateBookingObjId(int $book_obj_id, int $pool_id): void
174 {
175 if ($book_obj_id > 0 && \ilBookingObject::lookupPoolId($book_obj_id) !== $pool_id) {
176 throw new \ilPermissionException("Booking object pool id does not match pool id.");
177 }
178 }
179
180 public function validateScheduleId(int $schedule_id, int $pool_id): void
181 {
182 $sm = $this->domain->schedules($pool_id);
183 if (!$sm->hasScheduleId($schedule_id)) {
184 throw new \ilPermissionException("Schedule id does not match pool id.");
185 }
186 }
187
188 public function canRead(int $ref_id, int $current_user = 0): bool
189 {
190 return $this->access->checkAccessOfUser(
191 $this->getCurrentUserId($current_user),
192 "read",
193 "",
194 $ref_id
195 );
196 }
197
198 public function canReadPublicLog(int $ref_id, int $current_user = 0): bool
199 {
200 return $this->canRead($ref_id, $current_user) && (new ilObjBookingPool($ref_id, true))->hasPublicLog();
201 }
202}
validateBookingObjId(int $book_obj_id, int $pool_id)
canRetrieveNotificationsForAllReservationsByObjId(int $book_obj_id, int $current_user=0)
__construct(InternalDomainService $domain, \ilAccessHandler $access)
canManageObjects(int $ref_id, int $current_user=0)
canReadPublicLog(int $ref_id, int $current_user=0)
canRetrieveNotificationsForOwnReservationsByObjId(int $book_obj_id, int $current_user=0)
validateScheduleId(int $schedule_id, int $pool_id)
canRead(int $ref_id, int $current_user=0)
canManageParticipants(int $ref_id, int $current_user=0)
filterManageableParticipants(int $ref_id, array $participant_ids)
hasPermissionOnAnyReference(string $perm, int $uid, int $obj_id)
canManageReservationForUser(int $ref_id, int $target_user, int $current_user=0)
canManageOwnReservations(int $ref_id, int $current_user=0)
canManageAllReservations(int $ref_id, int $current_user=0)
canManageSettings(int $ref_id, int $current_user=0)
Author: Alexander Killing killing@leifos.de
static lookupPoolId(int $object_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAllReferences(int $id)
get all reference ids for object ID
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Combines all available interfaces which can be called via global $ilAccess.