ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjRole.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 class ilObjRole extends ilObject
27 {
32 
33  public const MODE_ADD_OPERATIONS = 1;
34  public const MODE_READ_OPERATIONS = 2;
35  public const MODE_REMOVE_OPERATIONS = 3;
36 
37  private ilLogger $logger;
38 
39  public ?int $parent = null;
40 
41  protected bool $allow_register = false;
42  protected bool $assign_users = false;
43 
50  public function __construct(int $a_id = 0, bool $a_call_by_reference = false)
51  {
52  global $DIC;
53 
54  $this->logger = $DIC->logger()->ac();
55  $this->type = "role";
56  parent::__construct($a_id, $a_call_by_reference);
57  }
58 
59  public static function createDefaultRole(
60  string $a_title,
61  string $a_description,
62  string $a_tpl_name,
63  int $a_ref_id
64  ): ?ilObjRole {
65  global $DIC;
66 
67  $ilDB = $DIC->database();
68 
69  // SET PERMISSION TEMPLATE OF NEW LOCAL CONTRIBUTOR ROLE
70  $res = $ilDB->query("SELECT obj_id FROM object_data " .
71  " WHERE type=" . $ilDB->quote("rolt", "text") .
72  " AND title=" . $ilDB->quote($a_tpl_name, "text"));
73  $tpl_id = 0;
74  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75  $tpl_id = (int) $row->obj_id;
76  }
77  if (!$tpl_id) {
78  return null;
79  }
80 
81  $role = new ilObjRole();
82  $role->setTitle($a_title);
83  $role->setDescription($a_description);
84  $role->create();
85 
86  $GLOBALS['DIC']['rbacadmin']->assignRoleToFolder($role->getId(), $a_ref_id, 'y');
87  $GLOBALS['DIC']['rbacadmin']->copyRoleTemplatePermissions(
88  $tpl_id,
90  $a_ref_id,
91  $role->getId()
92  );
93 
94  $ops = $GLOBALS['DIC']['rbacreview']->getOperationsOfRole(
95  $role->getId(),
96  ilObject::_lookupType($a_ref_id, true),
97  $a_ref_id
98  );
99  $GLOBALS['DIC']['rbacadmin']->grantPermission(
100  $role->getId(),
101  $ops,
102  $a_ref_id
103  );
104  return $role;
105  }
106 
107  public function validate(): bool
108  {
109  global $DIC;
110 
111  $ilErr = $DIC['ilErr'];
112 
113  if (substr($this->getTitle(), 0, 3) == 'il_') {
114  $ilErr->setMessage('msg_role_reserved_prefix');
115  return false;
116  }
117  return true;
118  }
119 
120  public function getPresentationTitle(): string
121  {
122  $r = ilObjRole::_getTranslation($this->getTitle());
123 
124  if ($r === $this->getUntranslatedTitle()) {
125  return $r;
126  }
127 
128  return $r . ' (' . $this->getUntranslatedTitle() . ')';
129  }
130 
131  public function toggleAssignUsersStatus(bool $a_assign_users): void
132  {
133  $this->assign_users = $a_assign_users;
134  }
135 
136  public function getAssignUsersStatus(): bool
137  {
138  return $this->assign_users;
139  }
140 
141  public static function _getAssignUsersStatus(int $a_role_id): bool
142  {
143  global $DIC;
144 
145  $ilDB = $DIC->database();
146  $query = "SELECT assign_users FROM role_data WHERE role_id = " . $ilDB->quote($a_role_id, 'integer') . " ";
147  $res = $ilDB->query($query);
148  while ($row = $ilDB->fetchObject($res)) {
149  return (bool) $row->assign_users;
150  }
151  return false;
152  }
153 
158  public function read(): void
159  {
160  $query = "SELECT * FROM role_data WHERE role_id= " . $this->db->quote($this->id, 'integer') . " ";
161  $res = $this->db->query($query);
162  if ($res->numRows() > 0) {
163  $row = $this->db->fetchAssoc($res);
164  $this->setAllowRegister((bool) $row['allow_register']);
165  $this->toggleAssignUsersStatus((bool) ($row['assign_users'] ?? false));
166  } else {
167  $this->logger->logStack(ilLogLevel::ERROR);
168  throw new ilObjectException('There is no dataset with id: ' . $this->id);
169  }
170  parent::read();
171  }
172 
173  public function update(): bool
174  {
175  $query = "UPDATE role_data SET " .
176  "allow_register= " . $this->db->quote($this->allow_register, 'integer') . ", " .
177  "assign_users = " . $this->db->quote($this->getAssignUsersStatus(), 'integer') . " " .
178  "WHERE role_id= " . $this->db->quote($this->id, 'integer') . " ";
179  $res = $this->db->manipulate($query);
180 
181  parent::update();
182 
183  $this->read();
184 
185  return true;
186  }
187 
188  public function create(): int
189  {
190  global $DIC;
191 
192  $this->id = parent::create();
193  $query = "INSERT INTO role_data " .
194  "(role_id,allow_register,assign_users) " .
195  "VALUES " .
196  "(" . $this->db->quote($this->id, 'integer') . "," .
197  $this->db->quote($this->getAllowRegister(), 'integer') . "," .
198  $this->db->quote($this->getAssignUsersStatus(), 'integer') . ")";
199  $res = $this->db->query($query);
200 
201  return $this->id;
202  }
203 
204  public function setAllowRegister(bool $a_allow_register): void
205  {
206  $this->allow_register = $a_allow_register;
207  }
208 
209  public function getAllowRegister(): bool
210  {
211  return $this->allow_register;
212  }
213 
217  public static function _lookupRegisterAllowed(): array
218  {
219  global $DIC;
220 
221  $ilDB = $DIC->database();
222  $query = "SELECT * FROM role_data " .
223  "JOIN object_data ON object_data.obj_id = role_data.role_id " .
224  "WHERE allow_register = 1";
225  $res = $ilDB->query($query);
226 
227  $roles = [];
228  while ($role = $ilDB->fetchAssoc($res)) {
229  $roles[] = array("id" => (int) $role["obj_id"],
230  "title" => (string) $role["title"],
231  "auth_mode" => (string) $role['auth_mode']
232  );
233  }
234  return $roles;
235  }
236 
240  public static function _lookupAllowRegister(int $a_role_id): bool
241  {
242  global $DIC;
243 
244  $ilDB = $DIC['ilDB'];
245 
246  $query = "SELECT * FROM role_data " .
247  " WHERE role_id =" . $ilDB->quote($a_role_id, 'integer');
248 
249  $res = $ilDB->query($query);
250  if ($role_rec = $ilDB->fetchAssoc($res)) {
251  if ($role_rec["allow_register"]) {
252  return true;
253  }
254  }
255  return false;
256  }
257 
262  public function setParent(int $a_parent_ref): void
263  {
264  $this->parent = $a_parent_ref;
265  }
266 
270  public function getParent(): ?int
271  {
272  return $this->parent;
273  }
274 
280  public function delete(): bool
281  {
282  global $DIC;
283 
284  // Temporary bugfix
285  if ($this->rbac_review->hasMultipleAssignments($this->getId())) {
286  $this->logger->warning('Found role with multiple assignments: role_id: ' . $this->getId());
287  $this->logger->warning('Aborted deletion of role.');
288  return false;
289  }
290 
291  if ($this->rbac_review->isAssignable($this->getId(), $this->getParent())) {
292  $this->logger->debug('Handling assignable role...');
293  // do not delete a global role, if the role is the last
294  // role a user is assigned to.
295  //
296  // Performance improvement: In the code section below, we
297  // only need to consider _global_ roles. We don't need
298  // to check for _local_ roles, because a user who has
299  // a local role _always_ has a global role too.
300  $last_role_user_ids = [];
301  if ($this->getParent() == ROLE_FOLDER_ID) {
302  ilLoggerFactory::getLogger('ac')->debug('Handling global role...');
303  // The role is a global role: check if
304  // we find users who aren't assigned to any
305  // other global role than this one.
306  $user_ids = $this->rbac_review->assignedUsers($this->getId());
307 
308  foreach ($user_ids as $user_id) {
309  // get all roles each user has
310  $role_ids = $this->rbac_review->assignedRoles($user_id);
311 
312  // is last role?
313  if (count($role_ids) == 1) {
314  $last_role_user_ids[] = $user_id;
315  }
316  }
317  }
318 
319  // users with last role found?
320  if ($last_role_user_ids !== []) {
321  $user_names = [];
322  foreach ($last_role_user_ids as $user_id) {
323  // GET OBJECT TITLE
324  $user_names[] = ilObjUser::_lookupLogin($user_id);
325  }
326 
327  // TODO: This check must be done in rolefolder object because if multiple
328  // roles were selected the other roles are still deleted and the system does not
329  // give any feedback about this.
330  $users = implode(', ', $user_names);
331  $this->logger->info('Cannot delete last global role of users.');
332  $this->ilias->raiseError($this->lng->txt("msg_user_last_role1") . " " .
333  $users . "<br/>" . $this->lng->txt("msg_user_last_role2"), $this->ilias->error_obj->WARNING);
334  } else {
335  $this->logger->debug('Starting deletion of assignable role: role_id: ' . $this->getId());
336  $this->rbac_admin->deleteRole($this->getId(), $this->getParent());
337 
338  // Delete ldap role group mappings
340 
341  // delete object_data entry
342  parent::delete();
343 
344  // delete role_data entry
345  $query = "DELETE FROM role_data WHERE role_id = " . $this->db->quote($this->getId(), 'integer');
346  $res = $this->db->manipulate($query);
347  }
348  } else {
349  $this->logger->debug('Starting deletion of linked role: role_id ' . $this->getId());
350  // linked local role: INHERITANCE WAS STOPPED, SO DELETE ONLY THIS LOCAL ROLE
351  $this->rbac_admin->deleteLocalRole($this->getId(), $this->getParent());
352  }
353  return true;
354  }
355 
359  public function getCountMembers(): int
360  {
361  return count($this->rbac_review->assignedUsers($this->getId()));
362  }
363 
364  public static function _getTranslation(string $a_role_title): string
365  {
366  global $DIC;
367 
368  $lng = $DIC->language();
369  $objDefinition = $DIC['objDefinition'];
370 
371  $role_title = self::_removeObjectId($a_role_title);
372 
373  if (preg_match("/^il_([a-z]{1,4})_./", $role_title, $type)) {
374  //BT ID 0032909: language variables for roles from plugins were not resolved properly
375  if ($objDefinition->isPlugin($type[1])) {
376  return ilObjectPlugin::lookupTxtById($type[1], $role_title);
377  }
378  return $lng->txt($role_title);
379  }
380  return $a_role_title;
381  }
382 
386  public static function _removeObjectId(string $a_role_title): string
387  {
388  $role_title_parts = explode('_', $a_role_title);
389 
390  $test2 = (int) ($role_title_parts[3] ?? 0);
391  if ($test2 > 0) {
392  unset($role_title_parts[3]);
393  }
394 
395  return implode('_', $role_title_parts);
396  }
397 
401  public static function getSubObjects(string $a_obj_type, bool $a_add_admin_objects): array
402  {
403  global $DIC;
407  $objDefinition = $DIC['objDefinition'];
408  $lng = $DIC->language();
409  $subs = $objDefinition->getSubObjectsRecursively($a_obj_type, true, $a_add_admin_objects);
410 
411  $filter = [];
412  $sorted = [];
413 
415  $filter = array_merge($filter, ilECSUtils::getPossibleRemoteTypes(false));
416  $filter[] = 'rtst';
417  }
418 
419  foreach ($subs as $subtype => $def) {
420  if (in_array($def["name"], $filter)) {
421  continue;
422  }
423 
424  if ($objDefinition->isPlugin($subtype)) {
425  $translation = ilObjectPlugin::lookupTxtById($subtype, "obj_" . $subtype);
426  } elseif ($objDefinition->isSystemObject($subtype)) {
427  $translation = $lng->txt("obj_" . $subtype);
428  } else {
429  $translation = $lng->txt('objs_' . $subtype);
430  }
431 
432  $sorted[$subtype] = $def;
433  $sorted[$subtype]['translation'] = $translation;
434  }
435 
436  return ilArrayUtil::sortArray($sorted, 'translation', 'asc', true, true);
437  }
438 
439  public static function _updateAuthMode(array $a_roles): void
440  {
441  global $DIC;
442 
443  $ilDB = $DIC->database();
444  foreach ($a_roles as $role_id => $auth_mode) {
445  $query = "UPDATE role_data SET " .
446  "auth_mode= " . $ilDB->quote($auth_mode, 'text') . " " .
447  "WHERE role_id= " . $ilDB->quote($role_id, 'integer') . " ";
448  $res = $ilDB->manipulate($query);
449  }
450  }
451 
452  public static function _getAuthMode(int $a_role_id): string
453  {
454  global $DIC;
455 
456  $ilDB = $DIC['ilDB'];
457 
458  $query = "SELECT auth_mode FROM role_data " .
459  "WHERE role_id= " . $ilDB->quote($a_role_id, 'integer') . " ";
460  $res = $ilDB->query($query);
461  $row = $ilDB->fetchAssoc($res);
462 
463  return $row['auth_mode'];
464  }
465 
472  public static function _getRolesByAuthMode(string $a_auth_mode): array
473  {
474  global $DIC;
475 
476  $ilDB = $DIC['ilDB'];
477 
478  $query = "SELECT * FROM role_data " .
479  "WHERE auth_mode = " . $ilDB->quote($a_auth_mode, 'text');
480  $res = $ilDB->query($query);
481  $roles = [];
482  while ($row = $ilDB->fetchObject($res)) {
483  $roles[] = $row->role_id;
484  }
485  return $roles;
486  }
487 
491  public static function _resetAuthMode(string $a_auth_mode): void
492  {
493  global $DIC;
494 
495  $ilDB = $DIC['ilDB'];
496 
497  $query = "UPDATE role_data SET auth_mode = 'default' WHERE auth_mode = " . $ilDB->quote($a_auth_mode, 'text');
498  $res = $ilDB->manipulate($query);
499  }
500 
501  public function __getPermissionDefinitions(): array
502  {
503  $operation_info = $this->rbac_review->getOperationAssignment();
504  $rbac_objects = $rbac_operations = [];
505  foreach ($operation_info as $info) {
506  if ($this->obj_definition->getDevMode($info['type'])) {
507  continue;
508  }
509  $rbac_objects[$info['typ_id']] = array("obj_id" => $info['typ_id'],
510  "type" => $info['type']
511  );
512 
513  // handle plugin permission texts
514  $txt = $this->obj_definition->isPlugin($info['type'])
515  ? ilObjectPlugin::lookupTxtById($info['type'], $info['type'] . "_" . $info['operation'])
516  : $this->lng->txt($info['type'] . "_" . $info['operation']);
517  if (substr($info['operation'], 0, 7) == "create_" &&
518  $this->obj_definition->isPlugin(substr($info['operation'], 7))) {
520  substr($info['operation'], 7),
521  $info['type'] . "_" . $info['operation']
522  );
523  }
524  $rbac_operations[$info['typ_id']][$info['ops_id']] = array(
525  "ops_id" => $info['ops_id'],
526  "title" => $info['operation'],
527  "name" => $txt
528  );
529  }
530  return array($rbac_objects, $rbac_operations);
531  }
532 
533  public static function isAutoGenerated(int $a_role_id): bool
534  {
535  return substr(ilObject::_lookupTitle($a_role_id), 0, 3) == 'il_';
536  }
537 
542  public function changeExistingObjects(
543  int $a_start_node,
544  int $a_mode,
545  array $a_filter,
546  array $a_exclusion_filter = [],
547  int $a_operation_mode = self::MODE_READ_OPERATIONS,
548  array $a_operation_stack = []
549  ): void {
550  // Get node info of subtree
551  $nodes = $this->tree->getRbacSubtreeInfo($a_start_node);
552 
553  // get local policies
554  $all_local_policies = $this->rbac_review->getObjectsWithStopedInheritance($this->getId());
555 
556  // filter relevant roles
557  $local_policies = [];
558  foreach ($all_local_policies as $lp) {
559  if (isset($nodes[$lp])) {
560  $local_policies[] = $lp;
561  }
562  }
563 
564  // Delete deprecated policies
565  switch ($a_mode) {
566  case self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES:
567  case self::MODE_PROTECTED_DELETE_LOCAL_POLICIES:
568  $local_policies = $this->deleteLocalPolicies($a_start_node, $local_policies, $a_filter);
569  break;
570  }
571  $this->adjustPermissions(
572  $a_mode,
573  $nodes,
574  $local_policies,
575  $a_filter,
576  $a_exclusion_filter,
577  $a_operation_mode,
578  $a_operation_stack
579  );
580  }
581 
582  protected function deleteLocalPolicies(int $a_start, array $a_policies, array $a_filter): array
583  {
584  global $DIC;
585  $rbacadmin = $DIC['rbacadmin'];
586 
587  $local_policies = [];
588  foreach ($a_policies as $policy) {
589  if ($policy == $a_start || $policy == SYSTEM_FOLDER_ID) {
590  $local_policies[] = $policy;
591  continue;
592  }
593  if (!in_array('all', $a_filter) && !in_array(
595  $a_filter
596  )) {
597  $local_policies[] = $policy;
598  continue;
599  }
600  $rbacadmin->deleteLocalRole($this->getId(), $policy);
601  }
602  return $local_policies;
603  }
604 
607  protected function adjustPermissions(
608  int $a_mode,
609  array $a_nodes,
610  array $a_policies,
611  array $a_filter,
612  array $a_exclusion_filter = [],
613  int $a_operation_mode = self::MODE_READ_OPERATIONS,
614  array $a_operation_stack = []
615  ): void {
616  $operation_stack = [];
617  $policy_stack = [];
618  $node_stack = [];
619 
620  $start_node = current($a_nodes);
621  $node_stack[] = $start_node;
622  $this->updatePolicyStack($policy_stack, $start_node['child']);
623 
624  if ($a_operation_mode == self::MODE_READ_OPERATIONS) {
625  $this->updateOperationStack($operation_stack, $start_node['child'], true);
626  } else {
627  $operation_stack = $a_operation_stack;
628  }
629 
630  $this->logger->debug('adjust permissions operation stack');
631  $this->logger->dump($operation_stack, ilLogLevel::DEBUG);
632 
633  $rbac_log_active = ilRbacLog::isActive();
634 
635  $local_policy = false;
636  foreach ($a_nodes as $node) {
637  $cmp_node = end($node_stack);
638  while ($relation = $this->tree->getRelationOfNodes($node, $cmp_node)) {
639  switch ($relation) {
642  $this->logger->debug('Handling sibling/none relation.');
643  array_pop($operation_stack);
644  array_pop($policy_stack);
645  array_pop($node_stack);
646  $cmp_node = end($node_stack);
647  $local_policy = false;
648  break;
649 
653  default:
654  $this->logger->debug('Handling child/equals/parent ' . $relation);
655  break 2;
656  }
657  }
658 
659  if ($local_policy) {
660  continue;
661  }
662 
663  // Start node => set permissions and continue
664  if ($node['child'] == $start_node['child']) {
665  if ($this->isHandledObjectType($a_filter, $a_exclusion_filter, $node['type'])) {
666  if ($rbac_log_active) {
667  $rbac_log_roles = $this->rbac_review->getParentRoleIds($node['child'], false);
668  $rbac_log_old = ilRbacLog::gatherFaPa((int) $node['child'], array_keys($rbac_log_roles));
669  }
670 
671  // Set permissions
672  $perms = end($operation_stack);
674  $this->getId(),
675  (array) ($perms[$node['type']] ?? []),
676  $node['child'],
677  $a_operation_mode
678  );
679 
680  if ($rbac_log_active) {
681  $rbac_log_new = ilRbacLog::gatherFaPa((int) $node['child'], array_keys($rbac_log_roles));
682  $rbac_log = ilRbacLog::diffFaPa($rbac_log_old, $rbac_log_new);
683  ilRbacLog::add(ilRbacLog::EDIT_TEMPLATE_EXISTING, $node['child'], $rbac_log);
684  }
685  }
686  continue;
687  }
688 
689  // Node has local policies => update permission stack and continue
690  if (in_array($node['child'], $a_policies) && $node['child'] != SYSTEM_FOLDER_ID) {
691  $local_policy = true;
692  $this->updatePolicyStack($policy_stack, $node['child']);
693  $this->updateOperationStack($operation_stack, $node['child']);
694  $node_stack[] = $node;
695  continue;
696  }
697 
698  // Continue if this object type is not in filter
699  if (!$this->isHandledObjectType($a_filter, $a_exclusion_filter, $node['type'])) {
700  continue;
701  }
702 
703  if ($rbac_log_active) {
704  $rbac_log_roles = $this->rbac_review->getParentRoleIds($node['child'], false);
705  $rbac_log_old = ilRbacLog::gatherFaPa((int) $node['child'], array_keys($rbac_log_roles));
706  }
707 
708  // Node is course or group => create permission intersection
709  if (
710  ($a_mode == self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES || $a_mode == self::MODE_UNPROTECTED_KEEP_LOCAL_POLICIES) &&
711  ($node['type'] == 'crs' || $node['type'] == 'grp')
712  ) {
713  // Copy role permission intersection
714  $perms = end($operation_stack);
716  $policy_stack,
717  $perms[$node['type']] ?? [],
718  $node['child'],
719  $node['type']
720  );
721  if ($this->updateOperationStack($operation_stack, $node['child'])) {
722  $this->updatePolicyStack($policy_stack, $node['child']);
723  $node_stack[] = $node;
724  }
725  }
726 
727  // Set permission
728  $perms = end($operation_stack);
730  $this->getId(),
731  (array) ($perms[$node['type']] ?? []),
732  $node['child'],
733  $a_operation_mode
734  );
735  if ($rbac_log_active) {
736  $rbac_log_new = ilRbacLog::gatherFaPa((int) $node['child'], array_keys($rbac_log_roles));
737  $rbac_log = ilRbacLog::diffFaPa($rbac_log_old, $rbac_log_new);
738  ilRbacLog::add(ilRbacLog::EDIT_TEMPLATE_EXISTING, $node['child'], $rbac_log);
739  }
740  }
741  }
742 
744  int $a_role_id,
745  array $a_permissions,
746  int $a_ref_id,
747  int $a_operation_mode
748  ): void {
749  global $DIC;
750 
751  $admin = $DIC->rbac()->admin();
752  $review = $DIC->rbac()->review();
753  if ($a_operation_mode == self::MODE_READ_OPERATIONS) {
754  $admin->grantPermission(
755  $a_role_id,
756  $a_permissions,
757  $a_ref_id
758  );
759  } elseif ($a_operation_mode == self::MODE_ADD_OPERATIONS) {
760  $current_operations = $review->getRoleOperationsOnObject(
761  $a_role_id,
762  $a_ref_id
763  );
764  $this->logger->debug('Current operations');
765  $this->logger->dump($current_operations);
766 
767  $new_ops = array_unique(array_merge($a_permissions, $current_operations));
768  $this->logger->debug('New operations');
769  $this->logger->dump($new_ops);
770 
771  $admin->grantPermission(
772  $a_role_id,
773  $new_ops,
774  $a_ref_id
775  );
776  } elseif ($a_operation_mode == self::MODE_REMOVE_OPERATIONS) {
777  $current_operations = $review->getRoleOperationsOnObject(
778  $a_role_id,
779  $a_ref_id
780  );
781  $this->logger->debug('Current operations');
782  $this->logger->dump($current_operations);
783 
784  $new_ops = array_diff($current_operations, $a_permissions);
785 
786  $admin->grantPermission(
787  $a_role_id,
788  $new_ops,
789  $a_ref_id
790  );
791  }
792  }
793 
794  protected function isHandledObjectType(array $a_filter, array $a_exclusion_filter, string $a_type): bool
795  {
796  if (in_array($a_type, $a_exclusion_filter)) {
797  return false;
798  }
799 
800  if (in_array('all', $a_filter)) {
801  return true;
802  }
803  return in_array($a_type, $a_filter);
804  }
805 
809  protected function updateOperationStack(
810  array &$a_stack,
811  int $a_node,
812  bool $a_init = false
813  ): bool {
814  $has_policies = null;
815 
816  if ($a_node == ROOT_FOLDER_ID) {
817  $has_policies = true;
818  $policy_origin = ROLE_FOLDER_ID;
819  } else {
820  $has_policies = $this->rbac_review->getLocalPolicies($a_node);
821  $policy_origin = $a_node;
822 
823  if ($a_init) {
824  $parent_roles = $this->rbac_review->getParentRoleIds($a_node, false);
825  if ($parent_roles[$this->getId()]) {
826  $a_stack[] = $this->rbac_review->getAllOperationsOfRole(
827  $this->getId(),
828  $parent_roles[$this->getId()]['parent']
829  );
830  }
831  return true;
832  }
833  }
834 
835  if (!$has_policies) {
836  return false;
837  }
838 
839  $a_stack[] = $this->rbac_review->getAllOperationsOfRole(
840  $this->getId(),
841  $policy_origin
842  );
843  return true;
844  }
845 
846  protected function updatePolicyStack(array &$a_stack, int $a_node): bool
847  {
848  $has_policies = null;
849 
850  if ($a_node == ROOT_FOLDER_ID) {
851  $has_policies = true;
852  $policy_origin = ROLE_FOLDER_ID;
853  } else {
854  $has_policies = $this->rbac_review->getLocalPolicies($a_node);
855  $policy_origin = $a_node;
856  }
857 
858  if (!$has_policies) {
859  return false;
860  }
861 
862  $a_stack[] = $policy_origin;
863  return true;
864  }
865 
869  protected function createPermissionIntersection(
870  array $policy_stack,
871  array $a_current_ops,
872  int $a_id,
873  string $a_type
874  ): void {
875  static $course_non_member_id = null;
876  static $group_non_member_id = null;
877  static $group_open_id = null;
878  static $group_closed_id = null;
879 
880  $template_id = 0;
881  // Get template id
882  switch ($a_type) {
883  case 'grp':
885  switch ($type) {
887  if (!$group_closed_id) {
888  $query = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
889  $res = $this->db->query($query);
890  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
891  $group_closed_id = (int) $row->obj_id;
892  }
893  }
894  $template_id = $group_closed_id;
895  #var_dump("GROUP CLOSED id:" . $template_id);
896  break;
897 
899  default:
900  if (!$group_open_id) {
901  $query = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
902  $res = $this->db->query($query);
903  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
904  $group_open_id = (int) $row->obj_id;
905  }
906  }
907  $template_id = $group_open_id;
908  break;
909  }
910  break;
911 
912  case 'crs':
913  if (!$course_non_member_id) {
914  $query = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
915  $res = $this->db->query($query);
916  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
917  $course_non_member_id = (int) $row->obj_id;
918  }
919  }
920  $template_id = $course_non_member_id;
921  break;
922  }
923 
924  // Create intersection template permissions
925  if ($template_id && $policy_stack !== []) {
926  $this->rbac_admin->copyRolePermissionIntersection(
927  $template_id,
929  $this->getId(),
930  end($policy_stack),
931  $a_id,
932  $this->getId()
933  );
934  } else {
935  }
936  if ($a_id && !$GLOBALS['DIC']['rbacreview']->isRoleAssignedToObject($this->getId(), $a_id)) {
937  $this->rbac_admin->assignRoleToFolder($this->getId(), $a_id, "n");
938  }
939  }
940 }
Class ilObjRole.
static isAutoGenerated(int $a_role_id)
static gatherFaPa(int $a_ref_id, array $a_role_ids, bool $a_add_action=false)
$res
Definition: ltiservices.php:69
string $type
static getLogger(string $a_component_id)
Get component logger.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupRegisterAllowed()
get all roles that are activated in user registration
ilLogger $logger
changeExistingObjectsGrantPermissions(int $a_role_id, array $a_permissions, int $a_ref_id, int $a_operation_mode)
static ecsConfigured()
Checks if an ecs server is configured.
const ROOT_FOLDER_ID
Definition: constants.php:32
createPermissionIntersection(array $policy_stack, array $a_current_ops, int $a_id, string $a_type)
Create permission intersection.
static _removeObjectId(string $a_role_title)
const MODE_PROTECTED_DELETE_LOCAL_POLICIES
deleteLocalPolicies(int $a_start, array $a_policies, array $a_filter)
setAllowRegister(bool $a_allow_register)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setParent(int $a_parent_ref)
set reference id of parent object this is neccessary for non RBAC protected objects!!! ...
const RELATION_PARENT
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static isActive()
adjustPermissions(int $a_mode, array $a_nodes, array $a_policies, array $a_filter, array $a_exclusion_filter=[], int $a_operation_mode=self::MODE_READ_OPERATIONS, array $a_operation_stack=[])
const MODE_REMOVE_OPERATIONS
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
const SYSTEM_FOLDER_ID
Definition: constants.php:35
static diffFaPa(array $a_old, array $a_new)
static lookupGroupTye(int $a_id)
static _getRolesByAuthMode(string $a_auth_mode)
Get roles by auth mode public.
$ilErr
Definition: raiseError.php:17
const MODE_PROTECTED_KEEP_LOCAL_POLICIES
static _lookupObjId(int $ref_id)
const MODE_READ_OPERATIONS
global $DIC
Definition: feed.php:28
toggleAssignUsersStatus(bool $a_assign_users)
static add(int $a_action, int $a_ref_id, array $a_diff, bool $a_source_ref_id=false)
static _lookupTitle(int $obj_id)
isHandledObjectType(array $a_filter, array $a_exclusion_filter, string $a_type)
ilLanguage $lng
static _getTranslation(string $a_role_title)
static _resetAuthMode(string $a_auth_mode)
Reset auth mode to default.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
bool $allow_register
header include for all ilias files.
$query
const RELATION_EQUALS
updateOperationStack(array &$a_stack, int $a_node, bool $a_init=false)
Update operation stack.
$txt
Definition: error.php:13
const RELATION_CHILD
const RELATION_NONE
const ROLE_FOLDER_ID
Definition: constants.php:34
static _getAuthMode(int $a_role_id)
getParent()
get reference id of parent object
const MODE_ADD_OPERATIONS
static lookupTxtById(string $plugin_id, string $lang_var)
__getPermissionDefinitions()
getCountMembers()
Get number of users assigned to role.
__construct(int $a_id=0, bool $a_call_by_reference=false)
Constructor public.
const MODE_UNPROTECTED_DELETE_LOCAL_POLICIES
static _updateAuthMode(array $a_roles)
__construct(Container $dic, ilPlugin $plugin)
const MODE_UNPROTECTED_KEEP_LOCAL_POLICIES
bool $assign_users
const EDIT_TEMPLATE_EXISTING
const RELATION_SIBLING
read()
loads "role" from database private
updatePolicyStack(array &$a_stack, int $a_node)
static _getAssignUsersStatus(int $a_role_id)
getUntranslatedTitle()
Get untranslated object title WebDAV needs to access the untranslated title of an object...
static _lookupType(int $id, bool $reference=false)
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not
changeExistingObjects(int $a_start_node, int $a_mode, array $a_filter, array $a_exclusion_filter=[], int $a_operation_mode=self::MODE_READ_OPERATIONS, array $a_operation_stack=[])
Change existing objects.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _lookupLogin(int $a_user_id)