ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AccessManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 protected \ilTree $tree;
28 protected int $user_id;
29 protected int $ref_id;
30 protected \ilAccessHandler $access;
32
33 public function __construct(
36 ) {
37 $this->domain = $domain;
38 $this->access = $access;
39 $this->tree = $this->domain->repositoryTree();
40 }
41
42 protected function getCurrentUserId(int $user_id): int
43 {
44 if ($user_id > 0) {
45 return $user_id;
46 }
47 return $this->domain->user()->getId();
48 }
49
50 public function canManageObjects(
51 int $ref_id,
52 int $current_user = 0
53 ): bool {
54 $current_user = $this->getCurrentUserId($current_user);
55 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
56 }
57
58 public function canManageSettings(
59 int $ref_id,
60 int $current_user = 0
61 ): bool {
62 $current_user = $this->getCurrentUserId($current_user);
63 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
64 }
65
66 public function canManageParticipants(
67 int $ref_id,
68 int $current_user = 0
69 ): bool {
70 $current_user = $this->getCurrentUserId($current_user);
71 return $this->access->checkAccessOfUser($current_user, "write", "", $ref_id);
72 }
73
75 int $ref_id,
76 array $participant_ids
77 ): array {
78 return $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
79 'render',
80 'render',
81 $ref_id,
82 $participant_ids
83 );
84 }
85
86 public function canManageAllReservations(
87 int $ref_id,
88 int $current_user = 0
89 ): bool {
90 $current_user = $this->getCurrentUserId($current_user);
91 return $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
92 }
93
94 public function canManageOwnReservations(
95 int $ref_id,
96 int $current_user = 0
97 ): bool {
98 $current_user = $this->getCurrentUserId($current_user);
99 return $this->access->checkAccessOfUser($current_user, "manage_own_reservations", "", $ref_id) ||
100 $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
101 }
102
104 int $ref_id,
105 int $target_user,
106 int $current_user = 0
107 ): bool {
108 $current_user = $this->getCurrentUserId($current_user);
109 if ($target_user === $current_user) {
110 return $this->access->checkAccessOfUser($current_user, "manage_own_reservations", "", $ref_id) ||
111 $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
112 }
113 return $this->access->checkAccessOfUser($current_user, "manage_all_reservations", "", $ref_id);
114 }
115
117 int $book_obj_id,
118 int $current_user = 0
119 ): bool {
120 $current_user = $this->getCurrentUserId($current_user);
121 return $this->hasPermissionOnAnyReference("manage_own_reservations", $current_user, $book_obj_id);
122 }
123
125 int $book_obj_id,
126 int $current_user = 0
127 ): bool {
128 $current_user = $this->getCurrentUserId($current_user);
129 return $this->hasPermissionOnAnyReference("manage_all_reservations", $current_user, $book_obj_id);
130 }
131
132 protected function hasPermissionOnAnyReference(
133 string $perm,
134 int $uid,
135 int $obj_id
136 ): bool {
137 $access = $this->access;
138 foreach (\ilObject::_getAllReferences($obj_id) as $ref_id) {
139 if ($access->checkAccessOfUser($uid, $perm, "", $ref_id)) {
140 return true;
141 }
142 }
143 return false;
144 }
145
146 public function getParentGroupCourse(int $ref_id): ?array
147 {
148 $tree = $this->tree;
149 if (($par_ref_id = $tree->checkForParentType($ref_id, "grp")) > 0) {
150 return [
151 "ref_id" => $par_ref_id,
152 "type" => "grp"
153 ];
154 }
155 if (($par_ref_id = $tree->checkForParentType($ref_id, "crs")) > 0) {
156 return [
157 "ref_id" => $par_ref_id,
158 "type" => "crs"
159 ];
160 }
161 return null;
162 }
163
164 public function canManageMembersOfParent(int $ref_id): bool
165 {
166 if (($parent = $this->getParentGroupCourse($ref_id)) !== null) {
167 return ($this->access->checkAccess("manage_members", "", (int) $parent["ref_id"])) ;
168 }
169 return false;
170 }
171
172 public function validateBookingObjId(int $book_obj_id, int $pool_id): void
173 {
174 if ($book_obj_id > 0 && \ilBookingObject::lookupPoolId($book_obj_id) !== $pool_id) {
175 throw new \ilPermissionException("Booking object pool id does not match pool id.");
176 }
177 }
178
179 public function validateScheduleId(int $schedule_id, int $pool_id): void
180 {
181 $sm = $this->domain->schedules($pool_id);
182 if (!$sm->hasScheduleId($schedule_id)) {
183 throw new \ilPermissionException("Schedule id does not match pool id.");
184 }
185 }
186
187}
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)
canRetrieveNotificationsForOwnReservationsByObjId(int $book_obj_id, int $current_user=0)
validateScheduleId(int $schedule_id, int $pool_id)
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)
static _getAllReferences(int $id)
get all reference ids for object ID
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66