/
file.php
88 lines (75 loc) · 2.83 KB
/
file.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
<?php
namespace Concrete\Controller\Permissions\Categories\TaskHandlers;
use Concrete\Core\Entity\File\File as ConcreteFile;
use Concrete\Core\Error\UserMessageException;
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\Permission\Access\Access;
use Concrete\Core\Permission\Category\ObjectTaskHandler;
use Concrete\Core\Permission\Checker;
use Concrete\Core\Permission\Key\Key;
use Concrete\Core\Permission\ObjectInterface;
use Concrete\Core\Workflow\Workflow;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
defined('C5_EXECUTE') or die('Access Denied.');
class File extends ObjectTaskHandler
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\Category\ObjectTaskHandler::getPermissionObject()
*/
protected function getPermissionObject(array $options): ObjectInterface
{
$fileID = $options['fID'] ?? null;
$file = $this->app->make(EntityManagerInterface::class)->find(ConcreteFile::class, $fileID);
if ($file === null) {
throw new UserMessageException(t('File not received'));
}
$fp = new Checker($file);
if (!$fp->canEditFilePermissions()) {
throw new UserMessageException(t('Access Denied.'));
}
return $file;
}
protected function revertToGlobalFilePermissions(ConcreteFile $file, array $options): ?Response
{
$file->resetPermissions();
return $this->app->make(ResponseFactoryInterface::class)->json(true);
}
protected function overrideGlobalFilePermissions(ConcreteFile $file, array $options): ?Response
{
$file->resetPermissions(1);
return $this->app->make(ResponseFactoryInterface::class)->json(true);
}
protected function savePermissionAssignments(ConcreteFile $file, array $options): ?Response
{
$permissions = Key::getList('file');
foreach ($permissions as $pk) {
$pk->setPermissionObject($file);
$pt = $pk->getPermissionAssignmentObject();
$pt->clearPermissionAssignment();
$paID = $options['pkID'][$pk->getPermissionKeyID()] ?? 0;
if ($paID > 0) {
$pa = Access::getByID($paID, $pk);
if ($pa !== null) {
$pt->assignPermissionAccess($pa);
}
}
}
return $this->app->make(ResponseFactoryInterface::class)->json(true);
}
protected function saveWorkflows(ConcreteFile $file, array $options): ?Response
{
$pk = Key::getByID($options['pkID']);
$pk->setPermissionObject($file);
$pk->clearWorkflows();
foreach (($options['wfID'] ?? []) as $wfID) {
$wf = Workflow::getByID($wfID);
if ($wf !== null) {
$pk->attachWorkflow($wf);
}
}
return null;
}
}