ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
CmdPermission.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23abstract class CmdPermission implements CmdPermissionInterface
24{
25 public function __construct(
26 protected \ilLanguage $lng,
27 protected ?\ilGlobalTemplateInterface $tpl = null,
28 protected ?\ilCtrlInterface $ctrl = null,
29 ) {
30 }
31
32 public function isRequestCommandPermitted(): bool
33 {
34 if (is_null($this->ctrl)) {
35 return false;
36 }
37 if (!$this->isRequestMultiCommand()) {
38 return $this->isCommandPermitted(
39 $this->getRequestCommand(),
40 $this->getRequestNodeId(),
41 (string) $this?->getRequestEntity()->getType(),
42 (string) $this?->getRequestEntity()->getId()
43 );
44 } else {
45 return $this->isCommandPermittedMulti(
46 $this->getRequestCommand(),
47 $this->getRequestNodeId(),
48 (string) $this?->getRequestEntity()->getType(),
49 (array) $this?->getRequestEntity()->getId()
50 );
51 }
52 }
53
54 public function isRequestMultiCommand(): bool
55 {
56 return is_array($this?->getRequestEntity()->getId());
57 }
58
59 public function isTableCommandPermitted(string $cmd, string $entity_id): bool
60 {
61 if (is_null($this->ctrl)) {
62 return false;
63 }
64 return $this->isCommandPermitted(
65 $cmd,
66 $this->getRequestNodeId(),
67 (string) $this?->getRequestEntity()->getType(),
68 $entity_id
69 );
70 }
71
72 public function isCommandPermittedMulti(
73 string $cmd,
74 int $node_id,
75 string $entity,
76 array $entity_ids
77 ): bool {
78 return array_all(
79 $entity_ids,
80 fn($entity_id) => $this->isCommandPermitted($cmd, $node_id, $entity, $entity_id)
81 );
82 }
83
84
85 public function getPermittedCommand(): string
86 {
87 if ($this->isRequestCommandPermitted()) {
88 return $this->getRequestCommand();
89 }
90 return "";
91 }
92
93 public function getRequestCommand(): string
94 {
95 return $this->ctrl->getCmd($this->getDefaultCommand());
96 }
97
98 protected function isClass(string $class): bool
99 {
100 if (is_null($this->ctrl)) {
101 return false;
102 }
103 $cmd_class = $this->ctrl->getCmdClass();
104 return $cmd_class === strtolower($class);
105 }
106
107 public function getDefaultCommand(): string
108 {
109 return "";
110 }
111
112
116 public function checkCommand(string $cmd, int $node_id, string $entity, string $entity_id = ""): void
117 {
118 if (!$this->isCommandPermitted($cmd, $node_id, $entity, $entity_id)) {
119 throw new \ILIAS\Repository\Permission\ilNoCmdPermissionException("No permission to execute command $cmd on $entity $entity_id");
120 }
121 }
122
123 protected function cmdEntity(
124 string $type,
125 string|array $id = ""
126 ): CmdEntity {
127 return new CmdEntity(
128 $type,
129 $id
130 );
131 }
132
133 public function forwardPermitted(
134 object $from_gui,
135 object $to_gui
136 ): mixed {
137 if (is_null($this->ctrl)) {
138 return null;
139 }
140 if ($this->isForwardPermitted(get_class($from_gui), get_class($to_gui))) {
141 return $this->ctrl->forwardCommand($to_gui);
142 }
143 if ($this->access->checkAccess("read", "", ROOT_FOLDER_ID)) {
144 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
145 $this->ctrl->setParameterByClass("ilRepositoryGUI", "ref_id", ROOT_FOLDER_ID);
146 $this->ctrl->redirectByClass("ilRepositoryGUI");
147 }
148 throw new \ilPermissionException($this->lng->txt("permission_denied"));
149 }
150
154 public function classImplementsMethodDirectly(string $className, string $method): bool
155 {
156 try {
157 $class = new \ReflectionClass($className);
158 } catch (\Exception $e) {
159 return false;
160 }
161
162 return $class->hasMethod($method)
163 && $class->getMethod($method)->getDeclaringClass()->getName() === $class->getName();
164 }
165}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
checkCommand(string $cmd, int $node_id, string $entity, string $entity_id="")
__construct(protected \ilLanguage $lng, protected ?\ilGlobalTemplateInterface $tpl=null, protected ?\ilCtrlInterface $ctrl=null,)
isCommandPermittedMulti(string $cmd, int $node_id, string $entity, array $entity_ids)
classImplementsMethodDirectly(string $className, string $method)
For intermediate solutions that don't implement the concept for all subclasses yet.
forwardPermitted(object $from_gui, object $to_gui)
cmdEntity(string $type, string|array $id="")
isTableCommandPermitted(string $cmd, string $entity_id)
language handling
const ROOT_FOLDER_ID
Definition: constants.php:32
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isCommandPermitted(string $cmd, int $node_id, string $entity, string $entity_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly ilGlobalTemplateInterface $tpl
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))