@@ -31,52 +31,52 @@ |
||
31 | 31 | * Scanner for SharedStorage |
32 | 32 | */ |
33 | 33 | class Scanner extends \OC\Files\Cache\Scanner { |
34 | - /** |
|
35 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
36 | - */ |
|
37 | - protected $storage; |
|
34 | + /** |
|
35 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
36 | + */ |
|
37 | + protected $storage; |
|
38 | 38 | |
39 | - private $sourceScanner; |
|
39 | + private $sourceScanner; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns metadata from the shared storage, but |
|
43 | - * with permissions from the source storage. |
|
44 | - * |
|
45 | - * @param string $path path of the file for which to retrieve metadata |
|
46 | - * |
|
47 | - * @return array an array of metadata of the file |
|
48 | - */ |
|
49 | - public function getData($path) { |
|
50 | - $data = parent::getData($path); |
|
51 | - if ($data === null) { |
|
52 | - return null; |
|
53 | - } |
|
54 | - $internalPath = $this->storage->getUnjailedPath($path); |
|
55 | - $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath); |
|
56 | - return $data; |
|
57 | - } |
|
41 | + /** |
|
42 | + * Returns metadata from the shared storage, but |
|
43 | + * with permissions from the source storage. |
|
44 | + * |
|
45 | + * @param string $path path of the file for which to retrieve metadata |
|
46 | + * |
|
47 | + * @return array an array of metadata of the file |
|
48 | + */ |
|
49 | + public function getData($path) { |
|
50 | + $data = parent::getData($path); |
|
51 | + if ($data === null) { |
|
52 | + return null; |
|
53 | + } |
|
54 | + $internalPath = $this->storage->getUnjailedPath($path); |
|
55 | + $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath); |
|
56 | + return $data; |
|
57 | + } |
|
58 | 58 | |
59 | - private function getSourceScanner() { |
|
60 | - if ($this->sourceScanner) { |
|
61 | - return $this->sourceScanner; |
|
62 | - } |
|
63 | - if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
64 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
65 | - list($storage) = $this->storage->resolvePath(''); |
|
66 | - $this->sourceScanner = $storage->getScanner(); |
|
67 | - return $this->sourceScanner; |
|
68 | - } else { |
|
69 | - return null; |
|
70 | - } |
|
71 | - } |
|
59 | + private function getSourceScanner() { |
|
60 | + if ($this->sourceScanner) { |
|
61 | + return $this->sourceScanner; |
|
62 | + } |
|
63 | + if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
64 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
65 | + list($storage) = $this->storage->resolvePath(''); |
|
66 | + $this->sourceScanner = $storage->getScanner(); |
|
67 | + return $this->sourceScanner; |
|
68 | + } else { |
|
69 | + return null; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
74 | - $sourceScanner = $this->getSourceScanner(); |
|
75 | - if ($sourceScanner instanceof NoopScanner) { |
|
76 | - return []; |
|
77 | - } else { |
|
78 | - return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); |
|
79 | - } |
|
80 | - } |
|
73 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
74 | + $sourceScanner = $this->getSourceScanner(); |
|
75 | + if ($sourceScanner instanceof NoopScanner) { |
|
76 | + return []; |
|
77 | + } else { |
|
78 | + return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | } |
82 | 82 |
@@ -25,28 +25,28 @@ |
||
25 | 25 | use OCP\AppFramework\Http\JSONResponse; |
26 | 26 | |
27 | 27 | class RateLimitTestController extends Controller { |
28 | - /** |
|
29 | - * @PublicPage |
|
30 | - * @NoCSRFRequired |
|
31 | - * |
|
32 | - * @UserRateThrottle(limit=5, period=100) |
|
33 | - * @AnonRateThrottle(limit=1, period=100) |
|
34 | - * |
|
35 | - * @return JSONResponse |
|
36 | - */ |
|
37 | - public function userAndAnonProtected() { |
|
38 | - return new JSONResponse(); |
|
39 | - } |
|
28 | + /** |
|
29 | + * @PublicPage |
|
30 | + * @NoCSRFRequired |
|
31 | + * |
|
32 | + * @UserRateThrottle(limit=5, period=100) |
|
33 | + * @AnonRateThrottle(limit=1, period=100) |
|
34 | + * |
|
35 | + * @return JSONResponse |
|
36 | + */ |
|
37 | + public function userAndAnonProtected() { |
|
38 | + return new JSONResponse(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @PublicPage |
|
43 | - * @NoCSRFRequired |
|
44 | - * |
|
45 | - * @AnonRateThrottle(limit=1, period=10) |
|
46 | - * |
|
47 | - * @return JSONResponse |
|
48 | - */ |
|
49 | - public function onlyAnonProtected() { |
|
50 | - return new JSONResponse(); |
|
51 | - } |
|
41 | + /** |
|
42 | + * @PublicPage |
|
43 | + * @NoCSRFRequired |
|
44 | + * |
|
45 | + * @AnonRateThrottle(limit=1, period=10) |
|
46 | + * |
|
47 | + * @return JSONResponse |
|
48 | + */ |
|
49 | + public function onlyAnonProtected() { |
|
50 | + return new JSONResponse(); |
|
51 | + } |
|
52 | 52 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | use OCP\AppFramework\Http; |
26 | 26 | |
27 | 27 | class RateLimitExceededException extends SecurityException { |
28 | - public function __construct() { |
|
29 | - parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
30 | - } |
|
28 | + public function __construct() { |
|
29 | + parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
30 | + } |
|
31 | 31 | } |
@@ -48,87 +48,87 @@ |
||
48 | 48 | * @package OC\AppFramework\Middleware\Security |
49 | 49 | */ |
50 | 50 | class RateLimitingMiddleware extends Middleware { |
51 | - /** @var IRequest $request */ |
|
52 | - private $request; |
|
53 | - /** @var IUserSession */ |
|
54 | - private $userSession; |
|
55 | - /** @var ControllerMethodReflector */ |
|
56 | - private $reflector; |
|
57 | - /** @var Limiter */ |
|
58 | - private $limiter; |
|
51 | + /** @var IRequest $request */ |
|
52 | + private $request; |
|
53 | + /** @var IUserSession */ |
|
54 | + private $userSession; |
|
55 | + /** @var ControllerMethodReflector */ |
|
56 | + private $reflector; |
|
57 | + /** @var Limiter */ |
|
58 | + private $limiter; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param IRequest $request |
|
62 | - * @param IUserSession $userSession |
|
63 | - * @param ControllerMethodReflector $reflector |
|
64 | - * @param Limiter $limiter |
|
65 | - */ |
|
66 | - public function __construct(IRequest $request, |
|
67 | - IUserSession $userSession, |
|
68 | - ControllerMethodReflector $reflector, |
|
69 | - Limiter $limiter) { |
|
70 | - $this->request = $request; |
|
71 | - $this->userSession = $userSession; |
|
72 | - $this->reflector = $reflector; |
|
73 | - $this->limiter = $limiter; |
|
74 | - } |
|
60 | + /** |
|
61 | + * @param IRequest $request |
|
62 | + * @param IUserSession $userSession |
|
63 | + * @param ControllerMethodReflector $reflector |
|
64 | + * @param Limiter $limiter |
|
65 | + */ |
|
66 | + public function __construct(IRequest $request, |
|
67 | + IUserSession $userSession, |
|
68 | + ControllerMethodReflector $reflector, |
|
69 | + Limiter $limiter) { |
|
70 | + $this->request = $request; |
|
71 | + $this->userSession = $userSession; |
|
72 | + $this->reflector = $reflector; |
|
73 | + $this->limiter = $limiter; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * {@inheritDoc} |
|
78 | - * @throws RateLimitExceededException |
|
79 | - */ |
|
80 | - public function beforeController($controller, $methodName) { |
|
81 | - parent::beforeController($controller, $methodName); |
|
76 | + /** |
|
77 | + * {@inheritDoc} |
|
78 | + * @throws RateLimitExceededException |
|
79 | + */ |
|
80 | + public function beforeController($controller, $methodName) { |
|
81 | + parent::beforeController($controller, $methodName); |
|
82 | 82 | |
83 | - $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
84 | - $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
85 | - $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
86 | - $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
87 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
88 | - if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
89 | - $this->limiter->registerUserRequest( |
|
90 | - $rateLimitIdentifier, |
|
91 | - $userLimit, |
|
92 | - $userPeriod, |
|
93 | - $this->userSession->getUser() |
|
94 | - ); |
|
95 | - } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
96 | - $this->limiter->registerAnonRequest( |
|
97 | - $rateLimitIdentifier, |
|
98 | - $anonLimit, |
|
99 | - $anonPeriod, |
|
100 | - $this->request->getRemoteAddress() |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
83 | + $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
84 | + $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
85 | + $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
86 | + $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
87 | + $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
88 | + if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
89 | + $this->limiter->registerUserRequest( |
|
90 | + $rateLimitIdentifier, |
|
91 | + $userLimit, |
|
92 | + $userPeriod, |
|
93 | + $this->userSession->getUser() |
|
94 | + ); |
|
95 | + } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
96 | + $this->limiter->registerAnonRequest( |
|
97 | + $rateLimitIdentifier, |
|
98 | + $anonLimit, |
|
99 | + $anonPeriod, |
|
100 | + $this->request->getRemoteAddress() |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * {@inheritDoc} |
|
107 | - */ |
|
108 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
109 | - if($exception instanceof RateLimitExceededException) { |
|
110 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
111 | - $response = new JSONResponse( |
|
112 | - [ |
|
113 | - 'message' => $exception->getMessage(), |
|
114 | - ], |
|
115 | - $exception->getCode() |
|
116 | - ); |
|
117 | - } else { |
|
118 | - $response = new TemplateResponse( |
|
119 | - 'core', |
|
120 | - '403', |
|
121 | - [ |
|
122 | - 'file' => $exception->getMessage() |
|
123 | - ], |
|
124 | - 'guest' |
|
125 | - ); |
|
126 | - $response->setStatus($exception->getCode()); |
|
127 | - } |
|
105 | + /** |
|
106 | + * {@inheritDoc} |
|
107 | + */ |
|
108 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
109 | + if($exception instanceof RateLimitExceededException) { |
|
110 | + if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
111 | + $response = new JSONResponse( |
|
112 | + [ |
|
113 | + 'message' => $exception->getMessage(), |
|
114 | + ], |
|
115 | + $exception->getCode() |
|
116 | + ); |
|
117 | + } else { |
|
118 | + $response = new TemplateResponse( |
|
119 | + 'core', |
|
120 | + '403', |
|
121 | + [ |
|
122 | + 'file' => $exception->getMessage() |
|
123 | + ], |
|
124 | + 'guest' |
|
125 | + ); |
|
126 | + $response->setStatus($exception->getCode()); |
|
127 | + } |
|
128 | 128 | |
129 | - return $response; |
|
130 | - } |
|
129 | + return $response; |
|
130 | + } |
|
131 | 131 | |
132 | - throw $exception; |
|
133 | - } |
|
132 | + throw $exception; |
|
133 | + } |
|
134 | 134 | } |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
85 | 85 | $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
86 | 86 | $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
87 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
88 | - if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
87 | + $rateLimitIdentifier = get_class($controller).'::'.$methodName; |
|
88 | + if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
89 | 89 | $this->limiter->registerUserRequest( |
90 | 90 | $rateLimitIdentifier, |
91 | 91 | $userLimit, |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * {@inheritDoc} |
107 | 107 | */ |
108 | 108 | public function afterException($controller, $methodName, \Exception $exception) { |
109 | - if($exception instanceof RateLimitExceededException) { |
|
110 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
109 | + if ($exception instanceof RateLimitExceededException) { |
|
110 | + if (stripos($this->request->getHeader('Accept'), 'html') === false) { |
|
111 | 111 | $response = new JSONResponse( |
112 | 112 | [ |
113 | 113 | 'message' => $exception->getMessage(), |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function beforeController($controller, $methodName) { |
62 | 62 | parent::beforeController($controller, $methodName); |
63 | 63 | |
64 | - if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
64 | + if ($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
65 | 65 | $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
66 | 66 | $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
67 | 67 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * {@inheritDoc} |
72 | 72 | */ |
73 | 73 | public function afterController($controller, $methodName, Response $response) { |
74 | - if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
74 | + if ($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
75 | 75 | $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
76 | 76 | $ip = $this->request->getRemoteAddress(); |
77 | 77 | $this->throttler->sleepDelay($ip, $action); |
@@ -35,49 +35,49 @@ |
||
35 | 35 | * @package OC\AppFramework\Middleware\Security |
36 | 36 | */ |
37 | 37 | class BruteForceMiddleware extends Middleware { |
38 | - /** @var ControllerMethodReflector */ |
|
39 | - private $reflector; |
|
40 | - /** @var Throttler */ |
|
41 | - private $throttler; |
|
42 | - /** @var IRequest */ |
|
43 | - private $request; |
|
38 | + /** @var ControllerMethodReflector */ |
|
39 | + private $reflector; |
|
40 | + /** @var Throttler */ |
|
41 | + private $throttler; |
|
42 | + /** @var IRequest */ |
|
43 | + private $request; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ControllerMethodReflector $controllerMethodReflector |
|
47 | - * @param Throttler $throttler |
|
48 | - * @param IRequest $request |
|
49 | - */ |
|
50 | - public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
51 | - Throttler $throttler, |
|
52 | - IRequest $request) { |
|
53 | - $this->reflector = $controllerMethodReflector; |
|
54 | - $this->throttler = $throttler; |
|
55 | - $this->request = $request; |
|
56 | - } |
|
45 | + /** |
|
46 | + * @param ControllerMethodReflector $controllerMethodReflector |
|
47 | + * @param Throttler $throttler |
|
48 | + * @param IRequest $request |
|
49 | + */ |
|
50 | + public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
51 | + Throttler $throttler, |
|
52 | + IRequest $request) { |
|
53 | + $this->reflector = $controllerMethodReflector; |
|
54 | + $this->throttler = $throttler; |
|
55 | + $this->request = $request; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - */ |
|
61 | - public function beforeController($controller, $methodName) { |
|
62 | - parent::beforeController($controller, $methodName); |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + */ |
|
61 | + public function beforeController($controller, $methodName) { |
|
62 | + parent::beforeController($controller, $methodName); |
|
63 | 63 | |
64 | - if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
65 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
66 | - $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
67 | - } |
|
68 | - } |
|
64 | + if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
65 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
66 | + $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritDoc} |
|
72 | - */ |
|
73 | - public function afterController($controller, $methodName, Response $response) { |
|
74 | - if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
75 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
76 | - $ip = $this->request->getRemoteAddress(); |
|
77 | - $this->throttler->sleepDelay($ip, $action); |
|
78 | - $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
79 | - } |
|
70 | + /** |
|
71 | + * {@inheritDoc} |
|
72 | + */ |
|
73 | + public function afterController($controller, $methodName, Response $response) { |
|
74 | + if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
75 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
76 | + $ip = $this->request->getRemoteAddress(); |
|
77 | + $this->throttler->sleepDelay($ip, $action); |
|
78 | + $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
79 | + } |
|
80 | 80 | |
81 | - return parent::afterController($controller, $methodName, $response); |
|
82 | - } |
|
81 | + return parent::afterController($controller, $methodName, $response); |
|
82 | + } |
|
83 | 83 | } |
@@ -43,185 +43,185 @@ |
||
43 | 43 | * User storages controller |
44 | 44 | */ |
45 | 45 | class UserStoragesController extends StoragesController { |
46 | - /** |
|
47 | - * @var IUserSession |
|
48 | - */ |
|
49 | - private $userSession; |
|
50 | - |
|
51 | - /** |
|
52 | - * Creates a new user storages controller. |
|
53 | - * |
|
54 | - * @param string $AppName application name |
|
55 | - * @param IRequest $request request object |
|
56 | - * @param IL10N $l10n l10n service |
|
57 | - * @param UserStoragesService $userStoragesService storage service |
|
58 | - * @param IUserSession $userSession |
|
59 | - * @param ILogger $logger |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - $AppName, |
|
63 | - IRequest $request, |
|
64 | - IL10N $l10n, |
|
65 | - UserStoragesService $userStoragesService, |
|
66 | - IUserSession $userSession, |
|
67 | - ILogger $logger |
|
68 | - ) { |
|
69 | - parent::__construct( |
|
70 | - $AppName, |
|
71 | - $request, |
|
72 | - $l10n, |
|
73 | - $userStoragesService, |
|
74 | - $logger |
|
75 | - ); |
|
76 | - $this->userSession = $userSession; |
|
77 | - } |
|
78 | - |
|
79 | - protected function manipulateStorageConfig(StorageConfig $storage) { |
|
80 | - /** @var AuthMechanism */ |
|
81 | - $authMechanism = $storage->getAuthMechanism(); |
|
82 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
83 | - /** @var Backend */ |
|
84 | - $backend = $storage->getBackend(); |
|
85 | - $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Get all storage entries |
|
90 | - * |
|
91 | - * @NoAdminRequired |
|
92 | - * |
|
93 | - * @return DataResponse |
|
94 | - */ |
|
95 | - public function index() { |
|
96 | - return parent::index(); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Return storage |
|
101 | - * |
|
102 | - * @NoAdminRequired |
|
103 | - * |
|
104 | - * {@inheritdoc} |
|
105 | - */ |
|
106 | - public function show($id, $testOnly = true) { |
|
107 | - return parent::show($id, $testOnly); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Create an external storage entry. |
|
112 | - * |
|
113 | - * @param string $mountPoint storage mount point |
|
114 | - * @param string $backend backend identifier |
|
115 | - * @param string $authMechanism authentication mechanism identifier |
|
116 | - * @param array $backendOptions backend-specific options |
|
117 | - * @param array $mountOptions backend-specific mount options |
|
118 | - * |
|
119 | - * @return DataResponse |
|
120 | - * |
|
121 | - * @NoAdminRequired |
|
122 | - */ |
|
123 | - public function create( |
|
124 | - $mountPoint, |
|
125 | - $backend, |
|
126 | - $authMechanism, |
|
127 | - $backendOptions, |
|
128 | - $mountOptions |
|
129 | - ) { |
|
130 | - $newStorage = $this->createStorage( |
|
131 | - $mountPoint, |
|
132 | - $backend, |
|
133 | - $authMechanism, |
|
134 | - $backendOptions, |
|
135 | - $mountOptions |
|
136 | - ); |
|
137 | - if ($newStorage instanceOf DataResponse) { |
|
138 | - return $newStorage; |
|
139 | - } |
|
140 | - |
|
141 | - $response = $this->validate($newStorage); |
|
142 | - if (!empty($response)) { |
|
143 | - return $response; |
|
144 | - } |
|
145 | - |
|
146 | - $newStorage = $this->service->addStorage($newStorage); |
|
147 | - $this->updateStorageStatus($newStorage); |
|
148 | - |
|
149 | - return new DataResponse( |
|
150 | - $newStorage, |
|
151 | - Http::STATUS_CREATED |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Update an external storage entry. |
|
157 | - * |
|
158 | - * @param int $id storage id |
|
159 | - * @param string $mountPoint storage mount point |
|
160 | - * @param string $backend backend identifier |
|
161 | - * @param string $authMechanism authentication mechanism identifier |
|
162 | - * @param array $backendOptions backend-specific options |
|
163 | - * @param array $mountOptions backend-specific mount options |
|
164 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
165 | - * |
|
166 | - * @return DataResponse |
|
167 | - * |
|
168 | - * @NoAdminRequired |
|
169 | - */ |
|
170 | - public function update( |
|
171 | - $id, |
|
172 | - $mountPoint, |
|
173 | - $backend, |
|
174 | - $authMechanism, |
|
175 | - $backendOptions, |
|
176 | - $mountOptions, |
|
177 | - $testOnly = true |
|
178 | - ) { |
|
179 | - $storage = $this->createStorage( |
|
180 | - $mountPoint, |
|
181 | - $backend, |
|
182 | - $authMechanism, |
|
183 | - $backendOptions, |
|
184 | - $mountOptions |
|
185 | - ); |
|
186 | - if ($storage instanceOf DataResponse) { |
|
187 | - return $storage; |
|
188 | - } |
|
189 | - $storage->setId($id); |
|
190 | - |
|
191 | - $response = $this->validate($storage); |
|
192 | - if (!empty($response)) { |
|
193 | - return $response; |
|
194 | - } |
|
195 | - |
|
196 | - try { |
|
197 | - $storage = $this->service->updateStorage($storage); |
|
198 | - } catch (NotFoundException $e) { |
|
199 | - return new DataResponse( |
|
200 | - [ |
|
201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
202 | - ], |
|
203 | - Http::STATUS_NOT_FOUND |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - $this->updateStorageStatus($storage, $testOnly); |
|
208 | - |
|
209 | - return new DataResponse( |
|
210 | - $storage, |
|
211 | - Http::STATUS_OK |
|
212 | - ); |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Delete storage |
|
218 | - * |
|
219 | - * @NoAdminRequired |
|
220 | - * |
|
221 | - * {@inheritdoc} |
|
222 | - */ |
|
223 | - public function destroy($id) { |
|
224 | - return parent::destroy($id); |
|
225 | - } |
|
46 | + /** |
|
47 | + * @var IUserSession |
|
48 | + */ |
|
49 | + private $userSession; |
|
50 | + |
|
51 | + /** |
|
52 | + * Creates a new user storages controller. |
|
53 | + * |
|
54 | + * @param string $AppName application name |
|
55 | + * @param IRequest $request request object |
|
56 | + * @param IL10N $l10n l10n service |
|
57 | + * @param UserStoragesService $userStoragesService storage service |
|
58 | + * @param IUserSession $userSession |
|
59 | + * @param ILogger $logger |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + $AppName, |
|
63 | + IRequest $request, |
|
64 | + IL10N $l10n, |
|
65 | + UserStoragesService $userStoragesService, |
|
66 | + IUserSession $userSession, |
|
67 | + ILogger $logger |
|
68 | + ) { |
|
69 | + parent::__construct( |
|
70 | + $AppName, |
|
71 | + $request, |
|
72 | + $l10n, |
|
73 | + $userStoragesService, |
|
74 | + $logger |
|
75 | + ); |
|
76 | + $this->userSession = $userSession; |
|
77 | + } |
|
78 | + |
|
79 | + protected function manipulateStorageConfig(StorageConfig $storage) { |
|
80 | + /** @var AuthMechanism */ |
|
81 | + $authMechanism = $storage->getAuthMechanism(); |
|
82 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
83 | + /** @var Backend */ |
|
84 | + $backend = $storage->getBackend(); |
|
85 | + $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Get all storage entries |
|
90 | + * |
|
91 | + * @NoAdminRequired |
|
92 | + * |
|
93 | + * @return DataResponse |
|
94 | + */ |
|
95 | + public function index() { |
|
96 | + return parent::index(); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Return storage |
|
101 | + * |
|
102 | + * @NoAdminRequired |
|
103 | + * |
|
104 | + * {@inheritdoc} |
|
105 | + */ |
|
106 | + public function show($id, $testOnly = true) { |
|
107 | + return parent::show($id, $testOnly); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Create an external storage entry. |
|
112 | + * |
|
113 | + * @param string $mountPoint storage mount point |
|
114 | + * @param string $backend backend identifier |
|
115 | + * @param string $authMechanism authentication mechanism identifier |
|
116 | + * @param array $backendOptions backend-specific options |
|
117 | + * @param array $mountOptions backend-specific mount options |
|
118 | + * |
|
119 | + * @return DataResponse |
|
120 | + * |
|
121 | + * @NoAdminRequired |
|
122 | + */ |
|
123 | + public function create( |
|
124 | + $mountPoint, |
|
125 | + $backend, |
|
126 | + $authMechanism, |
|
127 | + $backendOptions, |
|
128 | + $mountOptions |
|
129 | + ) { |
|
130 | + $newStorage = $this->createStorage( |
|
131 | + $mountPoint, |
|
132 | + $backend, |
|
133 | + $authMechanism, |
|
134 | + $backendOptions, |
|
135 | + $mountOptions |
|
136 | + ); |
|
137 | + if ($newStorage instanceOf DataResponse) { |
|
138 | + return $newStorage; |
|
139 | + } |
|
140 | + |
|
141 | + $response = $this->validate($newStorage); |
|
142 | + if (!empty($response)) { |
|
143 | + return $response; |
|
144 | + } |
|
145 | + |
|
146 | + $newStorage = $this->service->addStorage($newStorage); |
|
147 | + $this->updateStorageStatus($newStorage); |
|
148 | + |
|
149 | + return new DataResponse( |
|
150 | + $newStorage, |
|
151 | + Http::STATUS_CREATED |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Update an external storage entry. |
|
157 | + * |
|
158 | + * @param int $id storage id |
|
159 | + * @param string $mountPoint storage mount point |
|
160 | + * @param string $backend backend identifier |
|
161 | + * @param string $authMechanism authentication mechanism identifier |
|
162 | + * @param array $backendOptions backend-specific options |
|
163 | + * @param array $mountOptions backend-specific mount options |
|
164 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
165 | + * |
|
166 | + * @return DataResponse |
|
167 | + * |
|
168 | + * @NoAdminRequired |
|
169 | + */ |
|
170 | + public function update( |
|
171 | + $id, |
|
172 | + $mountPoint, |
|
173 | + $backend, |
|
174 | + $authMechanism, |
|
175 | + $backendOptions, |
|
176 | + $mountOptions, |
|
177 | + $testOnly = true |
|
178 | + ) { |
|
179 | + $storage = $this->createStorage( |
|
180 | + $mountPoint, |
|
181 | + $backend, |
|
182 | + $authMechanism, |
|
183 | + $backendOptions, |
|
184 | + $mountOptions |
|
185 | + ); |
|
186 | + if ($storage instanceOf DataResponse) { |
|
187 | + return $storage; |
|
188 | + } |
|
189 | + $storage->setId($id); |
|
190 | + |
|
191 | + $response = $this->validate($storage); |
|
192 | + if (!empty($response)) { |
|
193 | + return $response; |
|
194 | + } |
|
195 | + |
|
196 | + try { |
|
197 | + $storage = $this->service->updateStorage($storage); |
|
198 | + } catch (NotFoundException $e) { |
|
199 | + return new DataResponse( |
|
200 | + [ |
|
201 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
202 | + ], |
|
203 | + Http::STATUS_NOT_FOUND |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + $this->updateStorageStatus($storage, $testOnly); |
|
208 | + |
|
209 | + return new DataResponse( |
|
210 | + $storage, |
|
211 | + Http::STATUS_OK |
|
212 | + ); |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Delete storage |
|
218 | + * |
|
219 | + * @NoAdminRequired |
|
220 | + * |
|
221 | + * {@inheritdoc} |
|
222 | + */ |
|
223 | + public function destroy($id) { |
|
224 | + return parent::destroy($id); |
|
225 | + } |
|
226 | 226 | |
227 | 227 | } |
@@ -198,7 +198,7 @@ |
||
198 | 198 | } catch (NotFoundException $e) { |
199 | 199 | return new DataResponse( |
200 | 200 | [ |
201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
201 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
202 | 202 | ], |
203 | 203 | Http::STATUS_NOT_FOUND |
204 | 204 | ); |
@@ -39,151 +39,151 @@ |
||
39 | 39 | * Global storages controller |
40 | 40 | */ |
41 | 41 | class GlobalStoragesController extends StoragesController { |
42 | - /** |
|
43 | - * Creates a new global storages controller. |
|
44 | - * |
|
45 | - * @param string $AppName application name |
|
46 | - * @param IRequest $request request object |
|
47 | - * @param IL10N $l10n l10n service |
|
48 | - * @param GlobalStoragesService $globalStoragesService storage service |
|
49 | - * @param ILogger $logger |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - $AppName, |
|
53 | - IRequest $request, |
|
54 | - IL10N $l10n, |
|
55 | - GlobalStoragesService $globalStoragesService, |
|
56 | - ILogger $logger |
|
57 | - ) { |
|
58 | - parent::__construct( |
|
59 | - $AppName, |
|
60 | - $request, |
|
61 | - $l10n, |
|
62 | - $globalStoragesService, |
|
63 | - $logger |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Create an external storage entry. |
|
69 | - * |
|
70 | - * @param string $mountPoint storage mount point |
|
71 | - * @param string $backend backend identifier |
|
72 | - * @param string $authMechanism authentication mechanism identifier |
|
73 | - * @param array $backendOptions backend-specific options |
|
74 | - * @param array $mountOptions mount-specific options |
|
75 | - * @param array $applicableUsers users for which to mount the storage |
|
76 | - * @param array $applicableGroups groups for which to mount the storage |
|
77 | - * @param int $priority priority |
|
78 | - * |
|
79 | - * @return DataResponse |
|
80 | - */ |
|
81 | - public function create( |
|
82 | - $mountPoint, |
|
83 | - $backend, |
|
84 | - $authMechanism, |
|
85 | - $backendOptions, |
|
86 | - $mountOptions, |
|
87 | - $applicableUsers, |
|
88 | - $applicableGroups, |
|
89 | - $priority |
|
90 | - ) { |
|
91 | - $newStorage = $this->createStorage( |
|
92 | - $mountPoint, |
|
93 | - $backend, |
|
94 | - $authMechanism, |
|
95 | - $backendOptions, |
|
96 | - $mountOptions, |
|
97 | - $applicableUsers, |
|
98 | - $applicableGroups, |
|
99 | - $priority |
|
100 | - ); |
|
101 | - if ($newStorage instanceof DataResponse) { |
|
102 | - return $newStorage; |
|
103 | - } |
|
104 | - |
|
105 | - $response = $this->validate($newStorage); |
|
106 | - if (!empty($response)) { |
|
107 | - return $response; |
|
108 | - } |
|
109 | - |
|
110 | - $newStorage = $this->service->addStorage($newStorage); |
|
111 | - |
|
112 | - $this->updateStorageStatus($newStorage); |
|
113 | - |
|
114 | - return new DataResponse( |
|
115 | - $newStorage, |
|
116 | - Http::STATUS_CREATED |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Update an external storage entry. |
|
122 | - * |
|
123 | - * @param int $id storage id |
|
124 | - * @param string $mountPoint storage mount point |
|
125 | - * @param string $backend backend identifier |
|
126 | - * @param string $authMechanism authentication mechansim identifier |
|
127 | - * @param array $backendOptions backend-specific options |
|
128 | - * @param array $mountOptions mount-specific options |
|
129 | - * @param array $applicableUsers users for which to mount the storage |
|
130 | - * @param array $applicableGroups groups for which to mount the storage |
|
131 | - * @param int $priority priority |
|
132 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
133 | - * |
|
134 | - * @return DataResponse |
|
135 | - */ |
|
136 | - public function update( |
|
137 | - $id, |
|
138 | - $mountPoint, |
|
139 | - $backend, |
|
140 | - $authMechanism, |
|
141 | - $backendOptions, |
|
142 | - $mountOptions, |
|
143 | - $applicableUsers, |
|
144 | - $applicableGroups, |
|
145 | - $priority, |
|
146 | - $testOnly = true |
|
147 | - ) { |
|
148 | - $storage = $this->createStorage( |
|
149 | - $mountPoint, |
|
150 | - $backend, |
|
151 | - $authMechanism, |
|
152 | - $backendOptions, |
|
153 | - $mountOptions, |
|
154 | - $applicableUsers, |
|
155 | - $applicableGroups, |
|
156 | - $priority |
|
157 | - ); |
|
158 | - if ($storage instanceof DataResponse) { |
|
159 | - return $storage; |
|
160 | - } |
|
161 | - $storage->setId($id); |
|
162 | - |
|
163 | - $response = $this->validate($storage); |
|
164 | - if (!empty($response)) { |
|
165 | - return $response; |
|
166 | - } |
|
167 | - |
|
168 | - try { |
|
169 | - $storage = $this->service->updateStorage($storage); |
|
170 | - } catch (NotFoundException $e) { |
|
171 | - return new DataResponse( |
|
172 | - [ |
|
173 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
174 | - ], |
|
175 | - Http::STATUS_NOT_FOUND |
|
176 | - ); |
|
177 | - } |
|
178 | - |
|
179 | - $this->updateStorageStatus($storage, $testOnly); |
|
180 | - |
|
181 | - return new DataResponse( |
|
182 | - $storage, |
|
183 | - Http::STATUS_OK |
|
184 | - ); |
|
185 | - |
|
186 | - } |
|
42 | + /** |
|
43 | + * Creates a new global storages controller. |
|
44 | + * |
|
45 | + * @param string $AppName application name |
|
46 | + * @param IRequest $request request object |
|
47 | + * @param IL10N $l10n l10n service |
|
48 | + * @param GlobalStoragesService $globalStoragesService storage service |
|
49 | + * @param ILogger $logger |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + $AppName, |
|
53 | + IRequest $request, |
|
54 | + IL10N $l10n, |
|
55 | + GlobalStoragesService $globalStoragesService, |
|
56 | + ILogger $logger |
|
57 | + ) { |
|
58 | + parent::__construct( |
|
59 | + $AppName, |
|
60 | + $request, |
|
61 | + $l10n, |
|
62 | + $globalStoragesService, |
|
63 | + $logger |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Create an external storage entry. |
|
69 | + * |
|
70 | + * @param string $mountPoint storage mount point |
|
71 | + * @param string $backend backend identifier |
|
72 | + * @param string $authMechanism authentication mechanism identifier |
|
73 | + * @param array $backendOptions backend-specific options |
|
74 | + * @param array $mountOptions mount-specific options |
|
75 | + * @param array $applicableUsers users for which to mount the storage |
|
76 | + * @param array $applicableGroups groups for which to mount the storage |
|
77 | + * @param int $priority priority |
|
78 | + * |
|
79 | + * @return DataResponse |
|
80 | + */ |
|
81 | + public function create( |
|
82 | + $mountPoint, |
|
83 | + $backend, |
|
84 | + $authMechanism, |
|
85 | + $backendOptions, |
|
86 | + $mountOptions, |
|
87 | + $applicableUsers, |
|
88 | + $applicableGroups, |
|
89 | + $priority |
|
90 | + ) { |
|
91 | + $newStorage = $this->createStorage( |
|
92 | + $mountPoint, |
|
93 | + $backend, |
|
94 | + $authMechanism, |
|
95 | + $backendOptions, |
|
96 | + $mountOptions, |
|
97 | + $applicableUsers, |
|
98 | + $applicableGroups, |
|
99 | + $priority |
|
100 | + ); |
|
101 | + if ($newStorage instanceof DataResponse) { |
|
102 | + return $newStorage; |
|
103 | + } |
|
104 | + |
|
105 | + $response = $this->validate($newStorage); |
|
106 | + if (!empty($response)) { |
|
107 | + return $response; |
|
108 | + } |
|
109 | + |
|
110 | + $newStorage = $this->service->addStorage($newStorage); |
|
111 | + |
|
112 | + $this->updateStorageStatus($newStorage); |
|
113 | + |
|
114 | + return new DataResponse( |
|
115 | + $newStorage, |
|
116 | + Http::STATUS_CREATED |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Update an external storage entry. |
|
122 | + * |
|
123 | + * @param int $id storage id |
|
124 | + * @param string $mountPoint storage mount point |
|
125 | + * @param string $backend backend identifier |
|
126 | + * @param string $authMechanism authentication mechansim identifier |
|
127 | + * @param array $backendOptions backend-specific options |
|
128 | + * @param array $mountOptions mount-specific options |
|
129 | + * @param array $applicableUsers users for which to mount the storage |
|
130 | + * @param array $applicableGroups groups for which to mount the storage |
|
131 | + * @param int $priority priority |
|
132 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
133 | + * |
|
134 | + * @return DataResponse |
|
135 | + */ |
|
136 | + public function update( |
|
137 | + $id, |
|
138 | + $mountPoint, |
|
139 | + $backend, |
|
140 | + $authMechanism, |
|
141 | + $backendOptions, |
|
142 | + $mountOptions, |
|
143 | + $applicableUsers, |
|
144 | + $applicableGroups, |
|
145 | + $priority, |
|
146 | + $testOnly = true |
|
147 | + ) { |
|
148 | + $storage = $this->createStorage( |
|
149 | + $mountPoint, |
|
150 | + $backend, |
|
151 | + $authMechanism, |
|
152 | + $backendOptions, |
|
153 | + $mountOptions, |
|
154 | + $applicableUsers, |
|
155 | + $applicableGroups, |
|
156 | + $priority |
|
157 | + ); |
|
158 | + if ($storage instanceof DataResponse) { |
|
159 | + return $storage; |
|
160 | + } |
|
161 | + $storage->setId($id); |
|
162 | + |
|
163 | + $response = $this->validate($storage); |
|
164 | + if (!empty($response)) { |
|
165 | + return $response; |
|
166 | + } |
|
167 | + |
|
168 | + try { |
|
169 | + $storage = $this->service->updateStorage($storage); |
|
170 | + } catch (NotFoundException $e) { |
|
171 | + return new DataResponse( |
|
172 | + [ |
|
173 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
174 | + ], |
|
175 | + Http::STATUS_NOT_FOUND |
|
176 | + ); |
|
177 | + } |
|
178 | + |
|
179 | + $this->updateStorageStatus($storage, $testOnly); |
|
180 | + |
|
181 | + return new DataResponse( |
|
182 | + $storage, |
|
183 | + Http::STATUS_OK |
|
184 | + ); |
|
185 | + |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | } |
@@ -198,7 +198,7 @@ |
||
198 | 198 | } catch (NotFoundException $e) { |
199 | 199 | return new DataResponse( |
200 | 200 | [ |
201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
201 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
202 | 202 | ], |
203 | 203 | Http::STATUS_NOT_FOUND |
204 | 204 | ); |
@@ -47,298 +47,298 @@ |
||
47 | 47 | */ |
48 | 48 | abstract class StoragesController extends Controller { |
49 | 49 | |
50 | - /** |
|
51 | - * L10N service |
|
52 | - * |
|
53 | - * @var IL10N |
|
54 | - */ |
|
55 | - protected $l10n; |
|
50 | + /** |
|
51 | + * L10N service |
|
52 | + * |
|
53 | + * @var IL10N |
|
54 | + */ |
|
55 | + protected $l10n; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Storages service |
|
59 | - * |
|
60 | - * @var StoragesService |
|
61 | - */ |
|
62 | - protected $service; |
|
57 | + /** |
|
58 | + * Storages service |
|
59 | + * |
|
60 | + * @var StoragesService |
|
61 | + */ |
|
62 | + protected $service; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @var ILogger |
|
66 | - */ |
|
67 | - protected $logger; |
|
64 | + /** |
|
65 | + * @var ILogger |
|
66 | + */ |
|
67 | + protected $logger; |
|
68 | 68 | |
69 | - /** |
|
70 | - * Creates a new storages controller. |
|
71 | - * |
|
72 | - * @param string $AppName application name |
|
73 | - * @param IRequest $request request object |
|
74 | - * @param IL10N $l10n l10n service |
|
75 | - * @param StoragesService $storagesService storage service |
|
76 | - * @param ILogger $logger |
|
77 | - */ |
|
78 | - public function __construct( |
|
79 | - $AppName, |
|
80 | - IRequest $request, |
|
81 | - IL10N $l10n, |
|
82 | - StoragesService $storagesService, |
|
83 | - ILogger $logger |
|
84 | - ) { |
|
85 | - parent::__construct($AppName, $request); |
|
86 | - $this->l10n = $l10n; |
|
87 | - $this->service = $storagesService; |
|
88 | - $this->logger = $logger; |
|
89 | - } |
|
69 | + /** |
|
70 | + * Creates a new storages controller. |
|
71 | + * |
|
72 | + * @param string $AppName application name |
|
73 | + * @param IRequest $request request object |
|
74 | + * @param IL10N $l10n l10n service |
|
75 | + * @param StoragesService $storagesService storage service |
|
76 | + * @param ILogger $logger |
|
77 | + */ |
|
78 | + public function __construct( |
|
79 | + $AppName, |
|
80 | + IRequest $request, |
|
81 | + IL10N $l10n, |
|
82 | + StoragesService $storagesService, |
|
83 | + ILogger $logger |
|
84 | + ) { |
|
85 | + parent::__construct($AppName, $request); |
|
86 | + $this->l10n = $l10n; |
|
87 | + $this->service = $storagesService; |
|
88 | + $this->logger = $logger; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Create a storage from its parameters |
|
93 | - * |
|
94 | - * @param string $mountPoint storage mount point |
|
95 | - * @param string $backend backend identifier |
|
96 | - * @param string $authMechanism authentication mechanism identifier |
|
97 | - * @param array $backendOptions backend-specific options |
|
98 | - * @param array|null $mountOptions mount-specific options |
|
99 | - * @param array|null $applicableUsers users for which to mount the storage |
|
100 | - * @param array|null $applicableGroups groups for which to mount the storage |
|
101 | - * @param int|null $priority priority |
|
102 | - * |
|
103 | - * @return StorageConfig|DataResponse |
|
104 | - */ |
|
105 | - protected function createStorage( |
|
106 | - $mountPoint, |
|
107 | - $backend, |
|
108 | - $authMechanism, |
|
109 | - $backendOptions, |
|
110 | - $mountOptions = null, |
|
111 | - $applicableUsers = null, |
|
112 | - $applicableGroups = null, |
|
113 | - $priority = null |
|
114 | - ) { |
|
115 | - try { |
|
116 | - return $this->service->createStorage( |
|
117 | - $mountPoint, |
|
118 | - $backend, |
|
119 | - $authMechanism, |
|
120 | - $backendOptions, |
|
121 | - $mountOptions, |
|
122 | - $applicableUsers, |
|
123 | - $applicableGroups, |
|
124 | - $priority |
|
125 | - ); |
|
126 | - } catch (\InvalidArgumentException $e) { |
|
127 | - $this->logger->logException($e); |
|
128 | - return new DataResponse( |
|
129 | - [ |
|
130 | - 'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class') |
|
131 | - ], |
|
132 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
133 | - ); |
|
134 | - } |
|
135 | - } |
|
91 | + /** |
|
92 | + * Create a storage from its parameters |
|
93 | + * |
|
94 | + * @param string $mountPoint storage mount point |
|
95 | + * @param string $backend backend identifier |
|
96 | + * @param string $authMechanism authentication mechanism identifier |
|
97 | + * @param array $backendOptions backend-specific options |
|
98 | + * @param array|null $mountOptions mount-specific options |
|
99 | + * @param array|null $applicableUsers users for which to mount the storage |
|
100 | + * @param array|null $applicableGroups groups for which to mount the storage |
|
101 | + * @param int|null $priority priority |
|
102 | + * |
|
103 | + * @return StorageConfig|DataResponse |
|
104 | + */ |
|
105 | + protected function createStorage( |
|
106 | + $mountPoint, |
|
107 | + $backend, |
|
108 | + $authMechanism, |
|
109 | + $backendOptions, |
|
110 | + $mountOptions = null, |
|
111 | + $applicableUsers = null, |
|
112 | + $applicableGroups = null, |
|
113 | + $priority = null |
|
114 | + ) { |
|
115 | + try { |
|
116 | + return $this->service->createStorage( |
|
117 | + $mountPoint, |
|
118 | + $backend, |
|
119 | + $authMechanism, |
|
120 | + $backendOptions, |
|
121 | + $mountOptions, |
|
122 | + $applicableUsers, |
|
123 | + $applicableGroups, |
|
124 | + $priority |
|
125 | + ); |
|
126 | + } catch (\InvalidArgumentException $e) { |
|
127 | + $this->logger->logException($e); |
|
128 | + return new DataResponse( |
|
129 | + [ |
|
130 | + 'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class') |
|
131 | + ], |
|
132 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
133 | + ); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Validate storage config |
|
139 | - * |
|
140 | - * @param StorageConfig $storage storage config |
|
141 | - *1 |
|
142 | - * @return DataResponse|null returns response in case of validation error |
|
143 | - */ |
|
144 | - protected function validate(StorageConfig $storage) { |
|
145 | - $mountPoint = $storage->getMountPoint(); |
|
146 | - if ($mountPoint === '') { |
|
147 | - return new DataResponse( |
|
148 | - array( |
|
149 | - 'message' => (string)$this->l10n->t('Invalid mount point') |
|
150 | - ), |
|
151 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
152 | - ); |
|
153 | - } |
|
137 | + /** |
|
138 | + * Validate storage config |
|
139 | + * |
|
140 | + * @param StorageConfig $storage storage config |
|
141 | + *1 |
|
142 | + * @return DataResponse|null returns response in case of validation error |
|
143 | + */ |
|
144 | + protected function validate(StorageConfig $storage) { |
|
145 | + $mountPoint = $storage->getMountPoint(); |
|
146 | + if ($mountPoint === '') { |
|
147 | + return new DataResponse( |
|
148 | + array( |
|
149 | + 'message' => (string)$this->l10n->t('Invalid mount point') |
|
150 | + ), |
|
151 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
152 | + ); |
|
153 | + } |
|
154 | 154 | |
155 | - if ($storage->getBackendOption('objectstore')) { |
|
156 | - // objectstore must not be sent from client side |
|
157 | - return new DataResponse( |
|
158 | - array( |
|
159 | - 'message' => (string)$this->l10n->t('Objectstore forbidden') |
|
160 | - ), |
|
161 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
162 | - ); |
|
163 | - } |
|
155 | + if ($storage->getBackendOption('objectstore')) { |
|
156 | + // objectstore must not be sent from client side |
|
157 | + return new DataResponse( |
|
158 | + array( |
|
159 | + 'message' => (string)$this->l10n->t('Objectstore forbidden') |
|
160 | + ), |
|
161 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
162 | + ); |
|
163 | + } |
|
164 | 164 | |
165 | - /** @var Backend */ |
|
166 | - $backend = $storage->getBackend(); |
|
167 | - /** @var AuthMechanism */ |
|
168 | - $authMechanism = $storage->getAuthMechanism(); |
|
169 | - if ($backend->checkDependencies()) { |
|
170 | - // invalid backend |
|
171 | - return new DataResponse( |
|
172 | - array( |
|
173 | - 'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [ |
|
174 | - $backend->getIdentifier() |
|
175 | - ]) |
|
176 | - ), |
|
177 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
178 | - ); |
|
179 | - } |
|
165 | + /** @var Backend */ |
|
166 | + $backend = $storage->getBackend(); |
|
167 | + /** @var AuthMechanism */ |
|
168 | + $authMechanism = $storage->getAuthMechanism(); |
|
169 | + if ($backend->checkDependencies()) { |
|
170 | + // invalid backend |
|
171 | + return new DataResponse( |
|
172 | + array( |
|
173 | + 'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [ |
|
174 | + $backend->getIdentifier() |
|
175 | + ]) |
|
176 | + ), |
|
177 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
178 | + ); |
|
179 | + } |
|
180 | 180 | |
181 | - if (!$backend->isVisibleFor($this->service->getVisibilityType())) { |
|
182 | - // not permitted to use backend |
|
183 | - return new DataResponse( |
|
184 | - array( |
|
185 | - 'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [ |
|
186 | - $backend->getIdentifier() |
|
187 | - ]) |
|
188 | - ), |
|
189 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
190 | - ); |
|
191 | - } |
|
192 | - if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) { |
|
193 | - // not permitted to use auth mechanism |
|
194 | - return new DataResponse( |
|
195 | - array( |
|
196 | - 'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [ |
|
197 | - $authMechanism->getIdentifier() |
|
198 | - ]) |
|
199 | - ), |
|
200 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
201 | - ); |
|
202 | - } |
|
181 | + if (!$backend->isVisibleFor($this->service->getVisibilityType())) { |
|
182 | + // not permitted to use backend |
|
183 | + return new DataResponse( |
|
184 | + array( |
|
185 | + 'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [ |
|
186 | + $backend->getIdentifier() |
|
187 | + ]) |
|
188 | + ), |
|
189 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
190 | + ); |
|
191 | + } |
|
192 | + if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) { |
|
193 | + // not permitted to use auth mechanism |
|
194 | + return new DataResponse( |
|
195 | + array( |
|
196 | + 'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [ |
|
197 | + $authMechanism->getIdentifier() |
|
198 | + ]) |
|
199 | + ), |
|
200 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | |
204 | - if (!$backend->validateStorage($storage)) { |
|
205 | - // unsatisfied parameters |
|
206 | - return new DataResponse( |
|
207 | - array( |
|
208 | - 'message' => (string)$this->l10n->t('Unsatisfied backend parameters') |
|
209 | - ), |
|
210 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
211 | - ); |
|
212 | - } |
|
213 | - if (!$authMechanism->validateStorage($storage)) { |
|
214 | - // unsatisfied parameters |
|
215 | - return new DataResponse( |
|
216 | - [ |
|
217 | - 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters') |
|
218 | - ], |
|
219 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
220 | - ); |
|
221 | - } |
|
204 | + if (!$backend->validateStorage($storage)) { |
|
205 | + // unsatisfied parameters |
|
206 | + return new DataResponse( |
|
207 | + array( |
|
208 | + 'message' => (string)$this->l10n->t('Unsatisfied backend parameters') |
|
209 | + ), |
|
210 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
211 | + ); |
|
212 | + } |
|
213 | + if (!$authMechanism->validateStorage($storage)) { |
|
214 | + // unsatisfied parameters |
|
215 | + return new DataResponse( |
|
216 | + [ |
|
217 | + 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters') |
|
218 | + ], |
|
219 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
220 | + ); |
|
221 | + } |
|
222 | 222 | |
223 | - return null; |
|
224 | - } |
|
223 | + return null; |
|
224 | + } |
|
225 | 225 | |
226 | - protected function manipulateStorageConfig(StorageConfig $storage) { |
|
227 | - /** @var AuthMechanism */ |
|
228 | - $authMechanism = $storage->getAuthMechanism(); |
|
229 | - $authMechanism->manipulateStorageConfig($storage); |
|
230 | - /** @var Backend */ |
|
231 | - $backend = $storage->getBackend(); |
|
232 | - $backend->manipulateStorageConfig($storage); |
|
233 | - } |
|
226 | + protected function manipulateStorageConfig(StorageConfig $storage) { |
|
227 | + /** @var AuthMechanism */ |
|
228 | + $authMechanism = $storage->getAuthMechanism(); |
|
229 | + $authMechanism->manipulateStorageConfig($storage); |
|
230 | + /** @var Backend */ |
|
231 | + $backend = $storage->getBackend(); |
|
232 | + $backend->manipulateStorageConfig($storage); |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * Check whether the given storage is available / valid. |
|
237 | - * |
|
238 | - * Note that this operation can be time consuming depending |
|
239 | - * on whether the remote storage is available or not. |
|
240 | - * |
|
241 | - * @param StorageConfig $storage storage configuration |
|
242 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
243 | - */ |
|
244 | - protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) { |
|
245 | - try { |
|
246 | - $this->manipulateStorageConfig($storage); |
|
235 | + /** |
|
236 | + * Check whether the given storage is available / valid. |
|
237 | + * |
|
238 | + * Note that this operation can be time consuming depending |
|
239 | + * on whether the remote storage is available or not. |
|
240 | + * |
|
241 | + * @param StorageConfig $storage storage configuration |
|
242 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
243 | + */ |
|
244 | + protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) { |
|
245 | + try { |
|
246 | + $this->manipulateStorageConfig($storage); |
|
247 | 247 | |
248 | - /** @var Backend */ |
|
249 | - $backend = $storage->getBackend(); |
|
250 | - // update status (can be time-consuming) |
|
251 | - $storage->setStatus( |
|
252 | - \OC_Mount_Config::getBackendStatus( |
|
253 | - $backend->getStorageClass(), |
|
254 | - $storage->getBackendOptions(), |
|
255 | - false, |
|
256 | - $testOnly |
|
257 | - ) |
|
258 | - ); |
|
259 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
260 | - $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; |
|
261 | - $storage->setStatus( |
|
262 | - $status, |
|
263 | - $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) |
|
264 | - ); |
|
265 | - } catch (StorageNotAvailableException $e) { |
|
266 | - $storage->setStatus( |
|
267 | - $e->getCode(), |
|
268 | - $this->l10n->t('%s', [$e->getMessage()]) |
|
269 | - ); |
|
270 | - } catch (\Exception $e) { |
|
271 | - // FIXME: convert storage exceptions to StorageNotAvailableException |
|
272 | - $storage->setStatus( |
|
273 | - StorageNotAvailableException::STATUS_ERROR, |
|
274 | - get_class($e).': '.$e->getMessage() |
|
275 | - ); |
|
276 | - } |
|
277 | - } |
|
248 | + /** @var Backend */ |
|
249 | + $backend = $storage->getBackend(); |
|
250 | + // update status (can be time-consuming) |
|
251 | + $storage->setStatus( |
|
252 | + \OC_Mount_Config::getBackendStatus( |
|
253 | + $backend->getStorageClass(), |
|
254 | + $storage->getBackendOptions(), |
|
255 | + false, |
|
256 | + $testOnly |
|
257 | + ) |
|
258 | + ); |
|
259 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
260 | + $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; |
|
261 | + $storage->setStatus( |
|
262 | + $status, |
|
263 | + $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) |
|
264 | + ); |
|
265 | + } catch (StorageNotAvailableException $e) { |
|
266 | + $storage->setStatus( |
|
267 | + $e->getCode(), |
|
268 | + $this->l10n->t('%s', [$e->getMessage()]) |
|
269 | + ); |
|
270 | + } catch (\Exception $e) { |
|
271 | + // FIXME: convert storage exceptions to StorageNotAvailableException |
|
272 | + $storage->setStatus( |
|
273 | + StorageNotAvailableException::STATUS_ERROR, |
|
274 | + get_class($e).': '.$e->getMessage() |
|
275 | + ); |
|
276 | + } |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Get all storage entries |
|
281 | - * |
|
282 | - * @return DataResponse |
|
283 | - */ |
|
284 | - public function index() { |
|
285 | - $storages = $this->service->getStorages(); |
|
279 | + /** |
|
280 | + * Get all storage entries |
|
281 | + * |
|
282 | + * @return DataResponse |
|
283 | + */ |
|
284 | + public function index() { |
|
285 | + $storages = $this->service->getStorages(); |
|
286 | 286 | |
287 | - return new DataResponse( |
|
288 | - $storages, |
|
289 | - Http::STATUS_OK |
|
290 | - ); |
|
291 | - } |
|
287 | + return new DataResponse( |
|
288 | + $storages, |
|
289 | + Http::STATUS_OK |
|
290 | + ); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * Get an external storage entry. |
|
295 | - * |
|
296 | - * @param int $id storage id |
|
297 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
298 | - * |
|
299 | - * @return DataResponse |
|
300 | - */ |
|
301 | - public function show($id, $testOnly = true) { |
|
302 | - try { |
|
303 | - $storage = $this->service->getStorage($id); |
|
293 | + /** |
|
294 | + * Get an external storage entry. |
|
295 | + * |
|
296 | + * @param int $id storage id |
|
297 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
298 | + * |
|
299 | + * @return DataResponse |
|
300 | + */ |
|
301 | + public function show($id, $testOnly = true) { |
|
302 | + try { |
|
303 | + $storage = $this->service->getStorage($id); |
|
304 | 304 | |
305 | - $this->updateStorageStatus($storage, $testOnly); |
|
306 | - } catch (NotFoundException $e) { |
|
307 | - return new DataResponse( |
|
308 | - [ |
|
309 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
310 | - ], |
|
311 | - Http::STATUS_NOT_FOUND |
|
312 | - ); |
|
313 | - } |
|
305 | + $this->updateStorageStatus($storage, $testOnly); |
|
306 | + } catch (NotFoundException $e) { |
|
307 | + return new DataResponse( |
|
308 | + [ |
|
309 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
310 | + ], |
|
311 | + Http::STATUS_NOT_FOUND |
|
312 | + ); |
|
313 | + } |
|
314 | 314 | |
315 | - return new DataResponse( |
|
316 | - $storage, |
|
317 | - Http::STATUS_OK |
|
318 | - ); |
|
319 | - } |
|
315 | + return new DataResponse( |
|
316 | + $storage, |
|
317 | + Http::STATUS_OK |
|
318 | + ); |
|
319 | + } |
|
320 | 320 | |
321 | - /** |
|
322 | - * Deletes the storage with the given id. |
|
323 | - * |
|
324 | - * @param int $id storage id |
|
325 | - * |
|
326 | - * @return DataResponse |
|
327 | - */ |
|
328 | - public function destroy($id) { |
|
329 | - try { |
|
330 | - $this->service->removeStorage($id); |
|
331 | - } catch (NotFoundException $e) { |
|
332 | - return new DataResponse( |
|
333 | - [ |
|
334 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
335 | - ], |
|
336 | - Http::STATUS_NOT_FOUND |
|
337 | - ); |
|
338 | - } |
|
321 | + /** |
|
322 | + * Deletes the storage with the given id. |
|
323 | + * |
|
324 | + * @param int $id storage id |
|
325 | + * |
|
326 | + * @return DataResponse |
|
327 | + */ |
|
328 | + public function destroy($id) { |
|
329 | + try { |
|
330 | + $this->service->removeStorage($id); |
|
331 | + } catch (NotFoundException $e) { |
|
332 | + return new DataResponse( |
|
333 | + [ |
|
334 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
335 | + ], |
|
336 | + Http::STATUS_NOT_FOUND |
|
337 | + ); |
|
338 | + } |
|
339 | 339 | |
340 | - return new DataResponse([], Http::STATUS_NO_CONTENT); |
|
341 | - } |
|
340 | + return new DataResponse([], Http::STATUS_NO_CONTENT); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | } |
344 | 344 |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $this->logger->logException($e); |
128 | 128 | return new DataResponse( |
129 | 129 | [ |
130 | - 'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class') |
|
130 | + 'message' => (string) $this->l10n->t('Invalid backend or authentication mechanism class') |
|
131 | 131 | ], |
132 | 132 | Http::STATUS_UNPROCESSABLE_ENTITY |
133 | 133 | ); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | if ($mountPoint === '') { |
147 | 147 | return new DataResponse( |
148 | 148 | array( |
149 | - 'message' => (string)$this->l10n->t('Invalid mount point') |
|
149 | + 'message' => (string) $this->l10n->t('Invalid mount point') |
|
150 | 150 | ), |
151 | 151 | Http::STATUS_UNPROCESSABLE_ENTITY |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | // objectstore must not be sent from client side |
157 | 157 | return new DataResponse( |
158 | 158 | array( |
159 | - 'message' => (string)$this->l10n->t('Objectstore forbidden') |
|
159 | + 'message' => (string) $this->l10n->t('Objectstore forbidden') |
|
160 | 160 | ), |
161 | 161 | Http::STATUS_UNPROCESSABLE_ENTITY |
162 | 162 | ); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | // invalid backend |
171 | 171 | return new DataResponse( |
172 | 172 | array( |
173 | - 'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [ |
|
173 | + 'message' => (string) $this->l10n->t('Invalid storage backend "%s"', [ |
|
174 | 174 | $backend->getIdentifier() |
175 | 175 | ]) |
176 | 176 | ), |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | // not permitted to use backend |
183 | 183 | return new DataResponse( |
184 | 184 | array( |
185 | - 'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [ |
|
185 | + 'message' => (string) $this->l10n->t('Not permitted to use backend "%s"', [ |
|
186 | 186 | $backend->getIdentifier() |
187 | 187 | ]) |
188 | 188 | ), |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | // not permitted to use auth mechanism |
194 | 194 | return new DataResponse( |
195 | 195 | array( |
196 | - 'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [ |
|
196 | + 'message' => (string) $this->l10n->t('Not permitted to use authentication mechanism "%s"', [ |
|
197 | 197 | $authMechanism->getIdentifier() |
198 | 198 | ]) |
199 | 199 | ), |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | // unsatisfied parameters |
206 | 206 | return new DataResponse( |
207 | 207 | array( |
208 | - 'message' => (string)$this->l10n->t('Unsatisfied backend parameters') |
|
208 | + 'message' => (string) $this->l10n->t('Unsatisfied backend parameters') |
|
209 | 209 | ), |
210 | 210 | Http::STATUS_UNPROCESSABLE_ENTITY |
211 | 211 | ); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | // unsatisfied parameters |
215 | 215 | return new DataResponse( |
216 | 216 | [ |
217 | - 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters') |
|
217 | + 'message' => (string) $this->l10n->t('Unsatisfied authentication mechanism parameters') |
|
218 | 218 | ], |
219 | 219 | Http::STATUS_UNPROCESSABLE_ENTITY |
220 | 220 | ); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } catch (NotFoundException $e) { |
307 | 307 | return new DataResponse( |
308 | 308 | [ |
309 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
309 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
310 | 310 | ], |
311 | 311 | Http::STATUS_NOT_FOUND |
312 | 312 | ); |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | } catch (NotFoundException $e) { |
332 | 332 | return new DataResponse( |
333 | 333 | [ |
334 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
334 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
335 | 335 | ], |
336 | 336 | Http::STATUS_NOT_FOUND |
337 | 337 | ); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | } catch (NotFoundException $e) { |
123 | 123 | return new DataResponse( |
124 | 124 | [ |
125 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
125 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
126 | 126 | ], |
127 | 127 | Http::STATUS_NOT_FOUND |
128 | 128 | ); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } else { |
163 | 163 | return new DataResponse( |
164 | 164 | [ |
165 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
165 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
166 | 166 | ], |
167 | 167 | Http::STATUS_FORBIDDEN |
168 | 168 | ); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } catch (NotFoundException $e) { |
171 | 171 | return new DataResponse( |
172 | 172 | [ |
173 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
173 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
174 | 174 | ], |
175 | 175 | Http::STATUS_NOT_FOUND |
176 | 176 | ); |
@@ -44,165 +44,165 @@ |
||
44 | 44 | * User global storages controller |
45 | 45 | */ |
46 | 46 | class UserGlobalStoragesController extends StoragesController { |
47 | - /** |
|
48 | - * @var IUserSession |
|
49 | - */ |
|
50 | - private $userSession; |
|
51 | - |
|
52 | - /** |
|
53 | - * Creates a new user global storages controller. |
|
54 | - * |
|
55 | - * @param string $AppName application name |
|
56 | - * @param IRequest $request request object |
|
57 | - * @param IL10N $l10n l10n service |
|
58 | - * @param UserGlobalStoragesService $userGlobalStoragesService storage service |
|
59 | - * @param IUserSession $userSession |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - $AppName, |
|
63 | - IRequest $request, |
|
64 | - IL10N $l10n, |
|
65 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
66 | - IUserSession $userSession, |
|
67 | - ILogger $logger |
|
68 | - ) { |
|
69 | - parent::__construct( |
|
70 | - $AppName, |
|
71 | - $request, |
|
72 | - $l10n, |
|
73 | - $userGlobalStoragesService, |
|
74 | - $logger |
|
75 | - ); |
|
76 | - $this->userSession = $userSession; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Get all storage entries |
|
81 | - * |
|
82 | - * @return DataResponse |
|
83 | - * |
|
84 | - * @NoAdminRequired |
|
85 | - */ |
|
86 | - public function index() { |
|
87 | - $storages = $this->service->getUniqueStorages(); |
|
88 | - |
|
89 | - // remove configuration data, this must be kept private |
|
90 | - foreach ($storages as $storage) { |
|
91 | - $this->sanitizeStorage($storage); |
|
92 | - } |
|
93 | - |
|
94 | - return new DataResponse( |
|
95 | - $storages, |
|
96 | - Http::STATUS_OK |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - protected function manipulateStorageConfig(StorageConfig $storage) { |
|
101 | - /** @var AuthMechanism */ |
|
102 | - $authMechanism = $storage->getAuthMechanism(); |
|
103 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
104 | - /** @var Backend */ |
|
105 | - $backend = $storage->getBackend(); |
|
106 | - $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get an external storage entry. |
|
111 | - * |
|
112 | - * @param int $id storage id |
|
113 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
114 | - * @return DataResponse |
|
115 | - * |
|
116 | - * @NoAdminRequired |
|
117 | - */ |
|
118 | - public function show($id, $testOnly = true) { |
|
119 | - try { |
|
120 | - $storage = $this->service->getStorage($id); |
|
121 | - |
|
122 | - $this->updateStorageStatus($storage, $testOnly); |
|
123 | - } catch (NotFoundException $e) { |
|
124 | - return new DataResponse( |
|
125 | - [ |
|
126 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
127 | - ], |
|
128 | - Http::STATUS_NOT_FOUND |
|
129 | - ); |
|
130 | - } |
|
131 | - |
|
132 | - $this->sanitizeStorage($storage); |
|
133 | - |
|
134 | - return new DataResponse( |
|
135 | - $storage, |
|
136 | - Http::STATUS_OK |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Update an external storage entry. |
|
142 | - * Only allows setting user provided backend fields |
|
143 | - * |
|
144 | - * @param int $id storage id |
|
145 | - * @param array $backendOptions backend-specific options |
|
146 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
147 | - * |
|
148 | - * @return DataResponse |
|
149 | - * |
|
150 | - * @NoAdminRequired |
|
151 | - */ |
|
152 | - public function update( |
|
153 | - $id, |
|
154 | - $backendOptions, |
|
155 | - $testOnly = true |
|
156 | - ) { |
|
157 | - try { |
|
158 | - $storage = $this->service->getStorage($id); |
|
159 | - $authMechanism = $storage->getAuthMechanism(); |
|
160 | - if ($authMechanism instanceof IUserProvided || $authMechanism instanceof UserGlobalAuth) { |
|
161 | - $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions); |
|
162 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
163 | - } else { |
|
164 | - return new DataResponse( |
|
165 | - [ |
|
166 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
167 | - ], |
|
168 | - Http::STATUS_FORBIDDEN |
|
169 | - ); |
|
170 | - } |
|
171 | - } catch (NotFoundException $e) { |
|
172 | - return new DataResponse( |
|
173 | - [ |
|
174 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
175 | - ], |
|
176 | - Http::STATUS_NOT_FOUND |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - $this->updateStorageStatus($storage, $testOnly); |
|
181 | - $this->sanitizeStorage($storage); |
|
182 | - |
|
183 | - return new DataResponse( |
|
184 | - $storage, |
|
185 | - Http::STATUS_OK |
|
186 | - ); |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Remove sensitive data from a StorageConfig before returning it to the user |
|
192 | - * |
|
193 | - * @param StorageConfig $storage |
|
194 | - */ |
|
195 | - protected function sanitizeStorage(StorageConfig $storage) { |
|
196 | - $storage->setBackendOptions([]); |
|
197 | - $storage->setMountOptions([]); |
|
198 | - |
|
199 | - if ($storage->getAuthMechanism() instanceof IUserProvided) { |
|
200 | - try { |
|
201 | - $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
202 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
203 | - // not configured yet |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
47 | + /** |
|
48 | + * @var IUserSession |
|
49 | + */ |
|
50 | + private $userSession; |
|
51 | + |
|
52 | + /** |
|
53 | + * Creates a new user global storages controller. |
|
54 | + * |
|
55 | + * @param string $AppName application name |
|
56 | + * @param IRequest $request request object |
|
57 | + * @param IL10N $l10n l10n service |
|
58 | + * @param UserGlobalStoragesService $userGlobalStoragesService storage service |
|
59 | + * @param IUserSession $userSession |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + $AppName, |
|
63 | + IRequest $request, |
|
64 | + IL10N $l10n, |
|
65 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
66 | + IUserSession $userSession, |
|
67 | + ILogger $logger |
|
68 | + ) { |
|
69 | + parent::__construct( |
|
70 | + $AppName, |
|
71 | + $request, |
|
72 | + $l10n, |
|
73 | + $userGlobalStoragesService, |
|
74 | + $logger |
|
75 | + ); |
|
76 | + $this->userSession = $userSession; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Get all storage entries |
|
81 | + * |
|
82 | + * @return DataResponse |
|
83 | + * |
|
84 | + * @NoAdminRequired |
|
85 | + */ |
|
86 | + public function index() { |
|
87 | + $storages = $this->service->getUniqueStorages(); |
|
88 | + |
|
89 | + // remove configuration data, this must be kept private |
|
90 | + foreach ($storages as $storage) { |
|
91 | + $this->sanitizeStorage($storage); |
|
92 | + } |
|
93 | + |
|
94 | + return new DataResponse( |
|
95 | + $storages, |
|
96 | + Http::STATUS_OK |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + protected function manipulateStorageConfig(StorageConfig $storage) { |
|
101 | + /** @var AuthMechanism */ |
|
102 | + $authMechanism = $storage->getAuthMechanism(); |
|
103 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
104 | + /** @var Backend */ |
|
105 | + $backend = $storage->getBackend(); |
|
106 | + $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get an external storage entry. |
|
111 | + * |
|
112 | + * @param int $id storage id |
|
113 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
114 | + * @return DataResponse |
|
115 | + * |
|
116 | + * @NoAdminRequired |
|
117 | + */ |
|
118 | + public function show($id, $testOnly = true) { |
|
119 | + try { |
|
120 | + $storage = $this->service->getStorage($id); |
|
121 | + |
|
122 | + $this->updateStorageStatus($storage, $testOnly); |
|
123 | + } catch (NotFoundException $e) { |
|
124 | + return new DataResponse( |
|
125 | + [ |
|
126 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
127 | + ], |
|
128 | + Http::STATUS_NOT_FOUND |
|
129 | + ); |
|
130 | + } |
|
131 | + |
|
132 | + $this->sanitizeStorage($storage); |
|
133 | + |
|
134 | + return new DataResponse( |
|
135 | + $storage, |
|
136 | + Http::STATUS_OK |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Update an external storage entry. |
|
142 | + * Only allows setting user provided backend fields |
|
143 | + * |
|
144 | + * @param int $id storage id |
|
145 | + * @param array $backendOptions backend-specific options |
|
146 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
147 | + * |
|
148 | + * @return DataResponse |
|
149 | + * |
|
150 | + * @NoAdminRequired |
|
151 | + */ |
|
152 | + public function update( |
|
153 | + $id, |
|
154 | + $backendOptions, |
|
155 | + $testOnly = true |
|
156 | + ) { |
|
157 | + try { |
|
158 | + $storage = $this->service->getStorage($id); |
|
159 | + $authMechanism = $storage->getAuthMechanism(); |
|
160 | + if ($authMechanism instanceof IUserProvided || $authMechanism instanceof UserGlobalAuth) { |
|
161 | + $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions); |
|
162 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
163 | + } else { |
|
164 | + return new DataResponse( |
|
165 | + [ |
|
166 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" is not user editable', array($id)) |
|
167 | + ], |
|
168 | + Http::STATUS_FORBIDDEN |
|
169 | + ); |
|
170 | + } |
|
171 | + } catch (NotFoundException $e) { |
|
172 | + return new DataResponse( |
|
173 | + [ |
|
174 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
175 | + ], |
|
176 | + Http::STATUS_NOT_FOUND |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + $this->updateStorageStatus($storage, $testOnly); |
|
181 | + $this->sanitizeStorage($storage); |
|
182 | + |
|
183 | + return new DataResponse( |
|
184 | + $storage, |
|
185 | + Http::STATUS_OK |
|
186 | + ); |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Remove sensitive data from a StorageConfig before returning it to the user |
|
192 | + * |
|
193 | + * @param StorageConfig $storage |
|
194 | + */ |
|
195 | + protected function sanitizeStorage(StorageConfig $storage) { |
|
196 | + $storage->setBackendOptions([]); |
|
197 | + $storage->setMountOptions([]); |
|
198 | + |
|
199 | + if ($storage->getAuthMechanism() instanceof IUserProvided) { |
|
200 | + try { |
|
201 | + $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
202 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
203 | + // not configured yet |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |