ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjectRolePermissionTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27{
28 public const ROLE_FILTER_ALL = 1;
29 public const ROLE_FILTER_GLOBAL = 2;
30 public const ROLE_FILTER_LOCAL = 3;
31 public const ROLE_FILTER_LOCAL_POLICY = 4;
32 public const ROLE_FILTER_LOCAL_OBJECT = 5;
33
34 private int $ref_id;
35 private array $tree_path_ids = [];
36 private array $activeOperations = [];
37 private array $visible_roles = [];
38
39 protected ilTree $tree;
42
43 public function __construct(ilPermissionGUI $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
44 {
45 global $DIC;
46
47 $this->objDefinition = $DIC['objDefinition'];
48 $this->review = $DIC->rbac()->review();
49
50 $this->ref_id = $a_ref_id;
51 $this->setId('objroleperm_' . $this->ref_id);
52 parent::__construct($a_parent_obj, $a_parent_cmd);
53
54 $this->lng->loadLanguageModule('rbac');
55
56 $this->tree = $DIC->repositoryTree();
57 $this->tree_path_ids = $this->tree->getPathId($this->ref_id);
58
59 $tpl = $DIC->ui()->mainTemplate();
60 $tpl->addJavaScript('assets/js/ilPermSelect.js');
61
62 $this->setTitle($this->lng->txt('permission_settings'));
63 $this->setEnableHeader(true);
64 $this->disable('sort');
65 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
66 $this->disable('numinfo');
67 $this->setRowTemplate("tpl.obj_role_perm_row.html", "components/ILIAS/AccessControl");
68 $this->setLimit(100);
69 $this->setShowRowsSelector(false);
70 $this->setDisableFilterHiding(true);
71 $this->setNoEntriesText($this->lng->txt('msg_no_roles_of_type'));
72 $this->addCommandButton('savePermissions', $this->lng->txt('save'));
73 $this->initFilter();
74 }
75
79 public function getPathIds(): array
80 {
82 }
83
87 public function getRefId(): int
88 {
89 return $this->ref_id;
90 }
91
95 public function getObjId(): int
96 {
97 return ilObject::_lookupObjId($this->getRefId());
98 }
99
103 public function getObjType(): string
104 {
105 return ilObject::_lookupType($this->getObjId());
106 }
107
111 public function addActiveOperation(int $a_ops_id): void
112 {
113 $this->activeOperations[] = $a_ops_id;
114 }
115
120 public function getActiveOperations(): array
121 {
123 }
124
125 public function setVisibleRoles(array $a_ar): void
126 {
127 $this->visible_roles = $a_ar;
128 }
129
133 public function getVisibleRoles(): array
134 {
136 }
137
141 public function initFilter(): void
142 {
143 global $DIC;
144
145 $tree = $DIC['tree'];
146
147 $roles = $this->addFilterItemByMetaType(
148 'role',
150 );
151
152 // Limit filter to local roles only for objects with group or course in path
153 if (!$roles->getValue()) {
154 if ($tree->checkForParentType($this->getRefId(), 'crs') || $tree->checkForParentType($this->getRefId(), 'grp')) {
155 $roles->setValue(self::ROLE_FILTER_LOCAL);
156 } else {
157 $roles->setValue(self::ROLE_FILTER_ALL);
158 }
159 }
160
161 $roles->setOptions(
162 [
163 self::ROLE_FILTER_ALL => $this->lng->txt('filter_all_roles'),
164 self::ROLE_FILTER_GLOBAL => $this->lng->txt('filter_global_roles'),
165 self::ROLE_FILTER_LOCAL => $this->lng->txt('filter_local_roles'),
166 self::ROLE_FILTER_LOCAL_POLICY => $this->lng->txt('filter_roles_local_policy'),
167 self::ROLE_FILTER_LOCAL_OBJECT => $this->lng->txt('filter_local_roles_object')
168 ]
169 );
170 }
171
174 protected function fillRow(array $a_set): void
175 {
176 // local policy
177 if (isset($a_set['show_local_policy_row'])) {
178 foreach ($a_set['roles'] as $role_id => $role_info) {
179 $this->tpl->setCurrentBlock('role_option');
180 $this->tpl->setVariable('INHERIT_ROLE_ID', $role_id);
181 $this->tpl->setVariable('INHERIT_CHECKED', $role_info['local_policy'] ? 'checked=checked' : '');
182 $this->tpl->setVariable(
183 'INHERIT_DISABLED',
184 ($role_info['protected'] || $role_info['isLocal'] || $role_info['blocked']) ? 'disabled="disabled"' : ''
185 );
186 $this->tpl->setVariable('TXT_INHERIT', $this->lng->txt('rbac_local_policy'));
187 $this->tpl->setVariable('INHERIT_LONG', $this->lng->txt('perm_use_local_policy_desc'));
188 $this->tpl->parseCurrentBlock();
189 }
190 return;
191 }
192 // protected
193 if (isset($a_set['show_protected_row'])) {
194 foreach ($a_set['roles'] as $role_id => $role_info) {
195 $this->tpl->setCurrentBlock('role_protect');
196 $this->tpl->setVariable('PROTECT_ROLE_ID', $role_id);
197 $this->tpl->setVariable('PROTECT_CHECKED', $role_info['protected_status'] ? 'checked=checked' : '');
198 $this->tpl->setVariable(
199 'PROTECT_DISABLED',
200 $role_info['protected_allowed'] ? '' : 'disabled="disabled"'
201 );
202 $this->tpl->setVariable('TXT_PROTECT', $this->lng->txt('role_protect_permissions'));
203 $this->tpl->setVariable('PROTECT_LONG', $this->lng->txt('role_protect_permissions_desc'));
204 $this->tpl->parseCurrentBlock();
205 }
206 return;
207 }
208
209 // block role
210 if (isset($a_set['show_block_row'])) {
211 foreach ($this->getVisibleRoles() as $role_info) {
212 $this->tpl->setCurrentBlock('role_block');
213 $this->tpl->setVariable('BLOCK_ROLE_ID', $role_info['obj_id']);
214 $this->tpl->setVariable('TXT_BLOCK', $this->lng->txt('role_block_role'));
215 $this->tpl->setVariable('BLOCK_LONG', $this->lng->txt('role_block_role_desc'));
216 if ($role_info['blocked']) {
217 $this->tpl->setVariable('BLOCK_CHECKED', 'checked="checked"');
218 }
219 if (
220 ($role_info['protected'] == 'y') ||
221 ($role_info['assign'] == 'y' && $role_info['parent'] == $this->getRefId())
222 ) {
223 $this->tpl->setVariable('BLOCK_DISABLED', 'disabled="disabled');
224 }
225
226 $this->tpl->parseCurrentBlock();
227 }
228 return;
229 }
230
231 // Select all
232 if (isset($a_set['show_select_all'])) {
233 foreach ($this->getVisibleRoles() as $role) {
234 $this->tpl->setCurrentBlock('role_select_all');
235 $this->tpl->setVariable('JS_ROLE_ID', $role['obj_id']);
236 $this->tpl->setVariable('JS_SUBID', $a_set['subtype']);
237 $this->tpl->setVariable('JS_ALL_PERMS', "['" . implode("','", $a_set['ops']) . "']");
238 $this->tpl->setVariable('JS_FORM_NAME', $this->getFormName());
239 $this->tpl->setVariable('TXT_SEL_ALL', $this->lng->txt('select_all'));
240 $this->tpl->parseCurrentBlock();
241 }
242 return;
243 }
244
245 // Object permissions
246 if (isset($a_set['show_start_info'])) {
247 $this->tpl->setCurrentBlock('section_info');
248 $this->tpl->setVariable('SECTION_TITLE', $this->lng->txt('perm_class_object'));
249 $this->tpl->setVariable('SECTION_DESC', $this->lng->txt('perm_class_object_desc'));
250 $this->tpl->parseCurrentBlock();
251
252 return;
253 }
254
255 if (isset($a_set['show_create_info'])) {
256 $this->tpl->setCurrentBlock('section_info');
257 $this->tpl->setVariable('SECTION_TITLE', $this->lng->txt('perm_class_create'));
258 $this->tpl->setVariable('SECTION_DESC', $this->lng->txt('perm_class_create_desc'));
259 $this->tpl->parseCurrentBlock();
260
261 return;
262 }
263
264 foreach ((array) $a_set['roles'] as $role_id => $role_info) {
265 $perm = "";
266 $this->tpl->setCurrentBlock('role_td');
267 $this->tpl->setVariable('PERM_ROLE_ID', $role_id);
268 $this->tpl->setVariable('PERM_PERM_ID', $a_set['perm']['ops_id']);
269
270 if (substr($a_set['perm']['operation'], 0, 6) == 'create') {
271 if ($this->objDefinition->isPlugin(substr($a_set['perm']['operation'], 7))) {
273 substr($a_set['perm']['operation'], 7),
274 "obj_" . substr($a_set['perm']['operation'], 7)
275 );
276 } else {
277 $perm = $this->lng->txt('obj_' . substr($a_set['perm']['operation'], 7));
278 }
279 } else {
280 if ($this->objDefinition->isPlugin($this->getObjType())) {
281 if (ilObjectPlugin::langExitsById($this->getObjType(), $a_set['perm']['operation'])) {
282 $perm = ilObjectPlugin::lookupTxtById($this->getObjType(), $a_set['perm']['operation']);
283 }
284 }
285
286 if (!$perm) {
287 if ($this->lng->exists($this->getObjType() . '_' . $a_set['perm']['operation'] . '_short')) {
288 $perm = $this->lng->txt($this->getObjType() . '_' . $a_set['perm']['operation'] . '_short');
289 } else {
290 $perm = $this->lng->txt($a_set['perm']['operation']);
291 }
292 }
293 }
294
295 $this->tpl->setVariable('TXT_PERM', $perm);
296
297 if ($this->objDefinition->isPlugin($this->getObjType())) {
298 $this->tpl->setVariable('PERM_LONG', ilObjectPlugin::lookupTxtById(
299 $this->getObjType(),
300 $this->getObjType() . "_" . $a_set['perm']['operation']
301 ));
302 } elseif (substr($a_set['perm']['operation'], 0, 6) == 'create') {
303 if ($this->objDefinition->isPlugin(substr($a_set['perm']['operation'], 7))) {
304 $this->tpl->setVariable('PERM_LONG', ilObjectPlugin::lookupTxtById(
305 substr($a_set['perm']['operation'], 7),
306 $this->getObjType() . "_" . $a_set['perm']['operation']
307 ));
308 } else {
309 $this->tpl->setVariable('PERM_LONG', $this->lng->txt('rbac_' . $a_set['perm']['operation']));
310 }
311 } else {
312 $this->tpl->setVariable(
313 'PERM_LONG',
314 $this->lng->txt($this->getObjType() . '_' . $a_set['perm']['operation'])
315 );
316 }
317
318 if ($role_info['protected'] || $role_info['blocked']) {
319 $this->tpl->setVariable('PERM_DISABLED', 'disabled="disabled"');
320 }
321 if ($role_info['permission_set']) {
322 $this->tpl->setVariable('PERM_CHECKED', 'checked="checked"');
323 }
324
325 $this->tpl->parseCurrentBlock();
326 }
327 }
328
332 public function parse(): void
333 {
334 $this->initColumns();
335
336 $perms = [];
337 $roles = [];
338
339 if ($this->getVisibleRoles() === []) {
340 $this->setData([]);
341 return;
342 }
343
344 // Read operations of role
345 $operations = [];
346 foreach ($this->getVisibleRoles() as $role_data) {
347 $operations[$role_data['obj_id']] = $this->review->getActiveOperationsOfRole(
348 $this->getRefId(),
349 $role_data['obj_id']
350 );
351 }
352
353 $counter = 0;
354
355 // Local policy
357 $roles = [];
358 $local_roles = $this->review->getRolesOfObject($this->getRefId());
359 foreach ($this->getVisibleRoles() as $role_data) {
360 $roles[$role_data['obj_id']] = [
361 'blocked' => $role_data['blocked'],
362 'protected' => $role_data['protected'],
363 'local_policy' => in_array($role_data['obj_id'], $local_roles),
364 'isLocal' => ($this->getRefId() == $role_data['parent']) && $role_data['assign'] == 'y'
365 ];
366 }
367 $perms[$counter]['roles'] = $roles;
368 $perms[$counter]['show_local_policy_row'] = 1;
369
370 $counter++;
371 }
372
373 // Protect permissions
375 $roles = [];
376 foreach ($this->getVisibleRoles() as $role_data) {
377 $roles[$role_data['obj_id']] = [
378 'blocked' => $role_data['blocked'],
379 'protected_allowed' => $this->review->isAssignable($role_data['obj_id'], $this->getRefId()),
380 'protected_status' => $this->review->isProtected($role_data['parent'], $role_data['obj_id']),
381 'isLocal' => ($this->getRefId() == $role_data['parent']) && $role_data['assign'] == 'y'
382 ];
383 }
384 $perms[$counter]['roles'] = $roles;
385 $perms[$counter]['show_protected_row'] = 1;
386
387 $counter++;
388 }
389 // Block role
391 $perms[$counter++]['show_block_row'] = 1;
392 }
393
395 $perms[$counter++]['show_start_info'] = true;
396 }
397
398 // no creation permissions
399 $no_creation_operations = [];
400 foreach ($this->review->getOperationsByTypeAndClass($this->getObjType(), 'object') as $operation) {
401 $this->addActiveOperation($operation);
402 $no_creation_operations[] = $operation;
403
404 $roles = [];
405 foreach ($this->getVisibleRoles() as $role_data) {
406 $roles[$role_data['obj_id']] =
407 [
408 'blocked' => $role_data['blocked'],
409 'protected' => $role_data['protected'],
410 'permission_set' => in_array($operation, (array) $operations[$role_data['obj_id']]),
411 'isLocal' => ($this->getRefId() == $role_data['parent']) && $role_data['assign'] == 'y'
412 ];
413 }
414
415 $op = $this->review->getOperation($operation);
416
417 $perms[$counter]['roles'] = $roles;
418 $perms[$counter]['perm'] = $op;
419 $counter++;
420 }
421
422 /*
423 * Select all
424 */
425 if ($no_creation_operations !== []) {
426 $perms[$counter]['show_select_all'] = 1;
427 $perms[$counter]['ops'] = $no_creation_operations;
428 $perms[$counter]['subtype'] = 'nocreation';
429 $counter++;
430 }
431
432 if ($this->objDefinition->isContainer($this->getObjType())) {
433 $perms[$counter++]['show_create_info'] = true;
434 }
435
436 // Get creatable objects
437 $objects = $this->objDefinition->getCreatableSubObjects($this->getObjType());
438 $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
439 $creation_operations = [];
440 foreach ($objects as $type => $info) {
441 $ops_id = $ops_ids[$type] ?? null;
442
443 if (!$ops_id) {
444 continue;
445 }
446
447 $this->addActiveOperation($ops_id);
448 $creation_operations[] = $ops_id;
449
450 $roles = [];
451 foreach ($this->getVisibleRoles() as $role_data) {
452 $roles[$role_data['obj_id']] =
453 [
454 'blocked' => $role_data['blocked'],
455 'protected' => $role_data['protected'],
456 'permission_set' => in_array($ops_id, (array) $operations[$role_data['obj_id']]),
457 'isLocal' => ($this->getRefId() == $role_data['parent']) && $role_data['assign'] == 'y'
458
459 ];
460 }
461
462 $op = $this->review->getOperation($ops_id);
463
464 $perms[$counter]['roles'] = $roles;
465 $perms[$counter]['perm'] = $op;
466 $counter++;
467 }
468
469 // Select all
470 if ($creation_operations !== []) {
471 $perms[$counter]['show_select_all'] = 1;
472 $perms[$counter]['ops'] = $creation_operations;
473 $perms[$counter]['subtype'] = 'creation';
474 $counter++;
475 }
476
477 $this->setData($perms);
478 }
479
480 protected function initColumns(): void
481 {
482 global $DIC;
483
484 $roles = $this->review->getParentRoleIds($this->getRefId());
485 $roles = $this->getParentObject()->applyRoleFilter(
486 $roles,
487 (int) $this->getFilterItemByPostVar('role')->getValue()
488 );
489
490 $possible_roles = [];
491 foreach ($roles as $role) {
492 if ($this->review->isBlockedInUpperContext((int) $role['obj_id'], $this->getRefId())) {
493 ilLoggerFactory::getLogger('ac')->debug('Ignoring blocked role: ' . $role['obj_id']);
494 continue;
495 }
496 $possible_roles[] = $role;
497 }
498
499 if ($possible_roles !== []) {
500 $column_width = 100 / count($possible_roles);
501 $column_width .= '%';
502 } else {
503 }
504
505 $all_roles = [];
506 foreach ($possible_roles as $role) {
507 if ($role['obj_id'] == SYSTEM_ROLE_ID) {
508 continue;
509 }
510 $role['obj_id'] = (int) $role['obj_id'];
511 $role['blocked'] = (bool) $this->review->isBlockedAtPosition($role['obj_id'], $this->getRefId());
512 $role['role_type'] = $this->review->isGlobalRole($role['obj_id']) ? 'global' : 'local';
513
514 // TODO check filter
515 $this->addColumn(
516 $this->createTitle($role),
517 (string) $role['obj_id'],
518 '',
519 false,
520 '',
521 $this->createTooltip($role)
522 );
523 $all_roles[] = $role;
524 }
525
526 $this->setVisibleRoles($all_roles);
527 }
528
532 protected function createTooltip(array $role): string
533 {
534 $protected_status = $this->review->isProtected($role['parent'], $role['obj_id']) ? 'protected_' : '';
535 if ($role['role_type'] == 'global') {
536 $tp = $this->lng->txt('perm_' . $protected_status . 'global_role');
537 } else {
538 $tp = $this->lng->txt('perm_' . $protected_status . 'local_role');
539 }
540
541 $inheritance_seperator = ': ';
542
543 // Show create at info
544 if (
545 $role['assign'] == 'y' && $role['role_type'] != 'global' || $role['assign'] == 'n' && $role['role_type'] != 'global'
546 ) {
547 $tp .= ': ';
548
549 $obj = $this->review->getObjectOfRole($role['obj_id']);
550 if ($obj) {
551 $type = ilObject::_lookupType($this->getRefId(), true);
552 if ($this->objDefinition->isPlugin($type)) {
553 $type_text = ilObjectPlugin::lookupTxtById($type, 'obj_' . $type);
554 } else {
555 $type_text = $this->lng->txt('obj_' . ilObject::_lookupType($obj));
556 }
557
558 $tp .= sprintf(
559 $this->lng->txt('perm_role_path_info_created'),
560 $type_text,
562 );
563 $inheritance_seperator = ', ';
564 }
565 }
566
567 $path_hierarchy = $this->review->getObjectsWithStopedInheritance(
568 $role['obj_id'],
569 $this->tree->getPathId($this->getRefId())
570 );
571
572 $reduced_path_hierarchy = array_diff(
573 $path_hierarchy,
574 [
575 $this->getRefId(),
576 $this->review->getObjectReferenceOfRole($role['obj_id'])
577 ]
578 );
579
580 // Inheritance
581 if ($role['assign'] == 'n' && count($reduced_path_hierarchy)) {
582 $tp .= $inheritance_seperator;
583
584 $parent = end($reduced_path_hierarchy);
587 $tp .= sprintf(
588 $this->lng->txt('perm_role_path_info_inheritance'),
589 $this->lng->txt('obj_' . $p_type),
590 $p_title
591 );
592 }
593
594 return $tp;
595 }
596
600 protected function createTitle(array $role): string
601 {
602 $role_title = ilObjRole::_getTranslation($role['title']);
603
604 // No local policies
605 if ($role['parent'] != $this->getRefId()) {
606 return $role_title;
607 }
608
609 $type = ilObject::_lookupType($this->getRefId(), true);
610 if ($this->objDefinition->isPlugin($type)) {
611 if (preg_match("/^il_./", $role["title"])) {
612 $role_title = ilObjectPlugin::lookupTxtById($type, ilObjRole::_removeObjectId($role["title"]));
613 }
614 }
615
616 if ($role['blocked']) {
617 return $role_title;
618 }
619 $this->ctrl->setParameterByClass('ilobjrolegui', 'obj_id', $role['obj_id']);
620
621 return '<a class="tblheader" href="' . $this->ctrl->getLinkTargetByClass(
622 'ilobjrolegui',
623 ''
624 ) . '" >' . $role_title . '</a>';
625 }
626}
static getLogger(string $a_component_id)
Get component logger.
static _removeObjectId(string $a_role_title)
static _getTranslation(string $a_role_title)
parses the objects.xml it handles the xml-description of all ilias objects
static langExitsById(string $pluginId, string $langVar)
Is searched lang var available in plugin lang files.
static lookupTxtById(string $plugin_id, string $lang_var)
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(ilPermissionGUI $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
createTooltip(array $role)
Create a linked title for roles with local policy.
createTitle(array $role)
Create (linked) title.
addActiveOperation(int $a_ops_id)
Add active operation.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static hasContainerCommands(string $a_type)
class ilRbacReview Contains Review functions of core Rbac.
static lookupCreateOperationIds(array $a_type_arr)
Lookup operation ids.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
getFormName()
get the name of the parent form
getFilterItemByPostVar(string $a_post_var)
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setDisableFilterHiding(bool $a_val=true)
setNoEntriesText(string $a_text)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
disable(string $a_module_name)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
checkForParentType(int $a_ref_id, string $a_type, bool $a_exclude_source_check=false)
Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentTyp...
const SYSTEM_ROLE_ID
Definition: constants.php:29
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
global $DIC
Definition: shib_login.php:26
$counter