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