-
Notifications
You must be signed in to change notification settings - Fork 451
/
PageResponse.php
288 lines (252 loc) · 9.23 KB
/
PageResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
namespace Concrete\Core\Permission\Response;
use Block;
use Concrete\Core\Area\Area;
use Concrete\Core\Cache\Level\RequestCache;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Access\Entity\Entity as PermissionAccessEntity;
use Concrete\Core\Permission\Assignment\PageTimedAssignment as PageContentPermissionTimedAssignment;
use Concrete\Core\Permission\Duration as PermissionDuration;
use Concrete\Core\Permission\Key\AreaKey as AreaPermissionKey;
use Concrete\Core\Permission\Key\BlockKey as BlockPermissionKey;
use Concrete\Core\Permission\Key\Key;
use Concrete\Core\Permission\Key\PageKey as PagePermissionKey;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\User\User;
use Config;
use Loader;
use Permissions;
use Session;
use TaskPermission;
class PageResponse extends Response
{
// legacy support
public function canWrite()
{
return $this->validate('edit_page_contents');
}
public function canReadVersions()
{
return $this->validate('view_page_versions');
}
public function canRead()
{
return $this->canViewPage();
}
public function canAddSubContent()
{
return $this->validate('add_subpage');
}
public function canViewPageInSitemap()
{
if (Config::get('concrete.permissions.model') != 'simple') {
$pk = $this->category->getPermissionKeyByHandle('view_page_in_sitemap');
$pk->setPermissionObject($this->object);
return $pk->validate();
}
return $this->canViewPage();
}
public function canViewPage()
{
return $this->validate('view_page');
}
public function canAddSubpages()
{
return $this->validate('add_subpage');
}
public function canDeleteCollection()
{
return $this->canDeletePage();
}
public function canEditPageType()
{
return $this->validate('edit_page_page_type');
}
public function canApproveCollection()
{
return $this->validate('approve_page_versions');
}
public function canAdminPage()
{
return $this->validate('edit_page_permissions');
}
public function canAdmin()
{
return $this->validate('edit_page_permissions');
}
public function canAddExternalLink()
{
$pk = $this->category->getPermissionKeyByHandle('add_subpage');
$pk->setPermissionObject($this->object);
return $pk->canAddExternalLink();
}
public function canAddSubCollection($ct)
{
$pk = $this->category->getPermissionKeyByHandle('add_subpage');
$pk->setPermissionObject($this->object);
return $pk->validate($ct);
}
public function canAddBlockType($bt)
{
// Check can add the block to any area on the site.
$key = Key::getByHandle('add_block');
if (!$key || !$key->validate($bt)) {
return false;
}
// Check can add blocks to this area.
$list = Area::getListOnPage($this->object);
foreach ($list as $la) {
$lap = new Permissions($la);
if ($lap->canAddBlockToArea($bt)) {
return true;
}
}
return false;
}
public function canEditPageProperties($obj = false)
{
$pk = $this->category->getPermissionKeyByHandle('edit_page_properties');
$pk->setPermissionObject($this->object);
return $pk->validate($obj);
}
public function canDeletePage()
{
return $this->validate('delete_page');
}
// end legacy
// convenience function
public function canViewToolbar()
{
$app = Application::getFacadeApplication();
/** @var RequestCache $cache */
$cache = $app->make('cache/request');
$identifier = 'permission/response/canviewtoolbar';
$cacheItem = $cache->getItem($identifier);
if ($cacheItem->isHit()) {
return $cacheItem->get();
}
$u = $app->make(User::class);
if (!$u->isRegistered()) {
$cache->save($cacheItem->set(false));
return false;
}
if ($u->isSuperUser()) {
$cache->save($cacheItem->set(true));
return true;
}
$sh = $app->make('helper/concrete/dashboard/sitemap');
if ($sh->canViewSitemapPanel()) {
$cache->save($cacheItem->set(true));
return true;
}
$dh = $app->make('helper/concrete/dashboard');
if ($dh->canRead() ||
$this->canViewPageVersions() ||
$this->canPreviewPageAsUser() ||
$this->canEditPageSpeedSettings() ||
$this->canEditPageProperties() ||
$this->canEditPageContents() ||
$this->canAddSubpage() ||
$this->canDeletePage() ||
$this->canApprovePageVersions() ||
$this->canEditPagePermissions() ||
$this->canMoveOrCopyPage()
) {
$cache->save($cacheItem->set(true));
return true;
}
$c = Page::getCurrentPage();
if ($c && $c->getCollectionPath() == STACKS_LISTING_PAGE_PATH) {
$cache->save($cacheItem->set(true));
return true;
}
$cache->save($cacheItem->set(false));
return false;
}
public function testForErrors()
{
if ($this->object->isMasterCollection()) {
$canEditMaster = TaskPermission::getByHandle('access_page_defaults')->can();
if (!($canEditMaster && Session::get('mcEditID') == $this->object->getCollectionID())) {
return COLLECTION_FORBIDDEN;
}
} else {
if ((!$this->canViewPage()) && (!$this->object->getCollectionPointerExternalLink() != '')) {
return COLLECTION_FORBIDDEN;
}
}
return parent::testForErrors();
}
public function getAllTimedAssignmentsForPage()
{
return $this->getAllAssignmentsForPage();
}
public function getAllAssignmentsForPage()
{
$db = Loader::db();
$assignments = [];
$r = $db->Execute(
'select peID, pkID, pdID from PagePermissionAssignments ppa inner join PermissionAccessList pal on ppa.paID = pal.paID where cID = ?',
[$this->object->getCollectionID()]
);
while ($row = $r->FetchRow()) {
$pk = PagePermissionKey::getByID($row['pkID']);
$pae = PermissionAccessEntity::getByID($row['peID']);
$pd = PermissionDuration::getByID($row['pdID']);
$ppc = new PageContentPermissionTimedAssignment();
$ppc->setDurationObject($pd);
$ppc->setAccessEntityObject($pae);
$ppc->setPermissionKeyObject($pk);
$assignments[] = $ppc;
}
$r = $db->Execute(
'select arHandle from Areas where cID = ? and arOverrideCollectionPermissions = 1',
[$this->object->getCollectionID()]
);
while ($row = $r->FetchRow()) {
$r2 = $db->Execute(
'select peID, pdID, pkID from AreaPermissionAssignments apa inner join PermissionAccessList pal on apa.paID = pal.paID where cID = ? and arHandle = ?',
[$this->object->getCollectionID(), $row['arHandle']]
);
while ($row2 = $r2->FetchRow()) {
$pk = AreaPermissionKey::getByID($row2['pkID']);
$pae = PermissionAccessEntity::getByID($row2['peID']);
$area = Area::get($this->getPermissionObject(), $row['arHandle']);
$pk->setPermissionObject($area);
$pd = PermissionDuration::getByID($row2['pdID']);
$ppc = new PageContentPermissionTimedAssignment();
$ppc->setDurationObject($pd);
$ppc->setAccessEntityObject($pae);
$ppc->setPermissionKeyObject($pk);
$assignments[] = $ppc;
}
}
$r = $db->Execute(
'select peID, cvb.cvID, cvb.bID, pdID, pkID from BlockPermissionAssignments bpa
inner join PermissionAccessList pal on bpa.paID = pal.paID inner join CollectionVersionBlocks cvb on cvb.cID = bpa.cID and cvb.cvID = bpa.cvID and cvb.bID = bpa.bID
where cvb.cID = ? and cvb.cvID = ? and cvb.cbOverrideAreaPermissions = 1',
[$this->object->getCollectionID(), $this->object->getVersionID()]
);
while ($row = $r->FetchRow()) {
$pk = BlockPermissionKey::getByID($row['pkID']);
$pae = PermissionAccessEntity::getByID($row['peID']);
$arHandle = $db->GetOne(
'select arHandle from CollectionVersionBlocks where bID = ? and cvID = ? and cID = ?',
[
$row['bID'],
$row['cvID'],
$this->object->getCollectionID(),
]
);
$b = Block::getByID($row['bID'], $this->object, $arHandle);
$pk->setPermissionObject($b);
$pd = PermissionDuration::getByID($row['pdID']);
$ppc = new PageContentPermissionTimedAssignment();
$ppc->setDurationObject($pd);
$ppc->setAccessEntityObject($pae);
$ppc->setPermissionKeyObject($pk);
$assignments[] = $ppc;
}
return $assignments;
}
}