ILIAS  release_8 Revision v8.24
class.ilAccessRBACStandardOperationsAddedObjective.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22use ILIAS\Setup;
24
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 = [
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}
static _getObjectTypeIdByTitle(string $type, \ilDBInterface $ilDB=null)
static _isRBACOperation(int $type_id, int $ops_id, \ilDBInterface $ilDB=null)
static _getCustomRBACOperationId(string $operation, \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...