ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
PermissionManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Permission;
22
25
27{
28 protected \ILIAS\Blog\Posting\PostingManager $posting_manager;
29 protected \ilWorkspaceTree $ws_tree;
30 protected int $owner;
31 protected int $id_type;
32 protected \ilWorkspaceAccessHandler|\ilAccessHandler $access;
33 protected ?int $node_id;
34 protected int $user_id;
36
37 public function __construct(
40 ?int $node_id,
41 int $id_type,
42 int $user_id,
43 int $owner
44 ) {
45 $this->access = $access_handler;
46 $this->node_id = $node_id;
47 $this->id_type = $id_type;
48 $this->user_id = $user_id;
49 $this->owner = $owner;
50 $this->ws_tree = new \ilWorkspaceTree($this->owner);
51 $this->posting_manager = $domain->posting();
52 $this->page_manager = $domain->pageManager();
53 }
54
55 public function canWrite(): bool
56 {
57 return $this->access->checkAccess('write', '', $this->node_id);
58 }
59
60 public function canRead(): bool
61 {
62 return $this->access->checkAccess('read', '', $this->node_id);
63 }
64
65 public function mayContribute(): bool
66 {
67 if ($this->id_type === \ilObject2GUI::WORKSPACE_NODE_ID) {
68 return $this->checkPermissionBool("write");
69 }
70
71 return ($this->checkPermissionBool("redact") ||
72 $this->checkPermissionBool("contribute"));
73 }
74
75 public function mayEditPosting(
76 int $a_posting_id,
77 ?int $a_author_id = null
78 ): bool {
79 // single author blog (owner) in personal workspace
80 if ($this->id_type === \ilObject2GUI::WORKSPACE_NODE_ID) {
81 return $this->checkPermissionBool("write");
82 }
83
84 // repository blogs
85
86 // redact allows to edit all postings
87 if ($this->checkPermissionBool("redact")) {
88 return true;
89 }
90
91 // contribute gives access to own postings
92 if ($this->checkPermissionBool("contribute")) {
93 // check owner of posting
94 if (!$a_author_id) {
95 $post = new \ilBlogPosting($a_posting_id);
96 $a_author_id = $post->getAuthor();
97 }
98 return $this->user_id === $a_author_id;
99 }
100 return false;
101 }
102
103 protected function checkPermissionBool(string $perm): bool
104 {
105 if (!is_null($this->node_id)) {
106 return $this->access->checkAccess($perm, "", $this->node_id);
107 }
108 if ($this->owner === $this->user_id) {
109 return true;
110 }
111 return false;
112 }
113
114
118 public function canManage(): bool
119 {
120 return ($this->checkPermissionBool("redact") ||
121 $this->checkPermissionBool("write"));
122 }
123
124 public function canReadPosting(int $posting_id): bool
125 {
126 return (
127 $this->postingIdMatches($posting_id) &&
128 $this->checkPermissionBool("read") &&
129 ($this->mayContribute() ||
130 $this->page_manager->lookupActive($posting_id, "blp")));
131 }
132
133 public function canApprove(int $posting_id): bool
134 {
135 if (!$this->postingIdMatches($posting_id)) {
136 return false;
137 }
138 return ($this->checkPermissionBool("redact") ||
139 $this->checkPermissionBool("write")
140 );
141 }
142
143 public function isActive(int $posting_id): bool
144 {
145 return $this->page_manager->lookupActive($posting_id, "blp");
146 }
147
148 public function postingIdMatches(int $posting_id): bool
149 {
150 if ($this->id_type === \ilObject2GUI::WORKSPACE_NODE_ID) {
151 $obj_id = $this->ws_tree->lookupObjectId($this->node_id);
152 } else {
153 $obj_id = \ilObject::_lookupObjId($this->node_id);
154 }
155 return $this->posting_manager->lookupBlogId($posting_id) === $obj_id;
156 }
157
159 {
160 return $this->access;
161 }
162
163}
ILIAS Blog Posting PostingManager $posting_manager
ilWorkspaceAccessHandler ilAccessHandler $access
__construct(InternalDomainService $domain, \ilWorkspaceAccessHandler|\ilAccessHandler $access_handler, ?int $node_id, int $id_type, int $user_id, int $owner)
mayEditPosting(int $a_posting_id, ?int $a_author_id=null)
canManage()
Check if user has admin access (approve, may edit & deactivate all postings)
New implementation of ilObjectGUI.
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Combines all available interfaces which can be called via global $ilAccess.
if(!file_exists('../ilias.ini.php'))