Issues (263)

lib/Middleware/SharingCheckMiddleware.php (6 issues)

Labels
Severity
1
<?php
2
/**
3
 * Nextcloud - Gallery
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Olivier Paroz <[email protected]>
10
 *
11
 * @copyright Lukas Reschke 2017
12
 * @copyright Olivier Paroz 2017
13
 */
14
15
namespace OCA\Gallery\Middleware;
16
17
use OCP\IConfig;
0 ignored issues
show
The type OCP\IConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use OCP\IRequest;
0 ignored issues
show
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use OCP\ILogger;
0 ignored issues
show
The type OCP\ILogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use OCP\IURLGenerator;
0 ignored issues
show
The type OCP\IURLGenerator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
use OCP\AppFramework\Http;
0 ignored issues
show
The type OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use OCP\AppFramework\Utility\IControllerMethodReflector;
0 ignored issues
show
The type OCP\AppFramework\Utility...ntrollerMethodReflector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
/**
26
 * Checks whether the "sharing check" is enabled
27
 *
28
 * @package OCA\Gallery\SharingCheckMiddleware
29
 */
30
class SharingCheckMiddleware extends CheckMiddleware {
31
32
	/** @var IConfig */
33
	private $config;
34
	/** @var IControllerMethodReflector */
35
	protected $reflector;
36
37
	/***
38
	 * Constructor
39
	 *
40
	 * @param string $appName
41
	 * @param IRequest $request
42
	 * @param IConfig $appConfig
43
	 * @param IControllerMethodReflector $reflector
44
	 * @param IURLGenerator $urlGenerator
45
	 * @param ILogger $logger
46
	 */
47
	public function __construct(
48
		$appName,
49
		IRequest $request,
50
		IConfig $appConfig,
51
		IControllerMethodReflector $reflector,
52
		IURLGenerator $urlGenerator,
53
		ILogger $logger
54
	) {
55
		parent::__construct(
56
			$appName,
57
			$request,
58
			$urlGenerator,
59
			$logger
60
		);
61
62
		$this->config = $appConfig;
63
		$this->reflector = $reflector;
64
	}
65
66
	/**
67
	 * Checks if sharing is enabled before the controllers is executed
68
	 *
69
	 * Inspects the controller method annotations and if PublicPage is found
70
	 * it makes sure that sharing is enabled in the configuration settings
71
	 *
72
	 * The check is not performed on "guest" pages which don't require sharing
73
	 * to be enabled
74
	 *
75
	 * @inheritDoc
76
	 */
77
	public function beforeController($controller, $methodName) {
78
		if ($this->reflector->hasAnnotation('Guest')) {
79
			return;
80
		}
81
82
		$sharingEnabled = $this->isSharingEnabled();
83
		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
84
		if ($isPublicPage && !$sharingEnabled) {
85
			throw new CheckException("'Sharing is disabled'", Http::STATUS_SERVICE_UNAVAILABLE);
86
		}
87
	}
88
89
	/**
90
	 * Checks whether public sharing (via links) is enabled
91
	 *
92
	 * @return bool
93
	 */
94
	private function isSharingEnabled() {
95
		$shareApiAllowLinks = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
96
97
		if ($shareApiAllowLinks !== 'yes') {
98
			return false;
99
		}
100
101
		return true;
102
	}
103
104
}
105