|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Morris Jobke <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @license GNU AGPL version 3 or any later version |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
10
|
|
|
* License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\FilesAccessControl\AppInfo; |
|
23
|
|
|
|
|
24
|
|
|
use OC; |
|
25
|
|
|
use OC\Files\Filesystem; |
|
26
|
|
|
use OCA\Files_Sharing\SharedStorage; |
|
27
|
|
|
use OCA\FilesAccessControl\Listener\FlowRegisterOperationListener; |
|
28
|
|
|
use OCA\FilesAccessControl\Operation; |
|
29
|
|
|
use OCA\FilesAccessControl\StorageWrapper; |
|
30
|
|
|
use OCP\AppFramework\App; |
|
31
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
32
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
33
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
34
|
|
|
use OCP\Files\Storage\IStorage; |
|
35
|
|
|
use OCP\Util; |
|
36
|
|
|
use OCP\WorkflowEngine\Events\RegisterOperationsEvent; |
|
37
|
|
|
|
|
38
|
|
|
class Application extends App implements IBootstrap { |
|
39
|
|
|
|
|
40
|
|
|
public function __construct() { |
|
41
|
|
|
parent::__construct('files_accesscontrol'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @internal |
|
46
|
|
|
*/ |
|
47
|
|
|
public function addStorageWrapper() { |
|
48
|
|
|
// Needs to be added as the first layer |
|
49
|
|
|
Filesystem::addStorageWrapper('files_accesscontrol', [$this, 'addStorageWrapperCallback'], -10); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @internal |
|
54
|
|
|
* @param $mountPoint |
|
55
|
|
|
* @param IStorage $storage |
|
56
|
|
|
* @return StorageWrapper|IStorage |
|
57
|
|
|
*/ |
|
58
|
|
|
public function addStorageWrapperCallback($mountPoint, IStorage $storage) { |
|
59
|
|
|
if (!OC::$CLI && !$storage->instanceOfStorage(SharedStorage::class)) { |
|
60
|
|
|
/** @var Operation $operation */ |
|
61
|
|
|
$operation = $this->getContainer()->query(Operation::class); |
|
62
|
|
|
return new StorageWrapper([ |
|
63
|
|
|
'storage' => $storage, |
|
64
|
|
|
'mountPoint' => $mountPoint, |
|
65
|
|
|
'operation' => $operation, |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $storage; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function register(IRegistrationContext $context): void { |
|
73
|
|
|
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); |
|
74
|
|
|
$context->registerEventListener(RegisterOperationsEvent::class, FlowRegisterOperationListener::class); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function boot(IBootContext $context): void { |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|