ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPortfolioAccessHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
6include_once "Modules/Group/classes/class.ilGroupParticipants.php";
7include_once "Modules/Course/classes/class.ilCourseParticipants.php";
8include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
9require_once('./Services/WebAccessChecker/interfaces/interface.ilWACCheckingClass.php');
10
20{
24 protected $lng;
25
29 protected $user;
30
34 protected $rbacreview;
35
39 protected $settings;
40
44 protected $db;
45
49 protected $access;
50
51 public function __construct()
52 {
53 global $DIC;
54
55 $this->lng = $DIC->language();
56 $this->user = $DIC->user();
57 $this->rbacreview = $DIC->rbac()->review();
58 $this->settings = $DIC->settings();
59 $this->db = $DIC->database();
60 $this->access = $DIC->access();
61 $lng = $DIC->language();
62 $lng->loadLanguageModule("wsp");
63 }
64
74 public function checkAccess($a_permission, $a_cmd, $a_node_id, $a_type = "")
75 {
77
78 return $this->checkAccessOfUser($ilUser->getId(), $a_permission, $a_cmd, $a_node_id, $a_type);
79 }
80
91 public function checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_node_id, $a_type = "")
92 {
96
97 // #20310
98 if (!$ilSetting->get("enable_global_profiles") && $ilUser->getId() == ANONYMOUS_USER_ID) {
99 return false;
100 }
101
102 // #12059
103 if (!$ilSetting->get('user_portfolios')) {
104 return false;
105 }
106
107 // :TODO: create permission for parent node with type ?!
108
109 $pf = new ilObjPortfolio($a_node_id, false);
110 if (!$pf->getId()) {
111 return false;
112 }
113
114 // portfolio owner has all rights
115 if ($pf->getOwner() == $a_user_id) {
116 return true;
117 }
118
119 // #11921
120 if (!$pf->isOnline()) {
121 return false;
122 }
123
124 // other users can only read
125 if ($a_permission == "read" || $a_permission == "visible") {
126 // get all objects with explicit permission
127 $objects = self::_getPermissions($a_node_id);
128 if ($objects) {
129 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
130
131 // check if given user is member of object or has role
132 foreach ($objects as $obj_id) {
133 switch ($obj_id) {
135 return true;
136
138 // check against input kept in session
139 if (self::getSharedNodePassword($a_node_id) == self::getSharedSessionPassword($a_node_id) ||
140 $a_permission == "visible") {
141 return true;
142 }
143 break;
144
146 if ($ilUser->getId() != ANONYMOUS_USER_ID) {
147 return true;
148 }
149 break;
150
151 default:
152 switch (ilObject::_lookupType($obj_id)) {
153 case "grp":
154 // member of group?
155 if (ilGroupParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id)) {
156 return true;
157 }
158 break;
159
160 case "crs":
161 // member of course?
162 if (ilCourseParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id)) {
163 return true;
164 }
165 break;
166
167 case "role":
168 // has role?
169 if ($rbacreview->isAssigned($a_user_id, $obj_id)) {
170 return true;
171 }
172 break;
173
174 case "usr":
175 // direct assignment
176 if ($a_user_id == $obj_id) {
177 return true;
178 }
179 break;
180 }
181 break;
182 }
183 }
184 }
185 }
186
187 return false;
188 }
189
196 public function setPermissions($a_parent_node_id, $a_node_id)
197 {
198 // nothing to do as owner has irrefutable rights to any portfolio object
199 }
200
208 public function addPermission($a_node_id, $a_object_id, $a_extended_data = null)
209 {
212
213 // current owner must not be added
214 if ($a_object_id == $ilUser->getId()) {
215 return;
216 }
217
218 $ilDB->manipulate("INSERT INTO usr_portf_acl (node_id, object_id, extended_data, tstamp)" .
219 " VALUES (" . $ilDB->quote($a_node_id, "integer") . ", " .
220 $ilDB->quote($a_object_id, "integer") . "," .
221 $ilDB->quote($a_extended_data, "text") . "," .
222 $ilDB->quote(time(), "integer") . ")");
223
224 // portfolio as profile
225 $this->syncProfile($a_node_id);
226 }
227
234 public function removePermission($a_node_id, $a_object_id = null)
235 {
237
238 $query = "DELETE FROM usr_portf_acl" .
239 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer");
240
241 if ($a_object_id) {
242 $query .= " AND object_id = " . $ilDB->quote($a_object_id, "integer");
243 }
244
245 $ilDB->manipulate($query);
246
247 // portfolio as profile
248 $this->syncProfile($a_node_id);
249 }
250
257 public function getPermissions($a_node_id)
258 {
259 return self::_getPermissions($a_node_id);
260 }
261
268 public static function _getPermissions($a_node_id)
269 {
270 global $DIC;
271
272 $ilDB = $DIC->database();
273
274 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl" .
275 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer"));
276 $res = array();
277 while ($row = $ilDB->fetchAssoc($set)) {
278 $res[] = $row["object_id"];
279 }
280 return $res;
281 }
282
283 public function hasRegisteredPermission($a_node_id)
284 {
286
287 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl" .
288 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer") .
289 " AND object_id = " . $ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_REGISTERED, "integer"));
290 return (bool) $ilDB->numRows($set);
291 }
292
293 public function hasGlobalPermission($a_node_id)
294 {
296
297 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl" .
298 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer") .
299 " AND object_id = " . $ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL, "integer"));
300 return (bool) $ilDB->numRows($set);
301 }
302
303 public function hasGlobalPasswordPermission($a_node_id)
304 {
306
307 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl" .
308 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer") .
309 " AND object_id = " . $ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
310 return (bool) $ilDB->numRows($set);
311 }
312
313 public function getObjectsIShare($a_online_only = true)
314 {
317
318 $res = array();
319
320 $sql = "SELECT obj.obj_id" .
321 " FROM object_data obj" .
322 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)" .
323 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)" .
324 " WHERE obj.owner = " . $ilDB->quote($ilUser->getId(), "integer");
325
326 if ($a_online_only) {
327 $sql .= " AND prtf.is_online = " . $ilDB->quote(1, "integer");
328 }
329
330 $set = $ilDB->query($sql);
331 while ($row = $ilDB->fetchAssoc($set)) {
332 $res[] = $row["obj_id"];
333 }
334
335 return $res;
336 }
337
338 public static function getPossibleSharedTargets()
339 {
340 global $DIC;
341
342 $ilUser = $DIC->user();
343
344 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
345 include_once "Services/Membership/classes/class.ilParticipants.php";
346 $grp_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "grp");
347 $crs_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "crs");
348
349 $obj_ids = array_merge($grp_ids, $crs_ids);
350 $obj_ids[] = $ilUser->getId();
354
355 return $obj_ids;
356 }
357
358 public function getSharedOwners()
359 {
362
363 $obj_ids = $this->getPossibleSharedTargets();
364
365 $user_ids = array();
366 $set = $ilDB->query("SELECT DISTINCT(obj.owner), u.lastname, u.firstname, u.title" .
367 " FROM object_data obj" .
368 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)" .
369 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)" .
370 " JOIN usr_data u on (u.usr_id = obj.owner)" .
371 " WHERE " . $ilDB->in("acl.object_id", $obj_ids, "", "integer") .
372 " AND obj.owner <> " . $ilDB->quote($ilUser->getId(), "integer") .
373 " AND prtf.is_online = " . $ilDB->quote(1, "integer") .
374 " ORDER BY u.lastname, u.firstname, u.title");
375 while ($row = $ilDB->fetchAssoc($set)) {
376 $user_ids[$row["owner"]] = $row["lastname"] . ", " . $row["firstname"];
377 if ($row["title"]) {
378 $user_ids[$row["owner"]] .= ", " . $row["title"];
379 }
380 }
381
382 return $user_ids;
383 }
384
385 public function getSharedObjects($a_owner_id)
386 {
388
389 $obj_ids = $this->getPossibleSharedTargets();
390
391 $res = array();
392 $set = $ilDB->query("SELECT obj.obj_id, obj.owner" .
393 " FROM object_data obj" .
394 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)" .
395 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)" .
396 " WHERE " . $ilDB->in("acl.object_id", $obj_ids, "", "integer") .
397 " AND obj.owner = " . $ilDB->quote($a_owner_id, "integer") .
398 " AND prtf.is_online = " . $ilDB->quote(1, "integer"));
399 while ($row = $ilDB->fetchAssoc($set)) {
400 $res[$row["obj_id"]] = $row["obj_id"];
401 }
402
403 return $res;
404 }
405
406 public function getShardObjectsDataForUserIds(array $a_owner_ids)
407 {
409
410 $obj_ids = $this->getPossibleSharedTargets();
411
412 $res = array();
413
414 $set = $ilDB->query("SELECT obj.obj_id, obj.owner, obj.title" .
415 " FROM object_data obj" .
416 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)" .
417 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)" .
418 " WHERE " . $ilDB->in("acl.object_id", $obj_ids, "", "integer") .
419 " AND " . $ilDB->in("obj.owner", $a_owner_ids, "", "integer") .
420 " AND prtf.is_online = " . $ilDB->quote(1, "integer"));
421 while ($row = $ilDB->fetchAssoc($set)) {
422 $res[$row["owner"]][$row["obj_id"]] = $row["title"];
423 }
424
425 return $res;
426 }
427
428 public function findSharedObjects(array $a_filter = null, array $a_crs_ids = null, array $a_grp_ids = null)
429 {
432 if (!$a_filter["acl_type"]) {
433 $obj_ids = $this->getPossibleSharedTargets();
434 } else {
435 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
436
437 switch ($a_filter["acl_type"]) {
438 case "all":
439 $obj_ids = array(ilWorkspaceAccessGUI::PERMISSION_ALL);
440 break;
441
442 case "password":
444 break;
445
446 case "registered":
448 break;
449
450 case "course":
451 $obj_ids = $a_crs_ids;
452 break;
453
454 case "group":
455 $obj_ids = $a_grp_ids;
456 break;
457
458 case "user":
459 $obj_ids = array($ilUser->getId());
460 break;
461 }
462 }
463
464 $res = array();
465
466 $sql = "SELECT obj.obj_id,obj.title,obj.owner" .
467 ",acl.object_id acl_type, acl.tstamp acl_date" .
468 " FROM object_data obj" .
469 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)" .
470 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)" .
471 " WHERE " . $ilDB->in("acl.object_id", $obj_ids, "", "integer") .
472 " AND obj.owner <> " . $ilDB->quote($ilUser->getId(), "integer") .
473 " AND obj.type = " . $ilDB->quote("prtf", "text") .
474 " AND prtf.is_online = " . $ilDB->quote(1, "integer");
475
476 if ($a_filter["title"] && strlen($a_filter["title"]) >= 3) {
477 $sql .= " AND " . $ilDB->like("obj.title", "text", "%" . $a_filter["title"] . "%");
478 }
479 if ($a_filter["user"] && strlen($a_filter["user"]) >= 3) {
480 $usr_ids = array();
481 $set = $ilDB->query("SELECT usr_id FROM usr_data" .
482 " WHERE (" . $ilDB->like("login", "text", "%" . $a_filter["user"] . "%") . " " .
483 "OR " . $ilDB->like("firstname", "text", "%" . $a_filter["user"] . "%") . " " .
484 "OR " . $ilDB->like("lastname", "text", "%" . $a_filter["user"] . "%") . " " .
485 "OR " . $ilDB->like("email", "text", "%" . $a_filter["user"] . "%") . ")");
486 while ($row = $ilDB->fetchAssoc($set)) {
487 $usr_ids[] = $row["usr_id"];
488 }
489 if (!sizeof($usr_ids)) {
490 return;
491 }
492 $sql .= " AND " . $ilDB->in("obj.owner", $usr_ids, "", "integer");
493 }
494
495 if ($a_filter["acl_date"]) {
496 $dt = $a_filter["acl_date"]->get(IL_CAL_DATE);
497 $dt = new ilDateTime($dt . " 00:00:00", IL_CAL_DATETIME);
498 $sql .= " AND acl.tstamp > " . $ilDB->quote($dt->get(IL_CAL_UNIX), "integer");
499 }
500
501 if ($a_filter["crsgrp"]) {
502 include_once "Services/Membership/classes/class.ilParticipants.php";
503 $part = ilParticipants::getInstanceByObjId($a_filter['crsgrp']);
504 $part = $part->getParticipants();
505 if (!sizeof($part)) {
506 return;
507 }
508 $sql .= " AND " . $ilDB->in("obj.owner", $part, "", "integer");
509 }
510
511 // we use the oldest share date
512 $sql .= " ORDER BY acl.tstamp";
513
514 $set = $ilDB->query($sql);
515 while ($row = $ilDB->fetchAssoc($set)) {
516 if (!isset($res[$row["obj_id"]])) {
517 $row["acl_type"] = array($row["acl_type"]);
518 $res[$row["obj_id"]] = $row;
519 } else {
520 $res[$row["obj_id"]]["acl_type"][] = $row["acl_type"];
521 }
522 }
523
524 return $res;
525 }
526
527 public static function getSharedNodePassword($a_node_id)
528 {
529 global $DIC;
530
531 $ilDB = $DIC->database();
532
533 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
534
535 $set = $ilDB->query("SELECT extended_data FROM usr_portf_acl" .
536 " WHERE node_id = " . $ilDB->quote($a_node_id, "integer") .
537 " AND object_id = " . $ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
538 $res = $ilDB->fetchAssoc($set);
539 if ($res) {
540 return $res["extended_data"];
541 }
542 }
543
544 public static function keepSharedSessionPassword($a_node_id, $a_password)
545 {
546 $_SESSION["ilshpw_" . $a_node_id] = $a_password;
547 }
548
549 public static function getSharedSessionPassword($a_node_id)
550 {
551 return $_SESSION["ilshpw_" . $a_node_id];
552 }
553
554 protected function syncProfile($a_node_id)
555 {
557
558 // #12845
559 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
560 if (ilObjPortfolio::getDefaultPortfolio($ilUser->getId()) == $a_node_id) {
561 $has_registered = $this->hasRegisteredPermission($a_node_id);
562 $has_global = $this->hasGlobalPermission($a_node_id);
563
564 // not published anymore - remove portfolio as profile
565 if (!$has_registered && !$has_global) {
566 $ilUser->setPref("public_profile", "n");
567 $ilUser->writePrefs();
569 }
570 // adapt profile setting
571 else {
572 $new_pref = "y";
573 if ($has_global) {
574 $new_pref = "g";
575 }
576 if ($ilUser->getPref("public_profile") != $new_pref) {
577 $ilUser->setPref("public_profile", $new_pref);
578 $ilUser->writePrefs();
579 }
580 }
581 }
582 }
583
584
590 public function canBeDelivered(ilWACPath $ilWACPath)
591 {
593 $ilAccess = $this->access;
594
595 if (preg_match("/\\/prtf_([\\d]*)\\//uism", $ilWACPath->getPath(), $results)) {
596 // portfolio (custom)
597 $obj_id = $results[1];
598 if (ilObject::_lookupType($obj_id) == "prtf") {
599 if ($this->checkAccessOfUser($ilUser->getId(), "read", "view", $obj_id, "prtf")) {
600 return true;
601 }
602 }
603 // portfolio template (RBAC)
604 else {
605 $ref_ids = ilObject::_getAllReferences($obj_id);
606 foreach ($ref_ids as $ref_id) {
607 if ($ilAccess->checkAccessOfUser($ilUser->getId(), "read", "view", $ref_id, "prtt", $obj_id)) {
608 return true;
609 }
610 }
611 }
612 }
613
614 return false;
615 }
616}
user()
Definition: user.php:4
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
@classDescription Date and time handling
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static setUserDefault($a_user_id, $a_portfolio_id=null)
Set the user default portfolio.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
Access handler for portfolio.
addPermission($a_node_id, $a_object_id, $a_extended_data=null)
Add permission to node for object.
findSharedObjects(array $a_filter=null, array $a_crs_ids=null, array $a_grp_ids=null)
checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_node_id, $a_type="")
check access for an object
setPermissions($a_parent_node_id, $a_node_id)
Set permissions after creating node/object.
checkAccess($a_permission, $a_cmd, $a_node_id, $a_type="")
check access for an object
static _getPermissions($a_node_id)
Get all permissions to node.
removePermission($a_node_id, $a_object_id=null)
Remove permission[s] (for object) to node.
static keepSharedSessionPassword($a_node_id, $a_password)
getPermissions($a_node_id)
Get all permissions to node.
Class ilWACPath.
Class ilWACCheckingClass.
global $ilSetting
Definition: privfeed.php:17
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
global $ilDB
$results
Definition: svg-scanner.php:47
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92