Completed
Pull Request — master (#31)
by Joas
05:46
created

CacheWrapper::formatCacheEntry()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Joas Schilling <[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;
23
24
use OC\Files\Cache\Wrapper\CacheWrapper as Wrapper;
25
use OCP\Constants;
26
use OCP\Files\Cache\ICache;
27
use OCP\Files\ForbiddenException;
28
29
class CacheWrapper extends Wrapper  {
30
	/** @var Operation */
31
	protected $operation;
32
	/** @var StorageWrapper */
33
	protected $storage;
34
	/** @var int */
35
	protected $mask;
36
37
	/**
38
	 * @param ICache $cache
39
	 * @param StorageWrapper $storage
40
	 * @param Operation $operation
41
	 */
42
	public function __construct(ICache $cache, StorageWrapper $storage, Operation $operation) {
43
		parent::__construct($cache);
44
		$this->storage = $storage;
45
		$this->operation = $operation;
46
47
		$this->mask = Constants::PERMISSION_ALL;
48
		$this->mask &= ~Constants::PERMISSION_READ;
49
		$this->mask &= ~Constants::PERMISSION_CREATE;
50
		$this->mask &= ~Constants::PERMISSION_UPDATE;
51
		$this->mask &= ~Constants::PERMISSION_DELETE;
52
	}
53
54
	const PERMISSION_CREATE = 4;
55
	const PERMISSION_READ = 1;
56
	const PERMISSION_UPDATE = 2;
57
	const PERMISSION_DELETE = 8;
58
59
	protected function formatCacheEntry($entry) {
60
		try {
61
			$this->operation->checkFileAccess($this->storage, $entry['path']);
62
		} catch (ForbiddenException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\ForbiddenException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
63
			$entry['permissions'] &= $this->mask;
64
		}
65
		return $entry;
66
	}
67
}
68