ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
BlogCmdPermission.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Blog\Access\BlogAccess;
33
35{
36 protected const BLOG = "blog";
37 protected const POSTING = "posting";
38 protected const BLOG_ASSIGNMENT = "blog_assignment";
39 protected \ilAccessHandler|\ilWorkspaceAccessHandler $access;
40
41 public function __construct(
42 protected \ilLanguage $lng,
43 protected PermissionManager $perm_manager,
45 protected ?\ilCtrlInterface $ctrl = null,
46 protected ?StandardGUIRequest $request = null,
47 protected ?BlogExercise $blog_exercise = null
48 ) {
50 $this->access = $perm_manager->getAccessHandler();
51 }
52
53 public function postingsBelongToBlog(array $posting_ids): bool
54 {
55 foreach ($posting_ids as $posting_id) {
56 if (!$this->perm_manager->postingIdMatches($posting_id)) {
57 return false;
58 }
59 }
60 return true;
61 }
62
63 public function assignmentBelongsToBlog(int $assignment_id): bool
64 {
65 if ($this->blog_exercise === null) {
66 return false;
67 }
68
69 foreach ($this->blog_exercise->getAssignmentsOfBlog() as $assignment) {
70 if ($assignment["ass_id"] === $assignment_id) {
71 return true;
72 }
73 }
74 return false;
75 }
76
77 public function isCommandPermitted(
78 string $cmd, // derived or from table
79 int $node_id,
80 string $entity,
81 string $entity_id = ""
82 ): bool {
83 switch ($entity) {
84 case self::BLOG:
85 return $this->hasBlogCmdPerm($cmd, $node_id);
86 case self::POSTING:
87 return $this->hasPostingCmdPerm($cmd, $node_id, (int) $entity_id);
89 return $this->hasBlogAssignmentCmdPerm($cmd, $node_id, (int) $entity_id);
90 }
91 return false;
92 }
93
94 protected function hasBlogCmdPerm(string $cmd, int $node_id): bool
95 {
96 // write permission
97 if (in_array($cmd, [
98 "edit",
99 "createExportFileWithComments",
100 "createExportFile",
101 "export",
102 "contributors",
103 "addUserFromAutoComplete",
104 "addContributor",
105 "confirmRemoveContributor",
106 "removeContributor",
107 "setContentStyleSheet",
108 "exportWithComments"
109 ])) {
110 return $this->access->checkAccess("write", "", $node_id);
111 }
112
113 if (in_array($cmd, [
114 "createPosting",
115 ])) {
116 return $this->perm_manager->mayContribute();
117 }
118
119 // read permission
120 if (in_array($cmd, [
121 "render", "preview", "addToDesk", "removeFromDesk", "renderFullscreen",
122 "setNotification", "printViewSelection", "printPostings"
123 ])) {
124 return $this->access->checkAccess("read", "", $node_id);
125 }
126
127 // visible permission
128 if (in_array($cmd, [
129 "infoScreen"
130 ])) {
131 return $this->access->checkAccess("visible", "", $node_id);
132 }
133
134
135 return false;
136 }
137
138 protected function hasPostingCmdPerm(string $cmd, int $node_id, int $posting_id): bool
139 {
140 if (in_array($cmd, ["printViewSelection", "printPostings"])) {
141 return $this->access->checkAccess("read", "", $node_id) &&
142 $this->perm_manager->postingIdMatches($posting_id);
143 }
144
145 // redact or write permission
146 if (in_array($cmd, [
147 "approve",
148 "deactivateAdmin"
149 ])) {
150 return $this->perm_manager->canApprove($posting_id);
151 }
152
153 return false;
154 }
155
156 protected function hasBlogAssignmentCmdPerm(string $cmd, int $node_id, int $assignment_id): bool
157 {
158 if (in_array($cmd, ["downloadExcAssFile", "downloadExcSubFile", "finalize"])) {
159 return $this->access->checkAccess("read", "", $node_id) &&
160 $this->assignmentBelongsToBlog($assignment_id);
161 }
162
163 return false;
164 }
165
166 public function getDefaultCommand(): string
167 {
168 if ($this->isClass(\ilObjBlogGUI::class)) {
169 return "render";
170 }
171 return "";
172 }
173
174 public function getRequestEntity(): ?CmdEntity
175 {
176 if ($this->isClass(\ilObjBlogGUI::class) || $this->isClass(EditingGUI::class)) {
177
178 if (in_array($this->ctrl->getCmd(), ["approve", "deactivateAdmin"])) {
179 $posting_id = $this->request->getApId();
180 return $this->cmdEntity(
181 self::POSTING,
182 (string) $posting_id
183 );
184 }
185 if (in_array($this->ctrl->getCmd(), ["printViewSelection", "printPostings"])) {
186 $posting_ids = $this->request->getObjIds();
187 if ($posting_ids !== []) {
188 return $this->cmdEntity(self::POSTING, $posting_ids);
189 }
190 }
191 return $this->cmdEntity(
192 self::BLOG
193 );
194 }
195 if ($this->isClass(\ilBlogExerciseGUI::class)) {
196 return $this->cmdEntity(
197 self::BLOG_ASSIGNMENT,
198 (string) $this->request->getAssId()
199 );
200 }
201 return null;
202 }
203
204 public function getRequestNodeId(): int
205 {
206 if ($this->access instanceof \ilWorkspaceAccessHandler) {
207 return $this->request->getWspId();
208 }
209 return $this->request->getRefId();
210 }
211
212 public function isForwardPermitted(
213 string $from_class,
214 string $to_class
215 ): bool {
216 $node_id = $this->getRequestNodeId();
217 $posting_id = $this->request->getBlogPage();
218 if ($from_class === \ilObjBlogGUI::class) {
219
220 // visible or read
221 if ($to_class === \ilCommonActionDispatcherGUI::class) {
222 return $this->access->checkAccess("visible", "", $node_id) ||
223 $this->access->checkAccess("read", "", $node_id);
224 }
225
226 // edit permission
227 if ($to_class === \ilPermissionGUI::class) {
228 return $this->access->checkAccess("edit_permission", "", $node_id);
229 }
230
231 if ($to_class === EditingGUI::class && in_array($this->ctrl->getCmd(), [
232 "approve",
233 "deactivateAdmin",
234 "printViewSelection",
235 "printPostings"
236 ])) {
237 return $this->isRequestCommandPermitted();
238 }
239
240 // read posting permission
241 if ($to_class === \ilBlogPostingGUI::class) {
242 return $this->perm_manager->canReadPosting($posting_id);
243 }
244
245 // write permission
246 if (in_array($to_class, [
247 \ilExportGUI::class,
248 \ilRepositorySearchGUI::class,
249 \ilObjectContentStyleSettingsGUI::class,
250 \ilObjNotificationSettingsGUI::class,
251 \ilObjectMetaDataGUI::class,
252 SettingsGUI::class,
253 \ILIAS\Blog\Settings\BlockSettingsGUI::class,
254 \ILIAS\Blog\Editing\EditingGUI::class,
255 \ILIAS\Blog\Export\ExportGUI::class,
256 ContributorGUI::class,
257 ])) {
258 return $this->access->checkAccess("write", "", $node_id);
259 }
260
261 // read permission
262 // note on ilObjectCopyGUI: This class performs the copy permission checks and
263 // can act on multiple source ids
264 if (in_array($to_class, [
265 \ilObjectCopyGUI::class,
266 \ILIAS\Blog\Presentation\PresentationGUI::class
267 ])) {
268 return $this->access->checkAccess("read", "", $node_id);
269 }
270
271 if ($to_class === \ilBlogExerciseGUI::class) {
272 $assignment_id = $this->request?->getAssId() ?? 0;
273 return $assignment_id === 0
274 ? $this->access->checkAccess("read", "", $node_id)
275 : $this->isRequestCommandPermitted();
276 }
277
278 // visible
279 if ($to_class === \ilInfoScreenGUI::class) {
280 return $this->access->checkAccess("visible", "", $node_id);
281 }
282 }
283 return false;
284 }
285
286}
@ilCtrl_Calls ILIAS\Blog\Contributor\ContributorGUI: ilRepositorySearchGUI
@ilCtrl_Calls ILIAS\Blog\Editing\EditingGUI: ilRepositorySearchGUI, ilBlogPostingGUI
Definition: EditingGUI.php:37
__construct(protected \ilLanguage $lng, protected PermissionManager $perm_manager, ?\ilGlobalTemplateInterface $tpl=null, protected ?\ilCtrlInterface $ctrl=null, protected ?StandardGUIRequest $request=null, protected ?BlogExercise $blog_exercise=null)
isCommandPermitted(string $cmd, int $node_id, string $entity, string $entity_id="")
hasPostingCmdPerm(string $cmd, int $node_id, int $posting_id)
hasBlogAssignmentCmdPerm(string $cmd, int $node_id, int $assignment_id)
isForwardPermitted(string $from_class, string $to_class)
ilAccessHandler ilWorkspaceAccessHandler $access
hasBlogCmdPerm(string $cmd, int $node_id)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
Definition: ltiauth.php:39
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
readonly ilGlobalTemplateInterface $tpl
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26