ILIAS  release_8 Revision v8.23
class.ilAccessRBACStandardOperationsAddedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 use ILIAS\Setup;
24 
25 class ilAccessRbacStandardOperationsAddedObjective implements Setup\Objective
26 {
27  protected const RBAC_OP_EDIT_PERMISSIONS = 1;
28  protected const RBAC_OP_VISIBLE = 2;
29  protected const RBAC_OP_READ = 3;
30  protected const RBAC_OP_WRITE = 4;
31  protected const RBAC_OP_DELETE = 6;
32  protected const RBAC_OP_COPY = 99;
33 
34  protected array $valid_operations = [
35  self::RBAC_OP_EDIT_PERMISSIONS,
36  self::RBAC_OP_VISIBLE,
37  self::RBAC_OP_READ,
38  self::RBAC_OP_WRITE,
39  self::RBAC_OP_DELETE,
40  self::RBAC_OP_COPY
41  ];
42 
43  protected string $type;
44 
45  public function __construct(string $type)
46  {
47  $this->type = $type;
48  }
49 
50  public function getHash(): string
51  {
52  return hash("sha256", self::class . "::" . $this->type);
53  }
54 
55  public function getLabel(): string
56  {
57  $operations = implode(",", $this->valid_operations);
58  return "Add standard rbac operations (type=$this->type;operations=$operations)";
59  }
60 
61  public function isNotable(): bool
62  {
63  return true;
64  }
65 
66  public function getPreconditions(Environment $environment): array
67  {
68  return [
70  ];
71  }
72 
73  public function achieve(Environment $environment): Environment
74  {
75  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
76  $type_id = ilObject::_getObjectTypeIdByTitle($this->type, $db);
77 
78  foreach ($this->valid_operations as $ops_id) {
79  if ($ops_id == self::RBAC_OP_COPY) {
80  $ops_id = ilRbacReview::_getCustomRBACOperationId("copy", $db);
81  }
82 
83  if (ilRbacReview::_isRBACOperation($type_id, $ops_id, $db)) {
84  continue;
85  }
86 
87  $values = [
88  "typ_id" => ["integer", $type_id],
89  "ops_id" => ["integer", $ops_id]
90  ];
91 
92  $db->insert("rbac_ta", $values);
93  }
94 
95  return $environment;
96  }
97 
98  public function isApplicable(Environment $environment): bool
99  {
100  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
101  $type_id = ilObject::_getObjectTypeIdByTitle($this->type, $db);
102 
103  foreach ($this->valid_operations as $ops_id) {
104  if ($ops_id == self::RBAC_OP_COPY) {
105  $ops_id = ilRbacReview::_getCustomRBACOperationId("copy", $db);
106  }
107 
108  if (!ilRbacReview::_isRBACOperation($type_id, $ops_id, $db)) {
109  return true;
110  }
111  }
112  return false;
113  }
114 }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
static _getCustomRBACOperationId(string $operation, \ilDBInterface $ilDB=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
static _isRBACOperation(int $type_id, int $ops_id, \ilDBInterface $ilDB=null)
static _getObjectTypeIdByTitle(string $type, \ilDBInterface $ilDB=null)