@@ -36,242 +36,242 @@ |
||
36 | 36 | * @package OC\AppFramework\routing |
37 | 37 | */ |
38 | 38 | class RouteConfig { |
39 | - /** @var DIContainer */ |
|
40 | - private $container; |
|
41 | - |
|
42 | - /** @var IRouter */ |
|
43 | - private $router; |
|
44 | - |
|
45 | - /** @var array */ |
|
46 | - private $routes; |
|
47 | - |
|
48 | - /** @var string */ |
|
49 | - private $appName; |
|
50 | - |
|
51 | - /** @var string[] */ |
|
52 | - private $controllerNameCache = []; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
56 | - * @param \OCP\Route\IRouter $router |
|
57 | - * @param array $routes |
|
58 | - * @internal param $appName |
|
59 | - */ |
|
60 | - public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
61 | - $this->routes = $routes; |
|
62 | - $this->container = $container; |
|
63 | - $this->router = $router; |
|
64 | - $this->appName = $container['AppName']; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * The routes and resource will be registered to the \OCP\Route\IRouter |
|
69 | - */ |
|
70 | - public function register() { |
|
71 | - |
|
72 | - // parse simple |
|
73 | - $this->processSimpleRoutes($this->routes); |
|
74 | - |
|
75 | - // parse resources |
|
76 | - $this->processResources($this->routes); |
|
77 | - |
|
78 | - /* |
|
39 | + /** @var DIContainer */ |
|
40 | + private $container; |
|
41 | + |
|
42 | + /** @var IRouter */ |
|
43 | + private $router; |
|
44 | + |
|
45 | + /** @var array */ |
|
46 | + private $routes; |
|
47 | + |
|
48 | + /** @var string */ |
|
49 | + private $appName; |
|
50 | + |
|
51 | + /** @var string[] */ |
|
52 | + private $controllerNameCache = []; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
56 | + * @param \OCP\Route\IRouter $router |
|
57 | + * @param array $routes |
|
58 | + * @internal param $appName |
|
59 | + */ |
|
60 | + public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
61 | + $this->routes = $routes; |
|
62 | + $this->container = $container; |
|
63 | + $this->router = $router; |
|
64 | + $this->appName = $container['AppName']; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * The routes and resource will be registered to the \OCP\Route\IRouter |
|
69 | + */ |
|
70 | + public function register() { |
|
71 | + |
|
72 | + // parse simple |
|
73 | + $this->processSimpleRoutes($this->routes); |
|
74 | + |
|
75 | + // parse resources |
|
76 | + $this->processResources($this->routes); |
|
77 | + |
|
78 | + /* |
|
79 | 79 | * OCS routes go into a different collection |
80 | 80 | */ |
81 | - $oldCollection = $this->router->getCurrentCollection(); |
|
82 | - $this->router->useCollection($oldCollection.'.ocs'); |
|
83 | - |
|
84 | - // parse ocs simple routes |
|
85 | - $this->processOCS($this->routes); |
|
86 | - |
|
87 | - $this->router->useCollection($oldCollection); |
|
88 | - } |
|
89 | - |
|
90 | - private function processOCS(array $routes) { |
|
91 | - $ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; |
|
92 | - foreach ($ocsRoutes as $ocsRoute) { |
|
93 | - $name = $ocsRoute['name']; |
|
94 | - $postfix = ''; |
|
95 | - |
|
96 | - if (isset($ocsRoute['postfix'])) { |
|
97 | - $postfix = $ocsRoute['postfix']; |
|
98 | - } |
|
99 | - |
|
100 | - if (isset($ocsRoute['root'])) { |
|
101 | - $root = $ocsRoute['root']; |
|
102 | - } else { |
|
103 | - $root = '/apps/'.$this->appName; |
|
104 | - } |
|
105 | - |
|
106 | - $url = $root . $ocsRoute['url']; |
|
107 | - $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
|
108 | - |
|
109 | - $split = explode('#', $name, 2); |
|
110 | - if (count($split) != 2) { |
|
111 | - throw new \UnexpectedValueException('Invalid route name'); |
|
112 | - } |
|
113 | - $controller = $split[0]; |
|
114 | - $action = $split[1]; |
|
115 | - |
|
116 | - $controllerName = $this->buildControllerName($controller); |
|
117 | - $actionName = $this->buildActionName($action); |
|
118 | - |
|
119 | - // register the route |
|
120 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
121 | - |
|
122 | - $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
123 | - ->method($verb) |
|
124 | - ->action($handler); |
|
125 | - |
|
126 | - // optionally register requirements for route. This is used to |
|
127 | - // tell the route parser how url parameters should be matched |
|
128 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
129 | - $router->requirements($ocsRoute['requirements']); |
|
130 | - } |
|
131 | - |
|
132 | - // optionally register defaults for route. This is used to |
|
133 | - // tell the route parser how url parameters should be default valued |
|
134 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
135 | - $router->defaults($ocsRoute['defaults']); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Creates one route base on the give configuration |
|
142 | - * @param array $routes |
|
143 | - * @throws \UnexpectedValueException |
|
144 | - */ |
|
145 | - private function processSimpleRoutes($routes) |
|
146 | - { |
|
147 | - $simpleRoutes = isset($routes['routes']) ? $routes['routes'] : array(); |
|
148 | - foreach ($simpleRoutes as $simpleRoute) { |
|
149 | - $name = $simpleRoute['name']; |
|
150 | - $postfix = ''; |
|
151 | - |
|
152 | - if (isset($simpleRoute['postfix'])) { |
|
153 | - $postfix = $simpleRoute['postfix']; |
|
154 | - } |
|
155 | - |
|
156 | - $url = $simpleRoute['url']; |
|
157 | - $verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET'; |
|
158 | - |
|
159 | - $split = explode('#', $name, 2); |
|
160 | - if (count($split) != 2) { |
|
161 | - throw new \UnexpectedValueException('Invalid route name'); |
|
162 | - } |
|
163 | - $controller = $split[0]; |
|
164 | - $action = $split[1]; |
|
165 | - |
|
166 | - $controllerName = $this->buildControllerName($controller); |
|
167 | - $actionName = $this->buildActionName($action); |
|
168 | - |
|
169 | - // register the route |
|
170 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
171 | - $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
172 | - ->method($verb) |
|
173 | - ->action($handler); |
|
174 | - |
|
175 | - // optionally register requirements for route. This is used to |
|
176 | - // tell the route parser how url parameters should be matched |
|
177 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
178 | - $router->requirements($simpleRoute['requirements']); |
|
179 | - } |
|
180 | - |
|
181 | - // optionally register defaults for route. This is used to |
|
182 | - // tell the route parser how url parameters should be default valued |
|
183 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
184 | - $router->defaults($simpleRoute['defaults']); |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * For a given name and url restful routes are created: |
|
191 | - * - index |
|
192 | - * - show |
|
193 | - * - new |
|
194 | - * - create |
|
195 | - * - update |
|
196 | - * - destroy |
|
197 | - * |
|
198 | - * @param array $routes |
|
199 | - */ |
|
200 | - private function processResources($routes) |
|
201 | - { |
|
202 | - // declaration of all restful actions |
|
203 | - $actions = array( |
|
204 | - array('name' => 'index', 'verb' => 'GET', 'on-collection' => true), |
|
205 | - array('name' => 'show', 'verb' => 'GET'), |
|
206 | - array('name' => 'create', 'verb' => 'POST', 'on-collection' => true), |
|
207 | - array('name' => 'update', 'verb' => 'PUT'), |
|
208 | - array('name' => 'destroy', 'verb' => 'DELETE'), |
|
209 | - ); |
|
210 | - |
|
211 | - $resources = isset($routes['resources']) ? $routes['resources'] : array(); |
|
212 | - foreach ($resources as $resource => $config) { |
|
213 | - |
|
214 | - // the url parameter used as id to the resource |
|
215 | - foreach($actions as $action) { |
|
216 | - $url = $config['url']; |
|
217 | - $method = $action['name']; |
|
218 | - $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
|
219 | - $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
|
220 | - if (!$collectionAction) { |
|
221 | - $url = $url . '/{id}'; |
|
222 | - } |
|
223 | - if (isset($action['url-postfix'])) { |
|
224 | - $url = $url . '/' . $action['url-postfix']; |
|
225 | - } |
|
226 | - |
|
227 | - $controller = $resource; |
|
228 | - |
|
229 | - $controllerName = $this->buildControllerName($controller); |
|
230 | - $actionName = $this->buildActionName($method); |
|
231 | - |
|
232 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
233 | - |
|
234 | - $this->router->create($routeName, $url)->method($verb)->action( |
|
235 | - new RouteActionHandler($this->container, $controllerName, $actionName) |
|
236 | - ); |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Based on a given route name the controller name is generated |
|
243 | - * @param string $controller |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - private function buildControllerName($controller) |
|
247 | - { |
|
248 | - if (!isset($this->controllerNameCache[$controller])) { |
|
249 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
250 | - } |
|
251 | - return $this->controllerNameCache[$controller]; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Based on the action part of the route name the controller method name is generated |
|
256 | - * @param string $action |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - private function buildActionName($action) { |
|
260 | - return $this->underScoreToCamelCase($action); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Underscored strings are converted to camel case strings |
|
265 | - * @param string $str |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - private function underScoreToCamelCase($str) { |
|
269 | - $pattern = "/_[a-z]?/"; |
|
270 | - return preg_replace_callback( |
|
271 | - $pattern, |
|
272 | - function ($matches) { |
|
273 | - return strtoupper(ltrim($matches[0], "_")); |
|
274 | - }, |
|
275 | - $str); |
|
276 | - } |
|
81 | + $oldCollection = $this->router->getCurrentCollection(); |
|
82 | + $this->router->useCollection($oldCollection.'.ocs'); |
|
83 | + |
|
84 | + // parse ocs simple routes |
|
85 | + $this->processOCS($this->routes); |
|
86 | + |
|
87 | + $this->router->useCollection($oldCollection); |
|
88 | + } |
|
89 | + |
|
90 | + private function processOCS(array $routes) { |
|
91 | + $ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; |
|
92 | + foreach ($ocsRoutes as $ocsRoute) { |
|
93 | + $name = $ocsRoute['name']; |
|
94 | + $postfix = ''; |
|
95 | + |
|
96 | + if (isset($ocsRoute['postfix'])) { |
|
97 | + $postfix = $ocsRoute['postfix']; |
|
98 | + } |
|
99 | + |
|
100 | + if (isset($ocsRoute['root'])) { |
|
101 | + $root = $ocsRoute['root']; |
|
102 | + } else { |
|
103 | + $root = '/apps/'.$this->appName; |
|
104 | + } |
|
105 | + |
|
106 | + $url = $root . $ocsRoute['url']; |
|
107 | + $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
|
108 | + |
|
109 | + $split = explode('#', $name, 2); |
|
110 | + if (count($split) != 2) { |
|
111 | + throw new \UnexpectedValueException('Invalid route name'); |
|
112 | + } |
|
113 | + $controller = $split[0]; |
|
114 | + $action = $split[1]; |
|
115 | + |
|
116 | + $controllerName = $this->buildControllerName($controller); |
|
117 | + $actionName = $this->buildActionName($action); |
|
118 | + |
|
119 | + // register the route |
|
120 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
121 | + |
|
122 | + $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
123 | + ->method($verb) |
|
124 | + ->action($handler); |
|
125 | + |
|
126 | + // optionally register requirements for route. This is used to |
|
127 | + // tell the route parser how url parameters should be matched |
|
128 | + if(array_key_exists('requirements', $ocsRoute)) { |
|
129 | + $router->requirements($ocsRoute['requirements']); |
|
130 | + } |
|
131 | + |
|
132 | + // optionally register defaults for route. This is used to |
|
133 | + // tell the route parser how url parameters should be default valued |
|
134 | + if(array_key_exists('defaults', $ocsRoute)) { |
|
135 | + $router->defaults($ocsRoute['defaults']); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Creates one route base on the give configuration |
|
142 | + * @param array $routes |
|
143 | + * @throws \UnexpectedValueException |
|
144 | + */ |
|
145 | + private function processSimpleRoutes($routes) |
|
146 | + { |
|
147 | + $simpleRoutes = isset($routes['routes']) ? $routes['routes'] : array(); |
|
148 | + foreach ($simpleRoutes as $simpleRoute) { |
|
149 | + $name = $simpleRoute['name']; |
|
150 | + $postfix = ''; |
|
151 | + |
|
152 | + if (isset($simpleRoute['postfix'])) { |
|
153 | + $postfix = $simpleRoute['postfix']; |
|
154 | + } |
|
155 | + |
|
156 | + $url = $simpleRoute['url']; |
|
157 | + $verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET'; |
|
158 | + |
|
159 | + $split = explode('#', $name, 2); |
|
160 | + if (count($split) != 2) { |
|
161 | + throw new \UnexpectedValueException('Invalid route name'); |
|
162 | + } |
|
163 | + $controller = $split[0]; |
|
164 | + $action = $split[1]; |
|
165 | + |
|
166 | + $controllerName = $this->buildControllerName($controller); |
|
167 | + $actionName = $this->buildActionName($action); |
|
168 | + |
|
169 | + // register the route |
|
170 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
171 | + $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
172 | + ->method($verb) |
|
173 | + ->action($handler); |
|
174 | + |
|
175 | + // optionally register requirements for route. This is used to |
|
176 | + // tell the route parser how url parameters should be matched |
|
177 | + if(array_key_exists('requirements', $simpleRoute)) { |
|
178 | + $router->requirements($simpleRoute['requirements']); |
|
179 | + } |
|
180 | + |
|
181 | + // optionally register defaults for route. This is used to |
|
182 | + // tell the route parser how url parameters should be default valued |
|
183 | + if(array_key_exists('defaults', $simpleRoute)) { |
|
184 | + $router->defaults($simpleRoute['defaults']); |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * For a given name and url restful routes are created: |
|
191 | + * - index |
|
192 | + * - show |
|
193 | + * - new |
|
194 | + * - create |
|
195 | + * - update |
|
196 | + * - destroy |
|
197 | + * |
|
198 | + * @param array $routes |
|
199 | + */ |
|
200 | + private function processResources($routes) |
|
201 | + { |
|
202 | + // declaration of all restful actions |
|
203 | + $actions = array( |
|
204 | + array('name' => 'index', 'verb' => 'GET', 'on-collection' => true), |
|
205 | + array('name' => 'show', 'verb' => 'GET'), |
|
206 | + array('name' => 'create', 'verb' => 'POST', 'on-collection' => true), |
|
207 | + array('name' => 'update', 'verb' => 'PUT'), |
|
208 | + array('name' => 'destroy', 'verb' => 'DELETE'), |
|
209 | + ); |
|
210 | + |
|
211 | + $resources = isset($routes['resources']) ? $routes['resources'] : array(); |
|
212 | + foreach ($resources as $resource => $config) { |
|
213 | + |
|
214 | + // the url parameter used as id to the resource |
|
215 | + foreach($actions as $action) { |
|
216 | + $url = $config['url']; |
|
217 | + $method = $action['name']; |
|
218 | + $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
|
219 | + $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
|
220 | + if (!$collectionAction) { |
|
221 | + $url = $url . '/{id}'; |
|
222 | + } |
|
223 | + if (isset($action['url-postfix'])) { |
|
224 | + $url = $url . '/' . $action['url-postfix']; |
|
225 | + } |
|
226 | + |
|
227 | + $controller = $resource; |
|
228 | + |
|
229 | + $controllerName = $this->buildControllerName($controller); |
|
230 | + $actionName = $this->buildActionName($method); |
|
231 | + |
|
232 | + $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
233 | + |
|
234 | + $this->router->create($routeName, $url)->method($verb)->action( |
|
235 | + new RouteActionHandler($this->container, $controllerName, $actionName) |
|
236 | + ); |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Based on a given route name the controller name is generated |
|
243 | + * @param string $controller |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + private function buildControllerName($controller) |
|
247 | + { |
|
248 | + if (!isset($this->controllerNameCache[$controller])) { |
|
249 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
250 | + } |
|
251 | + return $this->controllerNameCache[$controller]; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Based on the action part of the route name the controller method name is generated |
|
256 | + * @param string $action |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + private function buildActionName($action) { |
|
260 | + return $this->underScoreToCamelCase($action); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Underscored strings are converted to camel case strings |
|
265 | + * @param string $str |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + private function underScoreToCamelCase($str) { |
|
269 | + $pattern = "/_[a-z]?/"; |
|
270 | + return preg_replace_callback( |
|
271 | + $pattern, |
|
272 | + function ($matches) { |
|
273 | + return strtoupper(ltrim($matches[0], "_")); |
|
274 | + }, |
|
275 | + $str); |
|
276 | + } |
|
277 | 277 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $root = '/apps/'.$this->appName; |
104 | 104 | } |
105 | 105 | |
106 | - $url = $root . $ocsRoute['url']; |
|
106 | + $url = $root.$ocsRoute['url']; |
|
107 | 107 | $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
108 | 108 | |
109 | 109 | $split = explode('#', $name, 2); |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | // register the route |
120 | 120 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
121 | 121 | |
122 | - $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
122 | + $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action.$postfix, $url) |
|
123 | 123 | ->method($verb) |
124 | 124 | ->action($handler); |
125 | 125 | |
126 | 126 | // optionally register requirements for route. This is used to |
127 | 127 | // tell the route parser how url parameters should be matched |
128 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
128 | + if (array_key_exists('requirements', $ocsRoute)) { |
|
129 | 129 | $router->requirements($ocsRoute['requirements']); |
130 | 130 | } |
131 | 131 | |
132 | 132 | // optionally register defaults for route. This is used to |
133 | 133 | // tell the route parser how url parameters should be default valued |
134 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
134 | + if (array_key_exists('defaults', $ocsRoute)) { |
|
135 | 135 | $router->defaults($ocsRoute['defaults']); |
136 | 136 | } |
137 | 137 | } |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | |
169 | 169 | // register the route |
170 | 170 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
171 | - $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
171 | + $router = $this->router->create($this->appName.'.'.$controller.'.'.$action.$postfix, $url) |
|
172 | 172 | ->method($verb) |
173 | 173 | ->action($handler); |
174 | 174 | |
175 | 175 | // optionally register requirements for route. This is used to |
176 | 176 | // tell the route parser how url parameters should be matched |
177 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
177 | + if (array_key_exists('requirements', $simpleRoute)) { |
|
178 | 178 | $router->requirements($simpleRoute['requirements']); |
179 | 179 | } |
180 | 180 | |
181 | 181 | // optionally register defaults for route. This is used to |
182 | 182 | // tell the route parser how url parameters should be default valued |
183 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
183 | + if (array_key_exists('defaults', $simpleRoute)) { |
|
184 | 184 | $router->defaults($simpleRoute['defaults']); |
185 | 185 | } |
186 | 186 | } |
@@ -212,16 +212,16 @@ discard block |
||
212 | 212 | foreach ($resources as $resource => $config) { |
213 | 213 | |
214 | 214 | // the url parameter used as id to the resource |
215 | - foreach($actions as $action) { |
|
215 | + foreach ($actions as $action) { |
|
216 | 216 | $url = $config['url']; |
217 | 217 | $method = $action['name']; |
218 | 218 | $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
219 | 219 | $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
220 | 220 | if (!$collectionAction) { |
221 | - $url = $url . '/{id}'; |
|
221 | + $url = $url.'/{id}'; |
|
222 | 222 | } |
223 | 223 | if (isset($action['url-postfix'])) { |
224 | - $url = $url . '/' . $action['url-postfix']; |
|
224 | + $url = $url.'/'.$action['url-postfix']; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $controller = $resource; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $controllerName = $this->buildControllerName($controller); |
230 | 230 | $actionName = $this->buildActionName($method); |
231 | 231 | |
232 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
232 | + $routeName = $this->appName.'.'.strtolower($resource).'.'.strtolower($method); |
|
233 | 233 | |
234 | 234 | $this->router->create($routeName, $url)->method($verb)->action( |
235 | 235 | new RouteActionHandler($this->container, $controllerName, $actionName) |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | private function buildControllerName($controller) |
247 | 247 | { |
248 | 248 | if (!isset($this->controllerNameCache[$controller])) { |
249 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
249 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)).'Controller'; |
|
250 | 250 | } |
251 | 251 | return $this->controllerNameCache[$controller]; |
252 | 252 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $pattern = "/_[a-z]?/"; |
270 | 270 | return preg_replace_callback( |
271 | 271 | $pattern, |
272 | - function ($matches) { |
|
272 | + function($matches) { |
|
273 | 273 | return strtoupper(ltrim($matches[0], "_")); |
274 | 274 | }, |
275 | 275 | $str); |
@@ -27,35 +27,35 @@ |
||
27 | 27 | |
28 | 28 | class SettingsManager { |
29 | 29 | |
30 | - /** @var IConfig */ |
|
31 | - private $config; |
|
32 | - |
|
33 | - private $sendPasswordByMailDefault = 'yes'; |
|
34 | - |
|
35 | - private $enforcePasswordProtectionDefault = 'no'; |
|
36 | - |
|
37 | - public function __construct(IConfig $config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * should the password for a mail share be send to the recipient |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function sendPasswordByMail() { |
|
47 | - $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
48 | - return $sendPasswordByMail === 'yes'; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * do we require a share by mail to be password protected |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function enforcePasswordProtection() { |
|
57 | - $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
58 | - return $enforcePassword === 'yes'; |
|
59 | - } |
|
30 | + /** @var IConfig */ |
|
31 | + private $config; |
|
32 | + |
|
33 | + private $sendPasswordByMailDefault = 'yes'; |
|
34 | + |
|
35 | + private $enforcePasswordProtectionDefault = 'no'; |
|
36 | + |
|
37 | + public function __construct(IConfig $config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * should the password for a mail share be send to the recipient |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function sendPasswordByMail() { |
|
47 | + $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
48 | + return $sendPasswordByMail === 'yes'; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * do we require a share by mail to be password protected |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function enforcePasswordProtection() { |
|
57 | + $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
58 | + return $enforcePassword === 'yes'; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -27,42 +27,42 @@ |
||
27 | 27 | |
28 | 28 | class Admin implements ISettings { |
29 | 29 | |
30 | - /** @var SettingsManager */ |
|
31 | - private $settingsManager; |
|
30 | + /** @var SettingsManager */ |
|
31 | + private $settingsManager; |
|
32 | 32 | |
33 | - public function __construct(SettingsManager $settingsManager) { |
|
34 | - $this->settingsManager = $settingsManager; |
|
35 | - } |
|
33 | + public function __construct(SettingsManager $settingsManager) { |
|
34 | + $this->settingsManager = $settingsManager; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return TemplateResponse |
|
39 | - */ |
|
40 | - public function getForm() { |
|
37 | + /** |
|
38 | + * @return TemplateResponse |
|
39 | + */ |
|
40 | + public function getForm() { |
|
41 | 41 | |
42 | - $parameters = [ |
|
43 | - 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
44 | - 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
45 | - ]; |
|
42 | + $parameters = [ |
|
43 | + 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
44 | + 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
45 | + ]; |
|
46 | 46 | |
47 | - return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
48 | - } |
|
47 | + return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string the section ID, e.g. 'sharing' |
|
52 | - */ |
|
53 | - public function getSection() { |
|
54 | - return 'sharing'; |
|
55 | - } |
|
50 | + /** |
|
51 | + * @return string the section ID, e.g. 'sharing' |
|
52 | + */ |
|
53 | + public function getSection() { |
|
54 | + return 'sharing'; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return int whether the form should be rather on the top or bottom of |
|
59 | - * the admin section. The forms are arranged in ascending order of the |
|
60 | - * priority values. It is required to return a value between 0 and 100. |
|
61 | - * |
|
62 | - * E.g.: 70 |
|
63 | - */ |
|
64 | - public function getPriority() { |
|
65 | - return 40; |
|
66 | - } |
|
57 | + /** |
|
58 | + * @return int whether the form should be rather on the top or bottom of |
|
59 | + * the admin section. The forms are arranged in ascending order of the |
|
60 | + * priority values. It is required to return a value between 0 and 100. |
|
61 | + * |
|
62 | + * E.g.: 70 |
|
63 | + */ |
|
64 | + public function getPriority() { |
|
65 | + return 40; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -27,27 +27,27 @@ |
||
27 | 27 | |
28 | 28 | class Settings { |
29 | 29 | |
30 | - /** @var SettingsManager */ |
|
31 | - private $settingsManager; |
|
32 | - |
|
33 | - public function __construct(SettingsManager $settingsManager) { |
|
34 | - $this->settingsManager = $settingsManager; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * announce that the share-by-mail share provider is enabled |
|
39 | - * |
|
40 | - * @param array $settings |
|
41 | - */ |
|
42 | - public function announceShareProvider(array $settings) { |
|
43 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
44 | - $array['shareByMailEnabled'] = true; |
|
45 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
46 | - } |
|
47 | - |
|
48 | - public function announceShareByMailSettings(array $settings) { |
|
49 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
50 | - $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
51 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
52 | - } |
|
30 | + /** @var SettingsManager */ |
|
31 | + private $settingsManager; |
|
32 | + |
|
33 | + public function __construct(SettingsManager $settingsManager) { |
|
34 | + $this->settingsManager = $settingsManager; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * announce that the share-by-mail share provider is enabled |
|
39 | + * |
|
40 | + * @param array $settings |
|
41 | + */ |
|
42 | + public function announceShareProvider(array $settings) { |
|
43 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
44 | + $array['shareByMailEnabled'] = true; |
|
45 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
46 | + } |
|
47 | + |
|
48 | + public function announceShareByMailSettings(array $settings) { |
|
49 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
50 | + $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
51 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
52 | + } |
|
53 | 53 | } |
@@ -11,9 +11,9 @@ |
||
11 | 11 | <em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> /> |
|
15 | 15 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
16 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
17 | 17 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
18 | 18 | </p> |
19 | 19 |
@@ -11,9 +11,15 @@ |
||
11 | 11 | <em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) { |
|
15 | + p('checked'); |
|
16 | +} |
|
17 | +?> /> |
|
15 | 18 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
19 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) { |
|
20 | + p('checked'); |
|
21 | +} |
|
22 | +?> /> |
|
17 | 23 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
18 | 24 | </p> |
19 | 25 |
@@ -29,19 +29,19 @@ |
||
29 | 29 | |
30 | 30 | class Application extends App { |
31 | 31 | |
32 | - public function __construct(array $urlParams = array()) { |
|
33 | - parent::__construct('sharebymail', $urlParams); |
|
32 | + public function __construct(array $urlParams = array()) { |
|
33 | + parent::__construct('sharebymail', $urlParams); |
|
34 | 34 | |
35 | - $settingsManager = \OC::$server->query(Settings\SettingsManager::class); |
|
36 | - $settings = new Settings($settingsManager); |
|
35 | + $settingsManager = \OC::$server->query(Settings\SettingsManager::class); |
|
36 | + $settings = new Settings($settingsManager); |
|
37 | 37 | |
38 | - /** register capabilities */ |
|
39 | - $container = $this->getContainer(); |
|
40 | - $container->registerCapability('OCA\ShareByMail\Capabilities'); |
|
38 | + /** register capabilities */ |
|
39 | + $container = $this->getContainer(); |
|
40 | + $container->registerCapability('OCA\ShareByMail\Capabilities'); |
|
41 | 41 | |
42 | - /** register hooks */ |
|
43 | - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider'); |
|
44 | - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings'); |
|
45 | - } |
|
42 | + /** register hooks */ |
|
43 | + Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider'); |
|
44 | + Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings'); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -36,76 +36,76 @@ |
||
36 | 36 | |
37 | 37 | $application = new Application(); |
38 | 38 | $application->registerRoutes($this, [ |
39 | - 'resources' => [ |
|
40 | - 'users' => ['url' => '/settings/users/users'], |
|
41 | - 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
42 | - ], |
|
43 | - 'routes' => [ |
|
44 | - ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
45 | - ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
46 | - ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
47 | - ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
48 | - ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
49 | - ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
50 | - ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
51 | - ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
52 | - ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
53 | - ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
54 | - ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
55 | - ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
56 | - ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
57 | - ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
58 | - ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
59 | - ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
60 | - ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
61 | - ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
62 | - ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
63 | - ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
64 | - ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
65 | - ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
66 | - ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
67 | - ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
68 | - ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
69 | - ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
70 | - ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
71 | - ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
72 | - ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
73 | - ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
74 | - ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
75 | - ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
76 | - ] |
|
39 | + 'resources' => [ |
|
40 | + 'users' => ['url' => '/settings/users/users'], |
|
41 | + 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
42 | + ], |
|
43 | + 'routes' => [ |
|
44 | + ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
45 | + ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
46 | + ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
47 | + ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
48 | + ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
49 | + ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
50 | + ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
51 | + ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
52 | + ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
53 | + ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
54 | + ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
55 | + ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
56 | + ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
57 | + ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
58 | + ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
59 | + ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
60 | + ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
61 | + ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
62 | + ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
63 | + ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
64 | + ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
65 | + ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
66 | + ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
67 | + ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
68 | + ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
69 | + ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
70 | + ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
71 | + ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
72 | + ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
73 | + ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
74 | + ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
75 | + ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
76 | + ] |
|
77 | 77 | ]); |
78 | 78 | |
79 | 79 | /** @var $this \OCP\Route\IRouter */ |
80 | 80 | |
81 | 81 | // Settings pages |
82 | 82 | $this->create('settings_help', '/settings/help') |
83 | - ->actionInclude('settings/help.php'); |
|
83 | + ->actionInclude('settings/help.php'); |
|
84 | 84 | $this->create('settings_personal', '/settings/personal') |
85 | - ->actionInclude('settings/personal.php'); |
|
85 | + ->actionInclude('settings/personal.php'); |
|
86 | 86 | $this->create('settings_users', '/settings/users') |
87 | - ->actionInclude('settings/users.php'); |
|
87 | + ->actionInclude('settings/users.php'); |
|
88 | 88 | // Settings ajax actions |
89 | 89 | // users |
90 | 90 | $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php') |
91 | - ->actionInclude('settings/ajax/setquota.php'); |
|
91 | + ->actionInclude('settings/ajax/setquota.php'); |
|
92 | 92 | $this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php') |
93 | - ->actionInclude('settings/ajax/togglegroups.php'); |
|
93 | + ->actionInclude('settings/ajax/togglegroups.php'); |
|
94 | 94 | $this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php') |
95 | - ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
95 | + ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
96 | 96 | $this->create('settings_ajax_changegorupname', '/settings/ajax/changegroupname.php') |
97 | - ->actionInclude('settings/ajax/changegroupname.php'); |
|
97 | + ->actionInclude('settings/ajax/changegroupname.php'); |
|
98 | 98 | // apps |
99 | 99 | $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') |
100 | - ->actionInclude('settings/ajax/enableapp.php'); |
|
100 | + ->actionInclude('settings/ajax/enableapp.php'); |
|
101 | 101 | $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') |
102 | - ->actionInclude('settings/ajax/disableapp.php'); |
|
102 | + ->actionInclude('settings/ajax/disableapp.php'); |
|
103 | 103 | $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php') |
104 | - ->actionInclude('settings/ajax/updateapp.php'); |
|
104 | + ->actionInclude('settings/ajax/updateapp.php'); |
|
105 | 105 | $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php') |
106 | - ->actionInclude('settings/ajax/uninstallapp.php'); |
|
106 | + ->actionInclude('settings/ajax/uninstallapp.php'); |
|
107 | 107 | $this->create('settings_ajax_navigationdetect', '/settings/ajax/navigationdetect.php') |
108 | - ->actionInclude('settings/ajax/navigationdetect.php'); |
|
108 | + ->actionInclude('settings/ajax/navigationdetect.php'); |
|
109 | 109 | // admin |
110 | 110 | $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php') |
111 | - ->actionInclude('settings/ajax/excludegroups.php'); |
|
111 | + ->actionInclude('settings/ajax/excludegroups.php'); |
@@ -58,1383 +58,1383 @@ |
||
58 | 58 | */ |
59 | 59 | class Manager implements IManager { |
60 | 60 | |
61 | - /** @var IProviderFactory */ |
|
62 | - private $factory; |
|
63 | - /** @var ILogger */ |
|
64 | - private $logger; |
|
65 | - /** @var IConfig */ |
|
66 | - private $config; |
|
67 | - /** @var ISecureRandom */ |
|
68 | - private $secureRandom; |
|
69 | - /** @var IHasher */ |
|
70 | - private $hasher; |
|
71 | - /** @var IMountManager */ |
|
72 | - private $mountManager; |
|
73 | - /** @var IGroupManager */ |
|
74 | - private $groupManager; |
|
75 | - /** @var IL10N */ |
|
76 | - private $l; |
|
77 | - /** @var IUserManager */ |
|
78 | - private $userManager; |
|
79 | - /** @var IRootFolder */ |
|
80 | - private $rootFolder; |
|
81 | - /** @var CappedMemoryCache */ |
|
82 | - private $sharingDisabledForUsersCache; |
|
83 | - /** @var EventDispatcher */ |
|
84 | - private $eventDispatcher; |
|
85 | - /** @var LegacyHooks */ |
|
86 | - private $legacyHooks; |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Manager constructor. |
|
91 | - * |
|
92 | - * @param ILogger $logger |
|
93 | - * @param IConfig $config |
|
94 | - * @param ISecureRandom $secureRandom |
|
95 | - * @param IHasher $hasher |
|
96 | - * @param IMountManager $mountManager |
|
97 | - * @param IGroupManager $groupManager |
|
98 | - * @param IL10N $l |
|
99 | - * @param IProviderFactory $factory |
|
100 | - * @param IUserManager $userManager |
|
101 | - * @param IRootFolder $rootFolder |
|
102 | - * @param EventDispatcher $eventDispatcher |
|
103 | - */ |
|
104 | - public function __construct( |
|
105 | - ILogger $logger, |
|
106 | - IConfig $config, |
|
107 | - ISecureRandom $secureRandom, |
|
108 | - IHasher $hasher, |
|
109 | - IMountManager $mountManager, |
|
110 | - IGroupManager $groupManager, |
|
111 | - IL10N $l, |
|
112 | - IProviderFactory $factory, |
|
113 | - IUserManager $userManager, |
|
114 | - IRootFolder $rootFolder, |
|
115 | - EventDispatcher $eventDispatcher |
|
116 | - ) { |
|
117 | - $this->logger = $logger; |
|
118 | - $this->config = $config; |
|
119 | - $this->secureRandom = $secureRandom; |
|
120 | - $this->hasher = $hasher; |
|
121 | - $this->mountManager = $mountManager; |
|
122 | - $this->groupManager = $groupManager; |
|
123 | - $this->l = $l; |
|
124 | - $this->factory = $factory; |
|
125 | - $this->userManager = $userManager; |
|
126 | - $this->rootFolder = $rootFolder; |
|
127 | - $this->eventDispatcher = $eventDispatcher; |
|
128 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
129 | - $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
134 | - * |
|
135 | - * @param string $id |
|
136 | - * @return string[] |
|
137 | - */ |
|
138 | - private function splitFullId($id) { |
|
139 | - return explode(':', $id, 2); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Verify if a password meets all requirements |
|
144 | - * |
|
145 | - * @param string $password |
|
146 | - * @throws \Exception |
|
147 | - */ |
|
148 | - protected function verifyPassword($password) { |
|
149 | - if ($password === null) { |
|
150 | - // No password is set, check if this is allowed. |
|
151 | - if ($this->shareApiLinkEnforcePassword()) { |
|
152 | - throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
153 | - } |
|
154 | - |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - // Let others verify the password |
|
159 | - try { |
|
160 | - $event = new GenericEvent($password); |
|
161 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
162 | - } catch (HintException $e) { |
|
163 | - throw new \Exception($e->getHint()); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Check for generic requirements before creating a share |
|
169 | - * |
|
170 | - * @param \OCP\Share\IShare $share |
|
171 | - * @throws \InvalidArgumentException |
|
172 | - * @throws GenericShareException |
|
173 | - */ |
|
174 | - protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
175 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
176 | - // We expect a valid user as sharedWith for user shares |
|
177 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
178 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
179 | - } |
|
180 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
181 | - // We expect a valid group as sharedWith for group shares |
|
182 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
183 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
184 | - } |
|
185 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
186 | - if ($share->getSharedWith() !== null) { |
|
187 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
188 | - } |
|
189 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
190 | - if ($share->getSharedWith() === null) { |
|
191 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
192 | - } |
|
193 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
194 | - if ($share->getSharedWith() === null) { |
|
195 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
196 | - } |
|
197 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
198 | - $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); |
|
199 | - if ($circle === null) { |
|
200 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
201 | - } |
|
202 | - } else { |
|
203 | - // We can't handle other types yet |
|
204 | - throw new \InvalidArgumentException('unknown share type'); |
|
205 | - } |
|
206 | - |
|
207 | - // Verify the initiator of the share is set |
|
208 | - if ($share->getSharedBy() === null) { |
|
209 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
210 | - } |
|
211 | - |
|
212 | - // Cannot share with yourself |
|
213 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
214 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
215 | - throw new \InvalidArgumentException('Can\'t share with yourself'); |
|
216 | - } |
|
217 | - |
|
218 | - // The path should be set |
|
219 | - if ($share->getNode() === null) { |
|
220 | - throw new \InvalidArgumentException('Path should be set'); |
|
221 | - } |
|
222 | - |
|
223 | - // And it should be a file or a folder |
|
224 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
225 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
226 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
227 | - } |
|
228 | - |
|
229 | - // And you can't share your rootfolder |
|
230 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
231 | - $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
232 | - } else { |
|
233 | - $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
234 | - } |
|
235 | - if ($sharedPath === $share->getNode()->getPath()) { |
|
236 | - throw new \InvalidArgumentException('You can\'t share your root folder'); |
|
237 | - } |
|
238 | - |
|
239 | - // Check if we actually have share permissions |
|
240 | - if (!$share->getNode()->isShareable()) { |
|
241 | - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
242 | - throw new GenericShareException($message_t, $message_t, 404); |
|
243 | - } |
|
244 | - |
|
245 | - // Permissions should be set |
|
246 | - if ($share->getPermissions() === null) { |
|
247 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
248 | - } |
|
249 | - |
|
250 | - /* |
|
61 | + /** @var IProviderFactory */ |
|
62 | + private $factory; |
|
63 | + /** @var ILogger */ |
|
64 | + private $logger; |
|
65 | + /** @var IConfig */ |
|
66 | + private $config; |
|
67 | + /** @var ISecureRandom */ |
|
68 | + private $secureRandom; |
|
69 | + /** @var IHasher */ |
|
70 | + private $hasher; |
|
71 | + /** @var IMountManager */ |
|
72 | + private $mountManager; |
|
73 | + /** @var IGroupManager */ |
|
74 | + private $groupManager; |
|
75 | + /** @var IL10N */ |
|
76 | + private $l; |
|
77 | + /** @var IUserManager */ |
|
78 | + private $userManager; |
|
79 | + /** @var IRootFolder */ |
|
80 | + private $rootFolder; |
|
81 | + /** @var CappedMemoryCache */ |
|
82 | + private $sharingDisabledForUsersCache; |
|
83 | + /** @var EventDispatcher */ |
|
84 | + private $eventDispatcher; |
|
85 | + /** @var LegacyHooks */ |
|
86 | + private $legacyHooks; |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Manager constructor. |
|
91 | + * |
|
92 | + * @param ILogger $logger |
|
93 | + * @param IConfig $config |
|
94 | + * @param ISecureRandom $secureRandom |
|
95 | + * @param IHasher $hasher |
|
96 | + * @param IMountManager $mountManager |
|
97 | + * @param IGroupManager $groupManager |
|
98 | + * @param IL10N $l |
|
99 | + * @param IProviderFactory $factory |
|
100 | + * @param IUserManager $userManager |
|
101 | + * @param IRootFolder $rootFolder |
|
102 | + * @param EventDispatcher $eventDispatcher |
|
103 | + */ |
|
104 | + public function __construct( |
|
105 | + ILogger $logger, |
|
106 | + IConfig $config, |
|
107 | + ISecureRandom $secureRandom, |
|
108 | + IHasher $hasher, |
|
109 | + IMountManager $mountManager, |
|
110 | + IGroupManager $groupManager, |
|
111 | + IL10N $l, |
|
112 | + IProviderFactory $factory, |
|
113 | + IUserManager $userManager, |
|
114 | + IRootFolder $rootFolder, |
|
115 | + EventDispatcher $eventDispatcher |
|
116 | + ) { |
|
117 | + $this->logger = $logger; |
|
118 | + $this->config = $config; |
|
119 | + $this->secureRandom = $secureRandom; |
|
120 | + $this->hasher = $hasher; |
|
121 | + $this->mountManager = $mountManager; |
|
122 | + $this->groupManager = $groupManager; |
|
123 | + $this->l = $l; |
|
124 | + $this->factory = $factory; |
|
125 | + $this->userManager = $userManager; |
|
126 | + $this->rootFolder = $rootFolder; |
|
127 | + $this->eventDispatcher = $eventDispatcher; |
|
128 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
129 | + $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
134 | + * |
|
135 | + * @param string $id |
|
136 | + * @return string[] |
|
137 | + */ |
|
138 | + private function splitFullId($id) { |
|
139 | + return explode(':', $id, 2); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Verify if a password meets all requirements |
|
144 | + * |
|
145 | + * @param string $password |
|
146 | + * @throws \Exception |
|
147 | + */ |
|
148 | + protected function verifyPassword($password) { |
|
149 | + if ($password === null) { |
|
150 | + // No password is set, check if this is allowed. |
|
151 | + if ($this->shareApiLinkEnforcePassword()) { |
|
152 | + throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
153 | + } |
|
154 | + |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + // Let others verify the password |
|
159 | + try { |
|
160 | + $event = new GenericEvent($password); |
|
161 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
162 | + } catch (HintException $e) { |
|
163 | + throw new \Exception($e->getHint()); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Check for generic requirements before creating a share |
|
169 | + * |
|
170 | + * @param \OCP\Share\IShare $share |
|
171 | + * @throws \InvalidArgumentException |
|
172 | + * @throws GenericShareException |
|
173 | + */ |
|
174 | + protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
175 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
176 | + // We expect a valid user as sharedWith for user shares |
|
177 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
178 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
179 | + } |
|
180 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
181 | + // We expect a valid group as sharedWith for group shares |
|
182 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
183 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
184 | + } |
|
185 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
186 | + if ($share->getSharedWith() !== null) { |
|
187 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
188 | + } |
|
189 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
190 | + if ($share->getSharedWith() === null) { |
|
191 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
192 | + } |
|
193 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
194 | + if ($share->getSharedWith() === null) { |
|
195 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
196 | + } |
|
197 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
198 | + $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); |
|
199 | + if ($circle === null) { |
|
200 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
201 | + } |
|
202 | + } else { |
|
203 | + // We can't handle other types yet |
|
204 | + throw new \InvalidArgumentException('unknown share type'); |
|
205 | + } |
|
206 | + |
|
207 | + // Verify the initiator of the share is set |
|
208 | + if ($share->getSharedBy() === null) { |
|
209 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
210 | + } |
|
211 | + |
|
212 | + // Cannot share with yourself |
|
213 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
214 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
215 | + throw new \InvalidArgumentException('Can\'t share with yourself'); |
|
216 | + } |
|
217 | + |
|
218 | + // The path should be set |
|
219 | + if ($share->getNode() === null) { |
|
220 | + throw new \InvalidArgumentException('Path should be set'); |
|
221 | + } |
|
222 | + |
|
223 | + // And it should be a file or a folder |
|
224 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
225 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
226 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
227 | + } |
|
228 | + |
|
229 | + // And you can't share your rootfolder |
|
230 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
231 | + $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
232 | + } else { |
|
233 | + $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
234 | + } |
|
235 | + if ($sharedPath === $share->getNode()->getPath()) { |
|
236 | + throw new \InvalidArgumentException('You can\'t share your root folder'); |
|
237 | + } |
|
238 | + |
|
239 | + // Check if we actually have share permissions |
|
240 | + if (!$share->getNode()->isShareable()) { |
|
241 | + $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
242 | + throw new GenericShareException($message_t, $message_t, 404); |
|
243 | + } |
|
244 | + |
|
245 | + // Permissions should be set |
|
246 | + if ($share->getPermissions() === null) { |
|
247 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
248 | + } |
|
249 | + |
|
250 | + /* |
|
251 | 251 | * Quick fix for #23536 |
252 | 252 | * Non moveable mount points do not have update and delete permissions |
253 | 253 | * while we 'most likely' do have that on the storage. |
254 | 254 | */ |
255 | - $permissions = $share->getNode()->getPermissions(); |
|
256 | - $mount = $share->getNode()->getMountPoint(); |
|
257 | - if (!($mount instanceof MoveableMount)) { |
|
258 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
259 | - } |
|
260 | - |
|
261 | - // Check that we do not share with more permissions than we have |
|
262 | - if ($share->getPermissions() & ~$permissions) { |
|
263 | - $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); |
|
264 | - throw new GenericShareException($message_t, $message_t, 404); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - // Check that read permissions are always set |
|
269 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
270 | - $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
271 | - || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
272 | - if (!$noReadPermissionRequired && |
|
273 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
274 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
275 | - } |
|
276 | - |
|
277 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
278 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
279 | - $message_t = $this->l->t('Files can\'t be shared with delete permissions'); |
|
280 | - throw new GenericShareException($message_t); |
|
281 | - } |
|
282 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
283 | - $message_t = $this->l->t('Files can\'t be shared with create permissions'); |
|
284 | - throw new GenericShareException($message_t); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Validate if the expiration date fits the system settings |
|
291 | - * |
|
292 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
293 | - * @return \OCP\Share\IShare The modified share object |
|
294 | - * @throws GenericShareException |
|
295 | - * @throws \InvalidArgumentException |
|
296 | - * @throws \Exception |
|
297 | - */ |
|
298 | - protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
299 | - |
|
300 | - $expirationDate = $share->getExpirationDate(); |
|
301 | - |
|
302 | - if ($expirationDate !== null) { |
|
303 | - //Make sure the expiration date is a date |
|
304 | - $expirationDate->setTime(0, 0, 0); |
|
305 | - |
|
306 | - $date = new \DateTime(); |
|
307 | - $date->setTime(0, 0, 0); |
|
308 | - if ($date >= $expirationDate) { |
|
309 | - $message = $this->l->t('Expiration date is in the past'); |
|
310 | - throw new GenericShareException($message, $message, 404); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - // If expiredate is empty set a default one if there is a default |
|
315 | - $fullId = null; |
|
316 | - try { |
|
317 | - $fullId = $share->getFullId(); |
|
318 | - } catch (\UnexpectedValueException $e) { |
|
319 | - // This is a new share |
|
320 | - } |
|
321 | - |
|
322 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
323 | - $expirationDate = new \DateTime(); |
|
324 | - $expirationDate->setTime(0,0,0); |
|
325 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
326 | - } |
|
327 | - |
|
328 | - // If we enforce the expiration date check that is does not exceed |
|
329 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
330 | - if ($expirationDate === null) { |
|
331 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
332 | - } |
|
333 | - |
|
334 | - $date = new \DateTime(); |
|
335 | - $date->setTime(0, 0, 0); |
|
336 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
337 | - if ($date < $expirationDate) { |
|
338 | - $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
339 | - throw new GenericShareException($message, $message, 404); |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - $accepted = true; |
|
344 | - $message = ''; |
|
345 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
346 | - 'expirationDate' => &$expirationDate, |
|
347 | - 'accepted' => &$accepted, |
|
348 | - 'message' => &$message, |
|
349 | - 'passwordSet' => $share->getPassword() !== null, |
|
350 | - ]); |
|
351 | - |
|
352 | - if (!$accepted) { |
|
353 | - throw new \Exception($message); |
|
354 | - } |
|
355 | - |
|
356 | - $share->setExpirationDate($expirationDate); |
|
357 | - |
|
358 | - return $share; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Check for pre share requirements for user shares |
|
363 | - * |
|
364 | - * @param \OCP\Share\IShare $share |
|
365 | - * @throws \Exception |
|
366 | - */ |
|
367 | - protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
368 | - // Check if we can share with group members only |
|
369 | - if ($this->shareWithGroupMembersOnly()) { |
|
370 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
371 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
372 | - // Verify we can share with this user |
|
373 | - $groups = array_intersect( |
|
374 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
375 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
376 | - ); |
|
377 | - if (empty($groups)) { |
|
378 | - throw new \Exception('Only sharing with group members is allowed'); |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - /* |
|
255 | + $permissions = $share->getNode()->getPermissions(); |
|
256 | + $mount = $share->getNode()->getMountPoint(); |
|
257 | + if (!($mount instanceof MoveableMount)) { |
|
258 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
259 | + } |
|
260 | + |
|
261 | + // Check that we do not share with more permissions than we have |
|
262 | + if ($share->getPermissions() & ~$permissions) { |
|
263 | + $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); |
|
264 | + throw new GenericShareException($message_t, $message_t, 404); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + // Check that read permissions are always set |
|
269 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
270 | + $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
271 | + || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
272 | + if (!$noReadPermissionRequired && |
|
273 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
274 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
275 | + } |
|
276 | + |
|
277 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
278 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
279 | + $message_t = $this->l->t('Files can\'t be shared with delete permissions'); |
|
280 | + throw new GenericShareException($message_t); |
|
281 | + } |
|
282 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
283 | + $message_t = $this->l->t('Files can\'t be shared with create permissions'); |
|
284 | + throw new GenericShareException($message_t); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Validate if the expiration date fits the system settings |
|
291 | + * |
|
292 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
293 | + * @return \OCP\Share\IShare The modified share object |
|
294 | + * @throws GenericShareException |
|
295 | + * @throws \InvalidArgumentException |
|
296 | + * @throws \Exception |
|
297 | + */ |
|
298 | + protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
299 | + |
|
300 | + $expirationDate = $share->getExpirationDate(); |
|
301 | + |
|
302 | + if ($expirationDate !== null) { |
|
303 | + //Make sure the expiration date is a date |
|
304 | + $expirationDate->setTime(0, 0, 0); |
|
305 | + |
|
306 | + $date = new \DateTime(); |
|
307 | + $date->setTime(0, 0, 0); |
|
308 | + if ($date >= $expirationDate) { |
|
309 | + $message = $this->l->t('Expiration date is in the past'); |
|
310 | + throw new GenericShareException($message, $message, 404); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + // If expiredate is empty set a default one if there is a default |
|
315 | + $fullId = null; |
|
316 | + try { |
|
317 | + $fullId = $share->getFullId(); |
|
318 | + } catch (\UnexpectedValueException $e) { |
|
319 | + // This is a new share |
|
320 | + } |
|
321 | + |
|
322 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
323 | + $expirationDate = new \DateTime(); |
|
324 | + $expirationDate->setTime(0,0,0); |
|
325 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
326 | + } |
|
327 | + |
|
328 | + // If we enforce the expiration date check that is does not exceed |
|
329 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
330 | + if ($expirationDate === null) { |
|
331 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
332 | + } |
|
333 | + |
|
334 | + $date = new \DateTime(); |
|
335 | + $date->setTime(0, 0, 0); |
|
336 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
337 | + if ($date < $expirationDate) { |
|
338 | + $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
339 | + throw new GenericShareException($message, $message, 404); |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + $accepted = true; |
|
344 | + $message = ''; |
|
345 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
346 | + 'expirationDate' => &$expirationDate, |
|
347 | + 'accepted' => &$accepted, |
|
348 | + 'message' => &$message, |
|
349 | + 'passwordSet' => $share->getPassword() !== null, |
|
350 | + ]); |
|
351 | + |
|
352 | + if (!$accepted) { |
|
353 | + throw new \Exception($message); |
|
354 | + } |
|
355 | + |
|
356 | + $share->setExpirationDate($expirationDate); |
|
357 | + |
|
358 | + return $share; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Check for pre share requirements for user shares |
|
363 | + * |
|
364 | + * @param \OCP\Share\IShare $share |
|
365 | + * @throws \Exception |
|
366 | + */ |
|
367 | + protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
368 | + // Check if we can share with group members only |
|
369 | + if ($this->shareWithGroupMembersOnly()) { |
|
370 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
371 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
372 | + // Verify we can share with this user |
|
373 | + $groups = array_intersect( |
|
374 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
375 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
376 | + ); |
|
377 | + if (empty($groups)) { |
|
378 | + throw new \Exception('Only sharing with group members is allowed'); |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + /* |
|
383 | 383 | * TODO: Could be costly, fix |
384 | 384 | * |
385 | 385 | * Also this is not what we want in the future.. then we want to squash identical shares. |
386 | 386 | */ |
387 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
388 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
389 | - foreach($existingShares as $existingShare) { |
|
390 | - // Ignore if it is the same share |
|
391 | - try { |
|
392 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
393 | - continue; |
|
394 | - } |
|
395 | - } catch (\UnexpectedValueException $e) { |
|
396 | - //Shares are not identical |
|
397 | - } |
|
398 | - |
|
399 | - // Identical share already existst |
|
400 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
401 | - throw new \Exception('Path already shared with this user'); |
|
402 | - } |
|
403 | - |
|
404 | - // The share is already shared with this user via a group share |
|
405 | - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
406 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
407 | - if (!is_null($group)) { |
|
408 | - $user = $this->userManager->get($share->getSharedWith()); |
|
409 | - |
|
410 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
411 | - throw new \Exception('Path already shared with this user'); |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Check for pre share requirements for group shares |
|
420 | - * |
|
421 | - * @param \OCP\Share\IShare $share |
|
422 | - * @throws \Exception |
|
423 | - */ |
|
424 | - protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
425 | - // Verify group shares are allowed |
|
426 | - if (!$this->allowGroupSharing()) { |
|
427 | - throw new \Exception('Group sharing is now allowed'); |
|
428 | - } |
|
429 | - |
|
430 | - // Verify if the user can share with this group |
|
431 | - if ($this->shareWithGroupMembersOnly()) { |
|
432 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
433 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
434 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
435 | - throw new \Exception('Only sharing within your own groups is allowed'); |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - /* |
|
387 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
388 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
389 | + foreach($existingShares as $existingShare) { |
|
390 | + // Ignore if it is the same share |
|
391 | + try { |
|
392 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
393 | + continue; |
|
394 | + } |
|
395 | + } catch (\UnexpectedValueException $e) { |
|
396 | + //Shares are not identical |
|
397 | + } |
|
398 | + |
|
399 | + // Identical share already existst |
|
400 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
401 | + throw new \Exception('Path already shared with this user'); |
|
402 | + } |
|
403 | + |
|
404 | + // The share is already shared with this user via a group share |
|
405 | + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
406 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
407 | + if (!is_null($group)) { |
|
408 | + $user = $this->userManager->get($share->getSharedWith()); |
|
409 | + |
|
410 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
411 | + throw new \Exception('Path already shared with this user'); |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Check for pre share requirements for group shares |
|
420 | + * |
|
421 | + * @param \OCP\Share\IShare $share |
|
422 | + * @throws \Exception |
|
423 | + */ |
|
424 | + protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
425 | + // Verify group shares are allowed |
|
426 | + if (!$this->allowGroupSharing()) { |
|
427 | + throw new \Exception('Group sharing is now allowed'); |
|
428 | + } |
|
429 | + |
|
430 | + // Verify if the user can share with this group |
|
431 | + if ($this->shareWithGroupMembersOnly()) { |
|
432 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
433 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
434 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
435 | + throw new \Exception('Only sharing within your own groups is allowed'); |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + /* |
|
440 | 440 | * TODO: Could be costly, fix |
441 | 441 | * |
442 | 442 | * Also this is not what we want in the future.. then we want to squash identical shares. |
443 | 443 | */ |
444 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
445 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
446 | - foreach($existingShares as $existingShare) { |
|
447 | - try { |
|
448 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
449 | - continue; |
|
450 | - } |
|
451 | - } catch (\UnexpectedValueException $e) { |
|
452 | - //It is a new share so just continue |
|
453 | - } |
|
454 | - |
|
455 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
456 | - throw new \Exception('Path already shared with this group'); |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Check for pre share requirements for link shares |
|
463 | - * |
|
464 | - * @param \OCP\Share\IShare $share |
|
465 | - * @throws \Exception |
|
466 | - */ |
|
467 | - protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
468 | - // Are link shares allowed? |
|
469 | - if (!$this->shareApiAllowLinks()) { |
|
470 | - throw new \Exception('Link sharing not allowed'); |
|
471 | - } |
|
472 | - |
|
473 | - // Link shares by definition can't have share permissions |
|
474 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
475 | - throw new \InvalidArgumentException('Link shares can\'t have reshare permissions'); |
|
476 | - } |
|
477 | - |
|
478 | - // Check if public upload is allowed |
|
479 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
480 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
481 | - throw new \InvalidArgumentException('Public upload not allowed'); |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * To make sure we don't get invisible link shares we set the parent |
|
487 | - * of a link if it is a reshare. This is a quick word around |
|
488 | - * until we can properly display multiple link shares in the UI |
|
489 | - * |
|
490 | - * See: https://github.com/owncloud/core/issues/22295 |
|
491 | - * |
|
492 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
493 | - * |
|
494 | - * @param \OCP\Share\IShare $share |
|
495 | - */ |
|
496 | - protected function setLinkParent(\OCP\Share\IShare $share) { |
|
497 | - |
|
498 | - // No sense in checking if the method is not there. |
|
499 | - if (method_exists($share, 'setParent')) { |
|
500 | - $storage = $share->getNode()->getStorage(); |
|
501 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
502 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
503 | - $share->setParent($storage->getShareId()); |
|
504 | - } |
|
505 | - }; |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * @param File|Folder $path |
|
510 | - */ |
|
511 | - protected function pathCreateChecks($path) { |
|
512 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
513 | - if ($path instanceof \OCP\Files\Folder) { |
|
514 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
515 | - foreach($mounts as $mount) { |
|
516 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
517 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
518 | - } |
|
519 | - } |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Check if the user that is sharing can actually share |
|
525 | - * |
|
526 | - * @param \OCP\Share\IShare $share |
|
527 | - * @throws \Exception |
|
528 | - */ |
|
529 | - protected function canShare(\OCP\Share\IShare $share) { |
|
530 | - if (!$this->shareApiEnabled()) { |
|
531 | - throw new \Exception('The share API is disabled'); |
|
532 | - } |
|
533 | - |
|
534 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
535 | - throw new \Exception('You are not allowed to share'); |
|
536 | - } |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Share a path |
|
541 | - * |
|
542 | - * @param \OCP\Share\IShare $share |
|
543 | - * @return Share The share object |
|
544 | - * @throws \Exception |
|
545 | - * |
|
546 | - * TODO: handle link share permissions or check them |
|
547 | - */ |
|
548 | - public function createShare(\OCP\Share\IShare $share) { |
|
549 | - $this->canShare($share); |
|
550 | - |
|
551 | - $this->generalCreateChecks($share); |
|
552 | - |
|
553 | - // Verify if there are any issues with the path |
|
554 | - $this->pathCreateChecks($share->getNode()); |
|
555 | - |
|
556 | - /* |
|
444 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
445 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
446 | + foreach($existingShares as $existingShare) { |
|
447 | + try { |
|
448 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
449 | + continue; |
|
450 | + } |
|
451 | + } catch (\UnexpectedValueException $e) { |
|
452 | + //It is a new share so just continue |
|
453 | + } |
|
454 | + |
|
455 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
456 | + throw new \Exception('Path already shared with this group'); |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Check for pre share requirements for link shares |
|
463 | + * |
|
464 | + * @param \OCP\Share\IShare $share |
|
465 | + * @throws \Exception |
|
466 | + */ |
|
467 | + protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
468 | + // Are link shares allowed? |
|
469 | + if (!$this->shareApiAllowLinks()) { |
|
470 | + throw new \Exception('Link sharing not allowed'); |
|
471 | + } |
|
472 | + |
|
473 | + // Link shares by definition can't have share permissions |
|
474 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
475 | + throw new \InvalidArgumentException('Link shares can\'t have reshare permissions'); |
|
476 | + } |
|
477 | + |
|
478 | + // Check if public upload is allowed |
|
479 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
480 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
481 | + throw new \InvalidArgumentException('Public upload not allowed'); |
|
482 | + } |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * To make sure we don't get invisible link shares we set the parent |
|
487 | + * of a link if it is a reshare. This is a quick word around |
|
488 | + * until we can properly display multiple link shares in the UI |
|
489 | + * |
|
490 | + * See: https://github.com/owncloud/core/issues/22295 |
|
491 | + * |
|
492 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
493 | + * |
|
494 | + * @param \OCP\Share\IShare $share |
|
495 | + */ |
|
496 | + protected function setLinkParent(\OCP\Share\IShare $share) { |
|
497 | + |
|
498 | + // No sense in checking if the method is not there. |
|
499 | + if (method_exists($share, 'setParent')) { |
|
500 | + $storage = $share->getNode()->getStorage(); |
|
501 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
502 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
503 | + $share->setParent($storage->getShareId()); |
|
504 | + } |
|
505 | + }; |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * @param File|Folder $path |
|
510 | + */ |
|
511 | + protected function pathCreateChecks($path) { |
|
512 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
513 | + if ($path instanceof \OCP\Files\Folder) { |
|
514 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
515 | + foreach($mounts as $mount) { |
|
516 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
517 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
518 | + } |
|
519 | + } |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Check if the user that is sharing can actually share |
|
525 | + * |
|
526 | + * @param \OCP\Share\IShare $share |
|
527 | + * @throws \Exception |
|
528 | + */ |
|
529 | + protected function canShare(\OCP\Share\IShare $share) { |
|
530 | + if (!$this->shareApiEnabled()) { |
|
531 | + throw new \Exception('The share API is disabled'); |
|
532 | + } |
|
533 | + |
|
534 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
535 | + throw new \Exception('You are not allowed to share'); |
|
536 | + } |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Share a path |
|
541 | + * |
|
542 | + * @param \OCP\Share\IShare $share |
|
543 | + * @return Share The share object |
|
544 | + * @throws \Exception |
|
545 | + * |
|
546 | + * TODO: handle link share permissions or check them |
|
547 | + */ |
|
548 | + public function createShare(\OCP\Share\IShare $share) { |
|
549 | + $this->canShare($share); |
|
550 | + |
|
551 | + $this->generalCreateChecks($share); |
|
552 | + |
|
553 | + // Verify if there are any issues with the path |
|
554 | + $this->pathCreateChecks($share->getNode()); |
|
555 | + |
|
556 | + /* |
|
557 | 557 | * On creation of a share the owner is always the owner of the path |
558 | 558 | * Except for mounted federated shares. |
559 | 559 | */ |
560 | - $storage = $share->getNode()->getStorage(); |
|
561 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
562 | - $parent = $share->getNode()->getParent(); |
|
563 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
564 | - $parent = $parent->getParent(); |
|
565 | - } |
|
566 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
567 | - } else { |
|
568 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
569 | - } |
|
570 | - |
|
571 | - //Verify share type |
|
572 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
573 | - $this->userCreateChecks($share); |
|
574 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
575 | - $this->groupCreateChecks($share); |
|
576 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
577 | - $this->linkCreateChecks($share); |
|
578 | - $this->setLinkParent($share); |
|
579 | - |
|
580 | - /* |
|
560 | + $storage = $share->getNode()->getStorage(); |
|
561 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
562 | + $parent = $share->getNode()->getParent(); |
|
563 | + while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
564 | + $parent = $parent->getParent(); |
|
565 | + } |
|
566 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
567 | + } else { |
|
568 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
569 | + } |
|
570 | + |
|
571 | + //Verify share type |
|
572 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
573 | + $this->userCreateChecks($share); |
|
574 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
575 | + $this->groupCreateChecks($share); |
|
576 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
577 | + $this->linkCreateChecks($share); |
|
578 | + $this->setLinkParent($share); |
|
579 | + |
|
580 | + /* |
|
581 | 581 | * For now ignore a set token. |
582 | 582 | */ |
583 | - $share->setToken( |
|
584 | - $this->secureRandom->generate( |
|
585 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
586 | - \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
587 | - \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
588 | - \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
589 | - ) |
|
590 | - ); |
|
591 | - |
|
592 | - //Verify the expiration date |
|
593 | - $this->validateExpirationDate($share); |
|
594 | - |
|
595 | - //Verify the password |
|
596 | - $this->verifyPassword($share->getPassword()); |
|
597 | - |
|
598 | - // If a password is set. Hash it! |
|
599 | - if ($share->getPassword() !== null) { |
|
600 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
601 | - } |
|
602 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
603 | - $share->setToken( |
|
604 | - $this->secureRandom->generate( |
|
605 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
606 | - \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
607 | - \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
608 | - \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
609 | - ) |
|
610 | - ); |
|
611 | - } |
|
612 | - |
|
613 | - // Cannot share with the owner |
|
614 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
615 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
616 | - throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
617 | - } |
|
618 | - |
|
619 | - // Generate the target |
|
620 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
621 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
622 | - $share->setTarget($target); |
|
623 | - |
|
624 | - // Pre share hook |
|
625 | - $run = true; |
|
626 | - $error = ''; |
|
627 | - $preHookData = [ |
|
628 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
629 | - 'itemSource' => $share->getNode()->getId(), |
|
630 | - 'shareType' => $share->getShareType(), |
|
631 | - 'uidOwner' => $share->getSharedBy(), |
|
632 | - 'permissions' => $share->getPermissions(), |
|
633 | - 'fileSource' => $share->getNode()->getId(), |
|
634 | - 'expiration' => $share->getExpirationDate(), |
|
635 | - 'token' => $share->getToken(), |
|
636 | - 'itemTarget' => $share->getTarget(), |
|
637 | - 'shareWith' => $share->getSharedWith(), |
|
638 | - 'run' => &$run, |
|
639 | - 'error' => &$error, |
|
640 | - ]; |
|
641 | - \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData); |
|
642 | - |
|
643 | - if ($run === false) { |
|
644 | - throw new \Exception($error); |
|
645 | - } |
|
646 | - |
|
647 | - $oldShare = $share; |
|
648 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
649 | - $share = $provider->create($share); |
|
650 | - //reuse the node we already have |
|
651 | - $share->setNode($oldShare->getNode()); |
|
652 | - |
|
653 | - // Post share hook |
|
654 | - $postHookData = [ |
|
655 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
656 | - 'itemSource' => $share->getNode()->getId(), |
|
657 | - 'shareType' => $share->getShareType(), |
|
658 | - 'uidOwner' => $share->getSharedBy(), |
|
659 | - 'permissions' => $share->getPermissions(), |
|
660 | - 'fileSource' => $share->getNode()->getId(), |
|
661 | - 'expiration' => $share->getExpirationDate(), |
|
662 | - 'token' => $share->getToken(), |
|
663 | - 'id' => $share->getId(), |
|
664 | - 'shareWith' => $share->getSharedWith(), |
|
665 | - 'itemTarget' => $share->getTarget(), |
|
666 | - 'fileTarget' => $share->getTarget(), |
|
667 | - ]; |
|
668 | - |
|
669 | - \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData); |
|
670 | - |
|
671 | - return $share; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Update a share |
|
676 | - * |
|
677 | - * @param \OCP\Share\IShare $share |
|
678 | - * @return \OCP\Share\IShare The share object |
|
679 | - * @throws \InvalidArgumentException |
|
680 | - */ |
|
681 | - public function updateShare(\OCP\Share\IShare $share) { |
|
682 | - $expirationDateUpdated = false; |
|
683 | - |
|
684 | - $this->canShare($share); |
|
685 | - |
|
686 | - try { |
|
687 | - $originalShare = $this->getShareById($share->getFullId()); |
|
688 | - } catch (\UnexpectedValueException $e) { |
|
689 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
690 | - } |
|
691 | - |
|
692 | - // We can't change the share type! |
|
693 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
694 | - throw new \InvalidArgumentException('Can\'t change share type'); |
|
695 | - } |
|
696 | - |
|
697 | - // We can only change the recipient on user shares |
|
698 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
699 | - $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
700 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
701 | - } |
|
702 | - |
|
703 | - // Cannot share with the owner |
|
704 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
705 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
706 | - throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
707 | - } |
|
708 | - |
|
709 | - $this->generalCreateChecks($share); |
|
710 | - |
|
711 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
712 | - $this->userCreateChecks($share); |
|
713 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
714 | - $this->groupCreateChecks($share); |
|
715 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
716 | - $this->linkCreateChecks($share); |
|
717 | - |
|
718 | - // Password updated. |
|
719 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
720 | - //Verify the password |
|
721 | - $this->verifyPassword($share->getPassword()); |
|
722 | - |
|
723 | - // If a password is set. Hash it! |
|
724 | - if ($share->getPassword() !== null) { |
|
725 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
726 | - } |
|
727 | - } |
|
728 | - |
|
729 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
730 | - //Verify the expiration date |
|
731 | - $this->validateExpirationDate($share); |
|
732 | - $expirationDateUpdated = true; |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - $plainTextPassword = null; |
|
737 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
738 | - // Password updated. |
|
739 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
740 | - //Verify the password |
|
741 | - $this->verifyPassword($share->getPassword()); |
|
742 | - |
|
743 | - // If a password is set. Hash it! |
|
744 | - if ($share->getPassword() !== null) { |
|
745 | - $plainTextPassword = $share->getPassword(); |
|
746 | - $share->setPassword($this->hasher->hash($plainTextPassword)); |
|
747 | - } |
|
748 | - } |
|
749 | - } |
|
750 | - |
|
751 | - $this->pathCreateChecks($share->getNode()); |
|
752 | - |
|
753 | - // Now update the share! |
|
754 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
755 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
756 | - $share = $provider->update($share, $plainTextPassword); |
|
757 | - } else { |
|
758 | - $share = $provider->update($share); |
|
759 | - } |
|
760 | - |
|
761 | - if ($expirationDateUpdated === true) { |
|
762 | - \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
763 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
764 | - 'itemSource' => $share->getNode()->getId(), |
|
765 | - 'date' => $share->getExpirationDate(), |
|
766 | - 'uidOwner' => $share->getSharedBy(), |
|
767 | - ]); |
|
768 | - } |
|
769 | - |
|
770 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
771 | - \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
772 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
773 | - 'itemSource' => $share->getNode()->getId(), |
|
774 | - 'uidOwner' => $share->getSharedBy(), |
|
775 | - 'token' => $share->getToken(), |
|
776 | - 'disabled' => is_null($share->getPassword()), |
|
777 | - ]); |
|
778 | - } |
|
779 | - |
|
780 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
781 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
782 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
783 | - } else { |
|
784 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
785 | - } |
|
786 | - \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
787 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
788 | - 'itemSource' => $share->getNode()->getId(), |
|
789 | - 'shareType' => $share->getShareType(), |
|
790 | - 'shareWith' => $share->getSharedWith(), |
|
791 | - 'uidOwner' => $share->getSharedBy(), |
|
792 | - 'permissions' => $share->getPermissions(), |
|
793 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
794 | - )); |
|
795 | - } |
|
796 | - |
|
797 | - return $share; |
|
798 | - } |
|
799 | - |
|
800 | - /** |
|
801 | - * Delete all the children of this share |
|
802 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
803 | - * |
|
804 | - * @param \OCP\Share\IShare $share |
|
805 | - * @return \OCP\Share\IShare[] List of deleted shares |
|
806 | - */ |
|
807 | - protected function deleteChildren(\OCP\Share\IShare $share) { |
|
808 | - $deletedShares = []; |
|
809 | - |
|
810 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
811 | - |
|
812 | - foreach ($provider->getChildren($share) as $child) { |
|
813 | - $deletedChildren = $this->deleteChildren($child); |
|
814 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
815 | - |
|
816 | - $provider->delete($child); |
|
817 | - $deletedShares[] = $child; |
|
818 | - } |
|
819 | - |
|
820 | - return $deletedShares; |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Delete a share |
|
825 | - * |
|
826 | - * @param \OCP\Share\IShare $share |
|
827 | - * @throws ShareNotFound |
|
828 | - * @throws \InvalidArgumentException |
|
829 | - */ |
|
830 | - public function deleteShare(\OCP\Share\IShare $share) { |
|
831 | - |
|
832 | - try { |
|
833 | - $share->getFullId(); |
|
834 | - } catch (\UnexpectedValueException $e) { |
|
835 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
836 | - } |
|
837 | - |
|
838 | - $event = new GenericEvent($share); |
|
839 | - $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
840 | - |
|
841 | - // Get all children and delete them as well |
|
842 | - $deletedShares = $this->deleteChildren($share); |
|
843 | - |
|
844 | - // Do the actual delete |
|
845 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
846 | - $provider->delete($share); |
|
847 | - |
|
848 | - // All the deleted shares caused by this delete |
|
849 | - $deletedShares[] = $share; |
|
850 | - |
|
851 | - // Emit post hook |
|
852 | - $event->setArgument('deletedShares', $deletedShares); |
|
853 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * Unshare a file as the recipient. |
|
859 | - * This can be different from a regular delete for example when one of |
|
860 | - * the users in a groups deletes that share. But the provider should |
|
861 | - * handle this. |
|
862 | - * |
|
863 | - * @param \OCP\Share\IShare $share |
|
864 | - * @param string $recipientId |
|
865 | - */ |
|
866 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
867 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
868 | - $provider = $this->factory->getProvider($providerId); |
|
869 | - |
|
870 | - $provider->deleteFromSelf($share, $recipientId); |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * @inheritdoc |
|
875 | - */ |
|
876 | - public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
877 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
878 | - throw new \InvalidArgumentException('Can\'t change target of link share'); |
|
879 | - } |
|
880 | - |
|
881 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
882 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
883 | - } |
|
884 | - |
|
885 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
886 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
887 | - if (is_null($sharedWith)) { |
|
888 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
889 | - } |
|
890 | - $recipient = $this->userManager->get($recipientId); |
|
891 | - if (!$sharedWith->inGroup($recipient)) { |
|
892 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
897 | - $provider = $this->factory->getProvider($providerId); |
|
898 | - |
|
899 | - $provider->move($share, $recipientId); |
|
900 | - } |
|
901 | - |
|
902 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
903 | - $providers = $this->factory->getAllProviders(); |
|
904 | - |
|
905 | - return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
906 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
907 | - foreach ($newShares as $fid => $data) { |
|
908 | - if (!isset($shares[$fid])) { |
|
909 | - $shares[$fid] = []; |
|
910 | - } |
|
911 | - |
|
912 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
913 | - } |
|
914 | - return $shares; |
|
915 | - }, []); |
|
916 | - } |
|
917 | - |
|
918 | - /** |
|
919 | - * @inheritdoc |
|
920 | - */ |
|
921 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
922 | - if ($path !== null && |
|
923 | - !($path instanceof \OCP\Files\File) && |
|
924 | - !($path instanceof \OCP\Files\Folder)) { |
|
925 | - throw new \InvalidArgumentException('invalid path'); |
|
926 | - } |
|
927 | - |
|
928 | - try { |
|
929 | - $provider = $this->factory->getProviderForType($shareType); |
|
930 | - } catch (ProviderException $e) { |
|
931 | - return []; |
|
932 | - } |
|
933 | - |
|
934 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
935 | - |
|
936 | - /* |
|
583 | + $share->setToken( |
|
584 | + $this->secureRandom->generate( |
|
585 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
586 | + \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
587 | + \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
588 | + \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
589 | + ) |
|
590 | + ); |
|
591 | + |
|
592 | + //Verify the expiration date |
|
593 | + $this->validateExpirationDate($share); |
|
594 | + |
|
595 | + //Verify the password |
|
596 | + $this->verifyPassword($share->getPassword()); |
|
597 | + |
|
598 | + // If a password is set. Hash it! |
|
599 | + if ($share->getPassword() !== null) { |
|
600 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
601 | + } |
|
602 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
603 | + $share->setToken( |
|
604 | + $this->secureRandom->generate( |
|
605 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
606 | + \OCP\Security\ISecureRandom::CHAR_LOWER. |
|
607 | + \OCP\Security\ISecureRandom::CHAR_UPPER. |
|
608 | + \OCP\Security\ISecureRandom::CHAR_DIGITS |
|
609 | + ) |
|
610 | + ); |
|
611 | + } |
|
612 | + |
|
613 | + // Cannot share with the owner |
|
614 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
615 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
616 | + throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
617 | + } |
|
618 | + |
|
619 | + // Generate the target |
|
620 | + $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
621 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
622 | + $share->setTarget($target); |
|
623 | + |
|
624 | + // Pre share hook |
|
625 | + $run = true; |
|
626 | + $error = ''; |
|
627 | + $preHookData = [ |
|
628 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
629 | + 'itemSource' => $share->getNode()->getId(), |
|
630 | + 'shareType' => $share->getShareType(), |
|
631 | + 'uidOwner' => $share->getSharedBy(), |
|
632 | + 'permissions' => $share->getPermissions(), |
|
633 | + 'fileSource' => $share->getNode()->getId(), |
|
634 | + 'expiration' => $share->getExpirationDate(), |
|
635 | + 'token' => $share->getToken(), |
|
636 | + 'itemTarget' => $share->getTarget(), |
|
637 | + 'shareWith' => $share->getSharedWith(), |
|
638 | + 'run' => &$run, |
|
639 | + 'error' => &$error, |
|
640 | + ]; |
|
641 | + \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData); |
|
642 | + |
|
643 | + if ($run === false) { |
|
644 | + throw new \Exception($error); |
|
645 | + } |
|
646 | + |
|
647 | + $oldShare = $share; |
|
648 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
649 | + $share = $provider->create($share); |
|
650 | + //reuse the node we already have |
|
651 | + $share->setNode($oldShare->getNode()); |
|
652 | + |
|
653 | + // Post share hook |
|
654 | + $postHookData = [ |
|
655 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
656 | + 'itemSource' => $share->getNode()->getId(), |
|
657 | + 'shareType' => $share->getShareType(), |
|
658 | + 'uidOwner' => $share->getSharedBy(), |
|
659 | + 'permissions' => $share->getPermissions(), |
|
660 | + 'fileSource' => $share->getNode()->getId(), |
|
661 | + 'expiration' => $share->getExpirationDate(), |
|
662 | + 'token' => $share->getToken(), |
|
663 | + 'id' => $share->getId(), |
|
664 | + 'shareWith' => $share->getSharedWith(), |
|
665 | + 'itemTarget' => $share->getTarget(), |
|
666 | + 'fileTarget' => $share->getTarget(), |
|
667 | + ]; |
|
668 | + |
|
669 | + \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData); |
|
670 | + |
|
671 | + return $share; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Update a share |
|
676 | + * |
|
677 | + * @param \OCP\Share\IShare $share |
|
678 | + * @return \OCP\Share\IShare The share object |
|
679 | + * @throws \InvalidArgumentException |
|
680 | + */ |
|
681 | + public function updateShare(\OCP\Share\IShare $share) { |
|
682 | + $expirationDateUpdated = false; |
|
683 | + |
|
684 | + $this->canShare($share); |
|
685 | + |
|
686 | + try { |
|
687 | + $originalShare = $this->getShareById($share->getFullId()); |
|
688 | + } catch (\UnexpectedValueException $e) { |
|
689 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
690 | + } |
|
691 | + |
|
692 | + // We can't change the share type! |
|
693 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
694 | + throw new \InvalidArgumentException('Can\'t change share type'); |
|
695 | + } |
|
696 | + |
|
697 | + // We can only change the recipient on user shares |
|
698 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
699 | + $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
700 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
701 | + } |
|
702 | + |
|
703 | + // Cannot share with the owner |
|
704 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
705 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
706 | + throw new \InvalidArgumentException('Can\'t share with the share owner'); |
|
707 | + } |
|
708 | + |
|
709 | + $this->generalCreateChecks($share); |
|
710 | + |
|
711 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
712 | + $this->userCreateChecks($share); |
|
713 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
714 | + $this->groupCreateChecks($share); |
|
715 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
716 | + $this->linkCreateChecks($share); |
|
717 | + |
|
718 | + // Password updated. |
|
719 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
720 | + //Verify the password |
|
721 | + $this->verifyPassword($share->getPassword()); |
|
722 | + |
|
723 | + // If a password is set. Hash it! |
|
724 | + if ($share->getPassword() !== null) { |
|
725 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
726 | + } |
|
727 | + } |
|
728 | + |
|
729 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
730 | + //Verify the expiration date |
|
731 | + $this->validateExpirationDate($share); |
|
732 | + $expirationDateUpdated = true; |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + $plainTextPassword = null; |
|
737 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
738 | + // Password updated. |
|
739 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
740 | + //Verify the password |
|
741 | + $this->verifyPassword($share->getPassword()); |
|
742 | + |
|
743 | + // If a password is set. Hash it! |
|
744 | + if ($share->getPassword() !== null) { |
|
745 | + $plainTextPassword = $share->getPassword(); |
|
746 | + $share->setPassword($this->hasher->hash($plainTextPassword)); |
|
747 | + } |
|
748 | + } |
|
749 | + } |
|
750 | + |
|
751 | + $this->pathCreateChecks($share->getNode()); |
|
752 | + |
|
753 | + // Now update the share! |
|
754 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
755 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
756 | + $share = $provider->update($share, $plainTextPassword); |
|
757 | + } else { |
|
758 | + $share = $provider->update($share); |
|
759 | + } |
|
760 | + |
|
761 | + if ($expirationDateUpdated === true) { |
|
762 | + \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
763 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
764 | + 'itemSource' => $share->getNode()->getId(), |
|
765 | + 'date' => $share->getExpirationDate(), |
|
766 | + 'uidOwner' => $share->getSharedBy(), |
|
767 | + ]); |
|
768 | + } |
|
769 | + |
|
770 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
771 | + \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
772 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
773 | + 'itemSource' => $share->getNode()->getId(), |
|
774 | + 'uidOwner' => $share->getSharedBy(), |
|
775 | + 'token' => $share->getToken(), |
|
776 | + 'disabled' => is_null($share->getPassword()), |
|
777 | + ]); |
|
778 | + } |
|
779 | + |
|
780 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
781 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
782 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
783 | + } else { |
|
784 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
785 | + } |
|
786 | + \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
787 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
788 | + 'itemSource' => $share->getNode()->getId(), |
|
789 | + 'shareType' => $share->getShareType(), |
|
790 | + 'shareWith' => $share->getSharedWith(), |
|
791 | + 'uidOwner' => $share->getSharedBy(), |
|
792 | + 'permissions' => $share->getPermissions(), |
|
793 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
794 | + )); |
|
795 | + } |
|
796 | + |
|
797 | + return $share; |
|
798 | + } |
|
799 | + |
|
800 | + /** |
|
801 | + * Delete all the children of this share |
|
802 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
803 | + * |
|
804 | + * @param \OCP\Share\IShare $share |
|
805 | + * @return \OCP\Share\IShare[] List of deleted shares |
|
806 | + */ |
|
807 | + protected function deleteChildren(\OCP\Share\IShare $share) { |
|
808 | + $deletedShares = []; |
|
809 | + |
|
810 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
811 | + |
|
812 | + foreach ($provider->getChildren($share) as $child) { |
|
813 | + $deletedChildren = $this->deleteChildren($child); |
|
814 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
815 | + |
|
816 | + $provider->delete($child); |
|
817 | + $deletedShares[] = $child; |
|
818 | + } |
|
819 | + |
|
820 | + return $deletedShares; |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Delete a share |
|
825 | + * |
|
826 | + * @param \OCP\Share\IShare $share |
|
827 | + * @throws ShareNotFound |
|
828 | + * @throws \InvalidArgumentException |
|
829 | + */ |
|
830 | + public function deleteShare(\OCP\Share\IShare $share) { |
|
831 | + |
|
832 | + try { |
|
833 | + $share->getFullId(); |
|
834 | + } catch (\UnexpectedValueException $e) { |
|
835 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
836 | + } |
|
837 | + |
|
838 | + $event = new GenericEvent($share); |
|
839 | + $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
840 | + |
|
841 | + // Get all children and delete them as well |
|
842 | + $deletedShares = $this->deleteChildren($share); |
|
843 | + |
|
844 | + // Do the actual delete |
|
845 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
846 | + $provider->delete($share); |
|
847 | + |
|
848 | + // All the deleted shares caused by this delete |
|
849 | + $deletedShares[] = $share; |
|
850 | + |
|
851 | + // Emit post hook |
|
852 | + $event->setArgument('deletedShares', $deletedShares); |
|
853 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * Unshare a file as the recipient. |
|
859 | + * This can be different from a regular delete for example when one of |
|
860 | + * the users in a groups deletes that share. But the provider should |
|
861 | + * handle this. |
|
862 | + * |
|
863 | + * @param \OCP\Share\IShare $share |
|
864 | + * @param string $recipientId |
|
865 | + */ |
|
866 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
867 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
868 | + $provider = $this->factory->getProvider($providerId); |
|
869 | + |
|
870 | + $provider->deleteFromSelf($share, $recipientId); |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * @inheritdoc |
|
875 | + */ |
|
876 | + public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
877 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
878 | + throw new \InvalidArgumentException('Can\'t change target of link share'); |
|
879 | + } |
|
880 | + |
|
881 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
882 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
883 | + } |
|
884 | + |
|
885 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
886 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
887 | + if (is_null($sharedWith)) { |
|
888 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
889 | + } |
|
890 | + $recipient = $this->userManager->get($recipientId); |
|
891 | + if (!$sharedWith->inGroup($recipient)) { |
|
892 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
897 | + $provider = $this->factory->getProvider($providerId); |
|
898 | + |
|
899 | + $provider->move($share, $recipientId); |
|
900 | + } |
|
901 | + |
|
902 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
903 | + $providers = $this->factory->getAllProviders(); |
|
904 | + |
|
905 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
906 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
907 | + foreach ($newShares as $fid => $data) { |
|
908 | + if (!isset($shares[$fid])) { |
|
909 | + $shares[$fid] = []; |
|
910 | + } |
|
911 | + |
|
912 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
913 | + } |
|
914 | + return $shares; |
|
915 | + }, []); |
|
916 | + } |
|
917 | + |
|
918 | + /** |
|
919 | + * @inheritdoc |
|
920 | + */ |
|
921 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
922 | + if ($path !== null && |
|
923 | + !($path instanceof \OCP\Files\File) && |
|
924 | + !($path instanceof \OCP\Files\Folder)) { |
|
925 | + throw new \InvalidArgumentException('invalid path'); |
|
926 | + } |
|
927 | + |
|
928 | + try { |
|
929 | + $provider = $this->factory->getProviderForType($shareType); |
|
930 | + } catch (ProviderException $e) { |
|
931 | + return []; |
|
932 | + } |
|
933 | + |
|
934 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
935 | + |
|
936 | + /* |
|
937 | 937 | * Work around so we don't return expired shares but still follow |
938 | 938 | * proper pagination. |
939 | 939 | */ |
940 | 940 | |
941 | - $shares2 = []; |
|
942 | - |
|
943 | - while(true) { |
|
944 | - $added = 0; |
|
945 | - foreach ($shares as $share) { |
|
946 | - |
|
947 | - try { |
|
948 | - $this->checkExpireDate($share); |
|
949 | - } catch (ShareNotFound $e) { |
|
950 | - //Ignore since this basically means the share is deleted |
|
951 | - continue; |
|
952 | - } |
|
953 | - |
|
954 | - $added++; |
|
955 | - $shares2[] = $share; |
|
956 | - |
|
957 | - if (count($shares2) === $limit) { |
|
958 | - break; |
|
959 | - } |
|
960 | - } |
|
961 | - |
|
962 | - if (count($shares2) === $limit) { |
|
963 | - break; |
|
964 | - } |
|
965 | - |
|
966 | - // If there was no limit on the select we are done |
|
967 | - if ($limit === -1) { |
|
968 | - break; |
|
969 | - } |
|
970 | - |
|
971 | - $offset += $added; |
|
972 | - |
|
973 | - // Fetch again $limit shares |
|
974 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
975 | - |
|
976 | - // No more shares means we are done |
|
977 | - if (empty($shares)) { |
|
978 | - break; |
|
979 | - } |
|
980 | - } |
|
981 | - |
|
982 | - $shares = $shares2; |
|
983 | - |
|
984 | - return $shares; |
|
985 | - } |
|
986 | - |
|
987 | - /** |
|
988 | - * @inheritdoc |
|
989 | - */ |
|
990 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
991 | - try { |
|
992 | - $provider = $this->factory->getProviderForType($shareType); |
|
993 | - } catch (ProviderException $e) { |
|
994 | - return []; |
|
995 | - } |
|
996 | - |
|
997 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
998 | - |
|
999 | - // remove all shares which are already expired |
|
1000 | - foreach ($shares as $key => $share) { |
|
1001 | - try { |
|
1002 | - $this->checkExpireDate($share); |
|
1003 | - } catch (ShareNotFound $e) { |
|
1004 | - unset($shares[$key]); |
|
1005 | - } |
|
1006 | - } |
|
1007 | - |
|
1008 | - return $shares; |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * @inheritdoc |
|
1013 | - */ |
|
1014 | - public function getShareById($id, $recipient = null) { |
|
1015 | - if ($id === null) { |
|
1016 | - throw new ShareNotFound(); |
|
1017 | - } |
|
1018 | - |
|
1019 | - list($providerId, $id) = $this->splitFullId($id); |
|
1020 | - |
|
1021 | - try { |
|
1022 | - $provider = $this->factory->getProvider($providerId); |
|
1023 | - } catch (ProviderException $e) { |
|
1024 | - throw new ShareNotFound(); |
|
1025 | - } |
|
1026 | - |
|
1027 | - $share = $provider->getShareById($id, $recipient); |
|
1028 | - |
|
1029 | - $this->checkExpireDate($share); |
|
1030 | - |
|
1031 | - return $share; |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * Get all the shares for a given path |
|
1036 | - * |
|
1037 | - * @param \OCP\Files\Node $path |
|
1038 | - * @param int $page |
|
1039 | - * @param int $perPage |
|
1040 | - * |
|
1041 | - * @return Share[] |
|
1042 | - */ |
|
1043 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1044 | - return []; |
|
1045 | - } |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Get the share by token possible with password |
|
1049 | - * |
|
1050 | - * @param string $token |
|
1051 | - * @return Share |
|
1052 | - * |
|
1053 | - * @throws ShareNotFound |
|
1054 | - */ |
|
1055 | - public function getShareByToken($token) { |
|
1056 | - $share = null; |
|
1057 | - try { |
|
1058 | - if($this->shareApiAllowLinks()) { |
|
1059 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1060 | - $share = $provider->getShareByToken($token); |
|
1061 | - } |
|
1062 | - } catch (ProviderException $e) { |
|
1063 | - } catch (ShareNotFound $e) { |
|
1064 | - } |
|
1065 | - |
|
1066 | - |
|
1067 | - // If it is not a link share try to fetch a federated share by token |
|
1068 | - if ($share === null) { |
|
1069 | - try { |
|
1070 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1071 | - $share = $provider->getShareByToken($token); |
|
1072 | - } catch (ProviderException $e) { |
|
1073 | - } catch (ShareNotFound $e) { |
|
1074 | - } |
|
1075 | - } |
|
1076 | - |
|
1077 | - // If it is not a link share try to fetch a mail share by token |
|
1078 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1079 | - try { |
|
1080 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1081 | - $share = $provider->getShareByToken($token); |
|
1082 | - } catch (ProviderException $e) { |
|
1083 | - } catch (ShareNotFound $e) { |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - if ($share === null) { |
|
1088 | - throw new ShareNotFound(); |
|
1089 | - } |
|
1090 | - |
|
1091 | - $this->checkExpireDate($share); |
|
1092 | - |
|
1093 | - /* |
|
941 | + $shares2 = []; |
|
942 | + |
|
943 | + while(true) { |
|
944 | + $added = 0; |
|
945 | + foreach ($shares as $share) { |
|
946 | + |
|
947 | + try { |
|
948 | + $this->checkExpireDate($share); |
|
949 | + } catch (ShareNotFound $e) { |
|
950 | + //Ignore since this basically means the share is deleted |
|
951 | + continue; |
|
952 | + } |
|
953 | + |
|
954 | + $added++; |
|
955 | + $shares2[] = $share; |
|
956 | + |
|
957 | + if (count($shares2) === $limit) { |
|
958 | + break; |
|
959 | + } |
|
960 | + } |
|
961 | + |
|
962 | + if (count($shares2) === $limit) { |
|
963 | + break; |
|
964 | + } |
|
965 | + |
|
966 | + // If there was no limit on the select we are done |
|
967 | + if ($limit === -1) { |
|
968 | + break; |
|
969 | + } |
|
970 | + |
|
971 | + $offset += $added; |
|
972 | + |
|
973 | + // Fetch again $limit shares |
|
974 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
975 | + |
|
976 | + // No more shares means we are done |
|
977 | + if (empty($shares)) { |
|
978 | + break; |
|
979 | + } |
|
980 | + } |
|
981 | + |
|
982 | + $shares = $shares2; |
|
983 | + |
|
984 | + return $shares; |
|
985 | + } |
|
986 | + |
|
987 | + /** |
|
988 | + * @inheritdoc |
|
989 | + */ |
|
990 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
991 | + try { |
|
992 | + $provider = $this->factory->getProviderForType($shareType); |
|
993 | + } catch (ProviderException $e) { |
|
994 | + return []; |
|
995 | + } |
|
996 | + |
|
997 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
998 | + |
|
999 | + // remove all shares which are already expired |
|
1000 | + foreach ($shares as $key => $share) { |
|
1001 | + try { |
|
1002 | + $this->checkExpireDate($share); |
|
1003 | + } catch (ShareNotFound $e) { |
|
1004 | + unset($shares[$key]); |
|
1005 | + } |
|
1006 | + } |
|
1007 | + |
|
1008 | + return $shares; |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * @inheritdoc |
|
1013 | + */ |
|
1014 | + public function getShareById($id, $recipient = null) { |
|
1015 | + if ($id === null) { |
|
1016 | + throw new ShareNotFound(); |
|
1017 | + } |
|
1018 | + |
|
1019 | + list($providerId, $id) = $this->splitFullId($id); |
|
1020 | + |
|
1021 | + try { |
|
1022 | + $provider = $this->factory->getProvider($providerId); |
|
1023 | + } catch (ProviderException $e) { |
|
1024 | + throw new ShareNotFound(); |
|
1025 | + } |
|
1026 | + |
|
1027 | + $share = $provider->getShareById($id, $recipient); |
|
1028 | + |
|
1029 | + $this->checkExpireDate($share); |
|
1030 | + |
|
1031 | + return $share; |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * Get all the shares for a given path |
|
1036 | + * |
|
1037 | + * @param \OCP\Files\Node $path |
|
1038 | + * @param int $page |
|
1039 | + * @param int $perPage |
|
1040 | + * |
|
1041 | + * @return Share[] |
|
1042 | + */ |
|
1043 | + public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1044 | + return []; |
|
1045 | + } |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Get the share by token possible with password |
|
1049 | + * |
|
1050 | + * @param string $token |
|
1051 | + * @return Share |
|
1052 | + * |
|
1053 | + * @throws ShareNotFound |
|
1054 | + */ |
|
1055 | + public function getShareByToken($token) { |
|
1056 | + $share = null; |
|
1057 | + try { |
|
1058 | + if($this->shareApiAllowLinks()) { |
|
1059 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1060 | + $share = $provider->getShareByToken($token); |
|
1061 | + } |
|
1062 | + } catch (ProviderException $e) { |
|
1063 | + } catch (ShareNotFound $e) { |
|
1064 | + } |
|
1065 | + |
|
1066 | + |
|
1067 | + // If it is not a link share try to fetch a federated share by token |
|
1068 | + if ($share === null) { |
|
1069 | + try { |
|
1070 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1071 | + $share = $provider->getShareByToken($token); |
|
1072 | + } catch (ProviderException $e) { |
|
1073 | + } catch (ShareNotFound $e) { |
|
1074 | + } |
|
1075 | + } |
|
1076 | + |
|
1077 | + // If it is not a link share try to fetch a mail share by token |
|
1078 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1079 | + try { |
|
1080 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1081 | + $share = $provider->getShareByToken($token); |
|
1082 | + } catch (ProviderException $e) { |
|
1083 | + } catch (ShareNotFound $e) { |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + if ($share === null) { |
|
1088 | + throw new ShareNotFound(); |
|
1089 | + } |
|
1090 | + |
|
1091 | + $this->checkExpireDate($share); |
|
1092 | + |
|
1093 | + /* |
|
1094 | 1094 | * Reduce the permissions for link shares if public upload is not enabled |
1095 | 1095 | */ |
1096 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1097 | - !$this->shareApiLinkAllowPublicUpload()) { |
|
1098 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1099 | - } |
|
1100 | - |
|
1101 | - return $share; |
|
1102 | - } |
|
1103 | - |
|
1104 | - protected function checkExpireDate($share) { |
|
1105 | - if ($share->getExpirationDate() !== null && |
|
1106 | - $share->getExpirationDate() <= new \DateTime()) { |
|
1107 | - $this->deleteShare($share); |
|
1108 | - throw new ShareNotFound(); |
|
1109 | - } |
|
1110 | - |
|
1111 | - } |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * Verify the password of a public share |
|
1115 | - * |
|
1116 | - * @param \OCP\Share\IShare $share |
|
1117 | - * @param string $password |
|
1118 | - * @return bool |
|
1119 | - */ |
|
1120 | - public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1121 | - $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1122 | - || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1123 | - if (!$passwordProtected) { |
|
1124 | - //TODO maybe exception? |
|
1125 | - return false; |
|
1126 | - } |
|
1127 | - |
|
1128 | - if ($password === null || $share->getPassword() === null) { |
|
1129 | - return false; |
|
1130 | - } |
|
1131 | - |
|
1132 | - $newHash = ''; |
|
1133 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1134 | - return false; |
|
1135 | - } |
|
1136 | - |
|
1137 | - if (!empty($newHash)) { |
|
1138 | - $share->setPassword($newHash); |
|
1139 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1140 | - $provider->update($share); |
|
1141 | - } |
|
1142 | - |
|
1143 | - return true; |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * @inheritdoc |
|
1148 | - */ |
|
1149 | - public function userDeleted($uid) { |
|
1150 | - $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
1151 | - |
|
1152 | - foreach ($types as $type) { |
|
1153 | - try { |
|
1154 | - $provider = $this->factory->getProviderForType($type); |
|
1155 | - } catch (ProviderException $e) { |
|
1156 | - continue; |
|
1157 | - } |
|
1158 | - $provider->userDeleted($uid, $type); |
|
1159 | - } |
|
1160 | - } |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * @inheritdoc |
|
1164 | - */ |
|
1165 | - public function groupDeleted($gid) { |
|
1166 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1167 | - $provider->groupDeleted($gid); |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * @inheritdoc |
|
1172 | - */ |
|
1173 | - public function userDeletedFromGroup($uid, $gid) { |
|
1174 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1175 | - $provider->userDeletedFromGroup($uid, $gid); |
|
1176 | - } |
|
1177 | - |
|
1178 | - /** |
|
1179 | - * Get access list to a path. This means |
|
1180 | - * all the users that can access a given path. |
|
1181 | - * |
|
1182 | - * Consider: |
|
1183 | - * -root |
|
1184 | - * |-folder1 (23) |
|
1185 | - * |-folder2 (32) |
|
1186 | - * |-fileA (42) |
|
1187 | - * |
|
1188 | - * fileA is shared with user1 and user1@server1 |
|
1189 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
1190 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1191 | - * |
|
1192 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1193 | - * [ |
|
1194 | - * users => [ |
|
1195 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1196 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1197 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1198 | - * ], |
|
1199 | - * remote => [ |
|
1200 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1201 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1202 | - * ], |
|
1203 | - * public => bool |
|
1204 | - * mail => bool |
|
1205 | - * ] |
|
1206 | - * |
|
1207 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1208 | - * [ |
|
1209 | - * users => ['user1', 'user2', 'user4'], |
|
1210 | - * remote => bool, |
|
1211 | - * public => bool |
|
1212 | - * mail => bool |
|
1213 | - * ] |
|
1214 | - * |
|
1215 | - * This is required for encryption/activity |
|
1216 | - * |
|
1217 | - * @param \OCP\Files\Node $path |
|
1218 | - * @param bool $recursive Should we check all parent folders as well |
|
1219 | - * @param bool $currentAccess Should the user have currently access to the file |
|
1220 | - * @return array |
|
1221 | - */ |
|
1222 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1223 | - $owner = $path->getOwner()->getUID(); |
|
1224 | - |
|
1225 | - if ($currentAccess) { |
|
1226 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1227 | - } else { |
|
1228 | - $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1229 | - } |
|
1230 | - if (!$this->userManager->userExists($owner)) { |
|
1231 | - return $al; |
|
1232 | - } |
|
1233 | - |
|
1234 | - //Get node for the owner |
|
1235 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1236 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1237 | - $path = $userFolder->getById($path->getId())[0]; |
|
1238 | - } |
|
1239 | - |
|
1240 | - $providers = $this->factory->getAllProviders(); |
|
1241 | - |
|
1242 | - /** @var Node[] $nodes */ |
|
1243 | - $nodes = []; |
|
1244 | - |
|
1245 | - |
|
1246 | - if ($currentAccess) { |
|
1247 | - $ownerPath = $path->getPath(); |
|
1248 | - $ownerPath = explode('/', $ownerPath, 4); |
|
1249 | - if (count($ownerPath) < 4) { |
|
1250 | - $ownerPath = ''; |
|
1251 | - } else { |
|
1252 | - $ownerPath = $ownerPath[3]; |
|
1253 | - } |
|
1254 | - $al['users'][$owner] = [ |
|
1255 | - 'node_id' => $path->getId(), |
|
1256 | - 'node_path' => '/' . $ownerPath, |
|
1257 | - ]; |
|
1258 | - } else { |
|
1259 | - $al['users'][] = $owner; |
|
1260 | - } |
|
1261 | - |
|
1262 | - // Collect all the shares |
|
1263 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
1264 | - $nodes[] = $path; |
|
1265 | - if (!$recursive) { |
|
1266 | - break; |
|
1267 | - } |
|
1268 | - $path = $path->getParent(); |
|
1269 | - } |
|
1270 | - |
|
1271 | - foreach ($providers as $provider) { |
|
1272 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1273 | - |
|
1274 | - foreach ($tmp as $k => $v) { |
|
1275 | - if (isset($al[$k])) { |
|
1276 | - if (is_array($al[$k])) { |
|
1277 | - $al[$k] = array_merge($al[$k], $v); |
|
1278 | - } else { |
|
1279 | - $al[$k] = $al[$k] || $v; |
|
1280 | - } |
|
1281 | - } else { |
|
1282 | - $al[$k] = $v; |
|
1283 | - } |
|
1284 | - } |
|
1285 | - } |
|
1286 | - |
|
1287 | - return $al; |
|
1288 | - } |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Create a new share |
|
1292 | - * @return \OCP\Share\IShare; |
|
1293 | - */ |
|
1294 | - public function newShare() { |
|
1295 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Is the share API enabled |
|
1300 | - * |
|
1301 | - * @return bool |
|
1302 | - */ |
|
1303 | - public function shareApiEnabled() { |
|
1304 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Is public link sharing enabled |
|
1309 | - * |
|
1310 | - * @return bool |
|
1311 | - */ |
|
1312 | - public function shareApiAllowLinks() { |
|
1313 | - return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1314 | - } |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * Is password on public link requires |
|
1318 | - * |
|
1319 | - * @return bool |
|
1320 | - */ |
|
1321 | - public function shareApiLinkEnforcePassword() { |
|
1322 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1323 | - } |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Is default expire date enabled |
|
1327 | - * |
|
1328 | - * @return bool |
|
1329 | - */ |
|
1330 | - public function shareApiLinkDefaultExpireDate() { |
|
1331 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Is default expire date enforced |
|
1336 | - *` |
|
1337 | - * @return bool |
|
1338 | - */ |
|
1339 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
1340 | - return $this->shareApiLinkDefaultExpireDate() && |
|
1341 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Number of default expire days |
|
1346 | - *shareApiLinkAllowPublicUpload |
|
1347 | - * @return int |
|
1348 | - */ |
|
1349 | - public function shareApiLinkDefaultExpireDays() { |
|
1350 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1351 | - } |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Allow public upload on link shares |
|
1355 | - * |
|
1356 | - * @return bool |
|
1357 | - */ |
|
1358 | - public function shareApiLinkAllowPublicUpload() { |
|
1359 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * check if user can only share with group members |
|
1364 | - * @return bool |
|
1365 | - */ |
|
1366 | - public function shareWithGroupMembersOnly() { |
|
1367 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Check if users can share with groups |
|
1372 | - * @return bool |
|
1373 | - */ |
|
1374 | - public function allowGroupSharing() { |
|
1375 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
1380 | - * |
|
1381 | - * TODO: Deprecate fuction from OC_Util |
|
1382 | - * |
|
1383 | - * @param string $userId |
|
1384 | - * @return bool |
|
1385 | - */ |
|
1386 | - public function sharingDisabledForUser($userId) { |
|
1387 | - if ($userId === null) { |
|
1388 | - return false; |
|
1389 | - } |
|
1390 | - |
|
1391 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1392 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
1393 | - } |
|
1394 | - |
|
1395 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1396 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1397 | - $excludedGroups = json_decode($groupsList); |
|
1398 | - if (is_null($excludedGroups)) { |
|
1399 | - $excludedGroups = explode(',', $groupsList); |
|
1400 | - $newValue = json_encode($excludedGroups); |
|
1401 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1402 | - } |
|
1403 | - $user = $this->userManager->get($userId); |
|
1404 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1405 | - if (!empty($usersGroups)) { |
|
1406 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1407 | - // if the user is only in groups which are disabled for sharing then |
|
1408 | - // sharing is also disabled for the user |
|
1409 | - if (empty($remainingGroups)) { |
|
1410 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
1411 | - return true; |
|
1412 | - } |
|
1413 | - } |
|
1414 | - } |
|
1415 | - |
|
1416 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
1417 | - return false; |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * @inheritdoc |
|
1422 | - */ |
|
1423 | - public function outgoingServer2ServerSharesAllowed() { |
|
1424 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * @inheritdoc |
|
1429 | - */ |
|
1430 | - public function shareProviderExists($shareType) { |
|
1431 | - try { |
|
1432 | - $this->factory->getProviderForType($shareType); |
|
1433 | - } catch (ProviderException $e) { |
|
1434 | - return false; |
|
1435 | - } |
|
1436 | - |
|
1437 | - return true; |
|
1438 | - } |
|
1096 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1097 | + !$this->shareApiLinkAllowPublicUpload()) { |
|
1098 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1099 | + } |
|
1100 | + |
|
1101 | + return $share; |
|
1102 | + } |
|
1103 | + |
|
1104 | + protected function checkExpireDate($share) { |
|
1105 | + if ($share->getExpirationDate() !== null && |
|
1106 | + $share->getExpirationDate() <= new \DateTime()) { |
|
1107 | + $this->deleteShare($share); |
|
1108 | + throw new ShareNotFound(); |
|
1109 | + } |
|
1110 | + |
|
1111 | + } |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * Verify the password of a public share |
|
1115 | + * |
|
1116 | + * @param \OCP\Share\IShare $share |
|
1117 | + * @param string $password |
|
1118 | + * @return bool |
|
1119 | + */ |
|
1120 | + public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1121 | + $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1122 | + || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1123 | + if (!$passwordProtected) { |
|
1124 | + //TODO maybe exception? |
|
1125 | + return false; |
|
1126 | + } |
|
1127 | + |
|
1128 | + if ($password === null || $share->getPassword() === null) { |
|
1129 | + return false; |
|
1130 | + } |
|
1131 | + |
|
1132 | + $newHash = ''; |
|
1133 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1134 | + return false; |
|
1135 | + } |
|
1136 | + |
|
1137 | + if (!empty($newHash)) { |
|
1138 | + $share->setPassword($newHash); |
|
1139 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1140 | + $provider->update($share); |
|
1141 | + } |
|
1142 | + |
|
1143 | + return true; |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * @inheritdoc |
|
1148 | + */ |
|
1149 | + public function userDeleted($uid) { |
|
1150 | + $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
1151 | + |
|
1152 | + foreach ($types as $type) { |
|
1153 | + try { |
|
1154 | + $provider = $this->factory->getProviderForType($type); |
|
1155 | + } catch (ProviderException $e) { |
|
1156 | + continue; |
|
1157 | + } |
|
1158 | + $provider->userDeleted($uid, $type); |
|
1159 | + } |
|
1160 | + } |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * @inheritdoc |
|
1164 | + */ |
|
1165 | + public function groupDeleted($gid) { |
|
1166 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1167 | + $provider->groupDeleted($gid); |
|
1168 | + } |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * @inheritdoc |
|
1172 | + */ |
|
1173 | + public function userDeletedFromGroup($uid, $gid) { |
|
1174 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1175 | + $provider->userDeletedFromGroup($uid, $gid); |
|
1176 | + } |
|
1177 | + |
|
1178 | + /** |
|
1179 | + * Get access list to a path. This means |
|
1180 | + * all the users that can access a given path. |
|
1181 | + * |
|
1182 | + * Consider: |
|
1183 | + * -root |
|
1184 | + * |-folder1 (23) |
|
1185 | + * |-folder2 (32) |
|
1186 | + * |-fileA (42) |
|
1187 | + * |
|
1188 | + * fileA is shared with user1 and user1@server1 |
|
1189 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
1190 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1191 | + * |
|
1192 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1193 | + * [ |
|
1194 | + * users => [ |
|
1195 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1196 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1197 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1198 | + * ], |
|
1199 | + * remote => [ |
|
1200 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1201 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1202 | + * ], |
|
1203 | + * public => bool |
|
1204 | + * mail => bool |
|
1205 | + * ] |
|
1206 | + * |
|
1207 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1208 | + * [ |
|
1209 | + * users => ['user1', 'user2', 'user4'], |
|
1210 | + * remote => bool, |
|
1211 | + * public => bool |
|
1212 | + * mail => bool |
|
1213 | + * ] |
|
1214 | + * |
|
1215 | + * This is required for encryption/activity |
|
1216 | + * |
|
1217 | + * @param \OCP\Files\Node $path |
|
1218 | + * @param bool $recursive Should we check all parent folders as well |
|
1219 | + * @param bool $currentAccess Should the user have currently access to the file |
|
1220 | + * @return array |
|
1221 | + */ |
|
1222 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1223 | + $owner = $path->getOwner()->getUID(); |
|
1224 | + |
|
1225 | + if ($currentAccess) { |
|
1226 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1227 | + } else { |
|
1228 | + $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1229 | + } |
|
1230 | + if (!$this->userManager->userExists($owner)) { |
|
1231 | + return $al; |
|
1232 | + } |
|
1233 | + |
|
1234 | + //Get node for the owner |
|
1235 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1236 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1237 | + $path = $userFolder->getById($path->getId())[0]; |
|
1238 | + } |
|
1239 | + |
|
1240 | + $providers = $this->factory->getAllProviders(); |
|
1241 | + |
|
1242 | + /** @var Node[] $nodes */ |
|
1243 | + $nodes = []; |
|
1244 | + |
|
1245 | + |
|
1246 | + if ($currentAccess) { |
|
1247 | + $ownerPath = $path->getPath(); |
|
1248 | + $ownerPath = explode('/', $ownerPath, 4); |
|
1249 | + if (count($ownerPath) < 4) { |
|
1250 | + $ownerPath = ''; |
|
1251 | + } else { |
|
1252 | + $ownerPath = $ownerPath[3]; |
|
1253 | + } |
|
1254 | + $al['users'][$owner] = [ |
|
1255 | + 'node_id' => $path->getId(), |
|
1256 | + 'node_path' => '/' . $ownerPath, |
|
1257 | + ]; |
|
1258 | + } else { |
|
1259 | + $al['users'][] = $owner; |
|
1260 | + } |
|
1261 | + |
|
1262 | + // Collect all the shares |
|
1263 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
1264 | + $nodes[] = $path; |
|
1265 | + if (!$recursive) { |
|
1266 | + break; |
|
1267 | + } |
|
1268 | + $path = $path->getParent(); |
|
1269 | + } |
|
1270 | + |
|
1271 | + foreach ($providers as $provider) { |
|
1272 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1273 | + |
|
1274 | + foreach ($tmp as $k => $v) { |
|
1275 | + if (isset($al[$k])) { |
|
1276 | + if (is_array($al[$k])) { |
|
1277 | + $al[$k] = array_merge($al[$k], $v); |
|
1278 | + } else { |
|
1279 | + $al[$k] = $al[$k] || $v; |
|
1280 | + } |
|
1281 | + } else { |
|
1282 | + $al[$k] = $v; |
|
1283 | + } |
|
1284 | + } |
|
1285 | + } |
|
1286 | + |
|
1287 | + return $al; |
|
1288 | + } |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Create a new share |
|
1292 | + * @return \OCP\Share\IShare; |
|
1293 | + */ |
|
1294 | + public function newShare() { |
|
1295 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Is the share API enabled |
|
1300 | + * |
|
1301 | + * @return bool |
|
1302 | + */ |
|
1303 | + public function shareApiEnabled() { |
|
1304 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Is public link sharing enabled |
|
1309 | + * |
|
1310 | + * @return bool |
|
1311 | + */ |
|
1312 | + public function shareApiAllowLinks() { |
|
1313 | + return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1314 | + } |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * Is password on public link requires |
|
1318 | + * |
|
1319 | + * @return bool |
|
1320 | + */ |
|
1321 | + public function shareApiLinkEnforcePassword() { |
|
1322 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1323 | + } |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Is default expire date enabled |
|
1327 | + * |
|
1328 | + * @return bool |
|
1329 | + */ |
|
1330 | + public function shareApiLinkDefaultExpireDate() { |
|
1331 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Is default expire date enforced |
|
1336 | + *` |
|
1337 | + * @return bool |
|
1338 | + */ |
|
1339 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
1340 | + return $this->shareApiLinkDefaultExpireDate() && |
|
1341 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Number of default expire days |
|
1346 | + *shareApiLinkAllowPublicUpload |
|
1347 | + * @return int |
|
1348 | + */ |
|
1349 | + public function shareApiLinkDefaultExpireDays() { |
|
1350 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1351 | + } |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Allow public upload on link shares |
|
1355 | + * |
|
1356 | + * @return bool |
|
1357 | + */ |
|
1358 | + public function shareApiLinkAllowPublicUpload() { |
|
1359 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * check if user can only share with group members |
|
1364 | + * @return bool |
|
1365 | + */ |
|
1366 | + public function shareWithGroupMembersOnly() { |
|
1367 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Check if users can share with groups |
|
1372 | + * @return bool |
|
1373 | + */ |
|
1374 | + public function allowGroupSharing() { |
|
1375 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
1380 | + * |
|
1381 | + * TODO: Deprecate fuction from OC_Util |
|
1382 | + * |
|
1383 | + * @param string $userId |
|
1384 | + * @return bool |
|
1385 | + */ |
|
1386 | + public function sharingDisabledForUser($userId) { |
|
1387 | + if ($userId === null) { |
|
1388 | + return false; |
|
1389 | + } |
|
1390 | + |
|
1391 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1392 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
1393 | + } |
|
1394 | + |
|
1395 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1396 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1397 | + $excludedGroups = json_decode($groupsList); |
|
1398 | + if (is_null($excludedGroups)) { |
|
1399 | + $excludedGroups = explode(',', $groupsList); |
|
1400 | + $newValue = json_encode($excludedGroups); |
|
1401 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1402 | + } |
|
1403 | + $user = $this->userManager->get($userId); |
|
1404 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1405 | + if (!empty($usersGroups)) { |
|
1406 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1407 | + // if the user is only in groups which are disabled for sharing then |
|
1408 | + // sharing is also disabled for the user |
|
1409 | + if (empty($remainingGroups)) { |
|
1410 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
1411 | + return true; |
|
1412 | + } |
|
1413 | + } |
|
1414 | + } |
|
1415 | + |
|
1416 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
1417 | + return false; |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * @inheritdoc |
|
1422 | + */ |
|
1423 | + public function outgoingServer2ServerSharesAllowed() { |
|
1424 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * @inheritdoc |
|
1429 | + */ |
|
1430 | + public function shareProviderExists($shareType) { |
|
1431 | + try { |
|
1432 | + $this->factory->getProviderForType($shareType); |
|
1433 | + } catch (ProviderException $e) { |
|
1434 | + return false; |
|
1435 | + } |
|
1436 | + |
|
1437 | + return true; |
|
1438 | + } |
|
1439 | 1439 | |
1440 | 1440 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | |
322 | 322 | if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
323 | 323 | $expirationDate = new \DateTime(); |
324 | - $expirationDate->setTime(0,0,0); |
|
324 | + $expirationDate->setTime(0, 0, 0); |
|
325 | 325 | $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
326 | 326 | } |
327 | 327 | |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | $date = new \DateTime(); |
335 | 335 | $date->setTime(0, 0, 0); |
336 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
336 | + $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
337 | 337 | if ($date < $expirationDate) { |
338 | 338 | $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
339 | 339 | throw new GenericShareException($message, $message, 404); |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | */ |
387 | 387 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
388 | 388 | $existingShares = $provider->getSharesByPath($share->getNode()); |
389 | - foreach($existingShares as $existingShare) { |
|
389 | + foreach ($existingShares as $existingShare) { |
|
390 | 390 | // Ignore if it is the same share |
391 | 391 | try { |
392 | 392 | if ($existingShare->getFullId() === $share->getFullId()) { |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
445 | 445 | $existingShares = $provider->getSharesByPath($share->getNode()); |
446 | - foreach($existingShares as $existingShare) { |
|
446 | + foreach ($existingShares as $existingShare) { |
|
447 | 447 | try { |
448 | 448 | if ($existingShare->getFullId() === $share->getFullId()) { |
449 | 449 | continue; |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | // Make sure that we do not share a path that contains a shared mountpoint |
513 | 513 | if ($path instanceof \OCP\Files\Folder) { |
514 | 514 | $mounts = $this->mountManager->findIn($path->getPath()); |
515 | - foreach($mounts as $mount) { |
|
515 | + foreach ($mounts as $mount) { |
|
516 | 516 | if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
517 | 517 | throw new \InvalidArgumentException('Path contains files shared with you'); |
518 | 518 | } |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $storage = $share->getNode()->getStorage(); |
561 | 561 | if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
562 | 562 | $parent = $share->getNode()->getParent(); |
563 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
563 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
564 | 564 | $parent = $parent->getParent(); |
565 | 565 | } |
566 | 566 | $share->setShareOwner($parent->getOwner()->getUID()); |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | } |
618 | 618 | |
619 | 619 | // Generate the target |
620 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
620 | + $target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName(); |
|
621 | 621 | $target = \OC\Files\Filesystem::normalizePath($target); |
622 | 622 | $share->setTarget($target); |
623 | 623 | |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | * @param string $recipientId |
865 | 865 | */ |
866 | 866 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
867 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
867 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
868 | 868 | $provider = $this->factory->getProvider($providerId); |
869 | 869 | |
870 | 870 | $provider->deleteFromSelf($share, $recipientId); |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
886 | 886 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
887 | 887 | if (is_null($sharedWith)) { |
888 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
888 | + throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist'); |
|
889 | 889 | } |
890 | 890 | $recipient = $this->userManager->get($recipientId); |
891 | 891 | if (!$sharedWith->inGroup($recipient)) { |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | } |
894 | 894 | } |
895 | 895 | |
896 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
896 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
897 | 897 | $provider = $this->factory->getProvider($providerId); |
898 | 898 | |
899 | 899 | $provider->move($share, $recipientId); |
@@ -940,7 +940,7 @@ discard block |
||
940 | 940 | |
941 | 941 | $shares2 = []; |
942 | 942 | |
943 | - while(true) { |
|
943 | + while (true) { |
|
944 | 944 | $added = 0; |
945 | 945 | foreach ($shares as $share) { |
946 | 946 | |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | * |
1041 | 1041 | * @return Share[] |
1042 | 1042 | */ |
1043 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1043 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
1044 | 1044 | return []; |
1045 | 1045 | } |
1046 | 1046 | |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | public function getShareByToken($token) { |
1056 | 1056 | $share = null; |
1057 | 1057 | try { |
1058 | - if($this->shareApiAllowLinks()) { |
|
1058 | + if ($this->shareApiAllowLinks()) { |
|
1059 | 1059 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
1060 | 1060 | $share = $provider->getShareByToken($token); |
1061 | 1061 | } |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | } |
1254 | 1254 | $al['users'][$owner] = [ |
1255 | 1255 | 'node_id' => $path->getId(), |
1256 | - 'node_path' => '/' . $ownerPath, |
|
1256 | + 'node_path' => '/'.$ownerPath, |
|
1257 | 1257 | ]; |
1258 | 1258 | } else { |
1259 | 1259 | $al['users'][] = $owner; |
@@ -1347,7 +1347,7 @@ discard block |
||
1347 | 1347 | * @return int |
1348 | 1348 | */ |
1349 | 1349 | public function shareApiLinkDefaultExpireDays() { |
1350 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1350 | + return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1351 | 1351 | } |
1352 | 1352 | |
1353 | 1353 | /** |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | * publish activity if a file/folder was shared by mail |
277 | 277 | * |
278 | 278 | * @param $subject |
279 | - * @param $parameters |
|
280 | - * @param $affectedUser |
|
279 | + * @param string[] $parameters |
|
280 | + * @param string $affectedUser |
|
281 | 281 | * @param $fileId |
282 | - * @param $filePath |
|
282 | + * @param string $filePath |
|
283 | 283 | */ |
284 | 284 | protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
285 | 285 | $event = $this->activityManager->generateEvent(); |
@@ -557,6 +557,7 @@ discard block |
||
557 | 557 | * @param string $uidOwner |
558 | 558 | * @param int $permissions |
559 | 559 | * @param string $token |
560 | + * @param string $password |
|
560 | 561 | * @return int |
561 | 562 | */ |
562 | 563 | protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
@@ -950,7 +951,7 @@ discard block |
||
950 | 951 | /** |
951 | 952 | * get database row of a give share |
952 | 953 | * |
953 | - * @param $id |
|
954 | + * @param integer $id |
|
954 | 955 | * @return array |
955 | 956 | * @throws ShareNotFound |
956 | 957 | */ |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | $passwordPolicy = $this->getPasswordPolicy(); |
212 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
212 | + $passwordCharset = ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS; |
|
213 | 213 | $passwordLength = 8; |
214 | 214 | if (!empty($passwordPolicy)) { |
215 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
215 | + $passwordLength = (int) $passwordPolicy['minLength'] > 0 ? (int) $passwordPolicy['minLength'] : $passwordLength; |
|
216 | 216 | $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
217 | 217 | } |
218 | 218 | |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | $share->getSharedWith() |
351 | 351 | ); |
352 | 352 | } catch (HintException $hintException) { |
353 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
353 | + $this->logger->error('Failed to send share by mail: '.$hintException->getMessage()); |
|
354 | 354 | $this->removeShareFromTable($shareId); |
355 | 355 | throw $hintException; |
356 | 356 | } catch (\Exception $e) { |
357 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
357 | + $this->logger->error('Failed to send share by mail: '.$e->getMessage()); |
|
358 | 358 | $this->removeShareFromTable($shareId); |
359 | 359 | throw new HintException('Failed to send share by mail', |
360 | 360 | $this->l->t('Failed to send share by E-mail')); |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
383 | 383 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
384 | 384 | if ($owner === $initiator) { |
385 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
385 | + $subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
386 | 386 | } else { |
387 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
387 | + $subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | $message = $this->mailer->createMessage(); |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | if ($owner === $initiator) { |
397 | 397 | $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
398 | 398 | } else { |
399 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
399 | + $text = $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
400 | 400 | } |
401 | 401 | $emailTemplate->addBodyText( |
402 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
402 | + $text.' '.$this->l->t('Click the button below to open it.'), |
|
403 | 403 | $text |
404 | 404 | ); |
405 | 405 | $emailTemplate->addBodyButton( |
@@ -423,9 +423,9 @@ discard block |
||
423 | 423 | // The "Reply-To" is set to the sharer if an mail address is configured |
424 | 424 | // also the default footer contains a "Do not reply" which needs to be adjusted. |
425 | 425 | $ownerEmail = $ownerUser->getEMailAddress(); |
426 | - if($ownerEmail !== null) { |
|
426 | + if ($ownerEmail !== null) { |
|
427 | 427 | $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
428 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
428 | + $emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan()); |
|
429 | 429 | } else { |
430 | 430 | $emailTemplate->addFooter(); |
431 | 431 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
458 | 458 | $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
459 | 459 | |
460 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
460 | + $subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
461 | 461 | $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
462 | 462 | $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
463 | 463 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | ); |
508 | 508 | } |
509 | 509 | |
510 | - $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
510 | + $subject = (string) $this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
511 | 511 | $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
512 | 512 | |
513 | 513 | $message = $this->mailer->createMessage(); |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | */ |
542 | 542 | protected function generateToken($size = 15) { |
543 | 543 | $token = $this->secureRandom->generate( |
544 | - $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
544 | + $size, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
545 | 545 | return $token; |
546 | 546 | } |
547 | 547 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | ->orderBy('id'); |
563 | 563 | |
564 | 564 | $cursor = $qb->execute(); |
565 | - while($data = $cursor->fetch()) { |
|
565 | + while ($data = $cursor->fetch()) { |
|
566 | 566 | $children[] = $this->createShareObject($data); |
567 | 567 | } |
568 | 568 | $cursor->closeCursor(); |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | $qb->execute(); |
607 | 607 | $id = $qb->getLastInsertId(); |
608 | 608 | |
609 | - return (int)$id; |
|
609 | + return (int) $id; |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | // a real password was given |
624 | 624 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
625 | 625 | |
626 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
626 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
627 | 627 | $this->sendPassword($share, $plainTextPassword); |
628 | 628 | } |
629 | 629 | /* |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | |
718 | 718 | $cursor = $qb->execute(); |
719 | 719 | $shares = []; |
720 | - while($data = $cursor->fetch()) { |
|
720 | + while ($data = $cursor->fetch()) { |
|
721 | 721 | $shares[] = $this->createShareObject($data); |
722 | 722 | } |
723 | 723 | $cursor->closeCursor(); |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | ->execute(); |
770 | 770 | |
771 | 771 | $shares = []; |
772 | - while($data = $cursor->fetch()) { |
|
772 | + while ($data = $cursor->fetch()) { |
|
773 | 773 | $shares[] = $this->createShareObject($data); |
774 | 774 | } |
775 | 775 | $cursor->closeCursor(); |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | |
809 | 809 | $cursor = $qb->execute(); |
810 | 810 | |
811 | - while($data = $cursor->fetch()) { |
|
811 | + while ($data = $cursor->fetch()) { |
|
812 | 812 | $shares[] = $this->createShareObject($data); |
813 | 813 | } |
814 | 814 | $cursor->closeCursor(); |
@@ -871,15 +871,15 @@ discard block |
||
871 | 871 | protected function createShareObject($data) { |
872 | 872 | |
873 | 873 | $share = new Share($this->rootFolder, $this->userManager); |
874 | - $share->setId((int)$data['id']) |
|
875 | - ->setShareType((int)$data['share_type']) |
|
876 | - ->setPermissions((int)$data['permissions']) |
|
874 | + $share->setId((int) $data['id']) |
|
875 | + ->setShareType((int) $data['share_type']) |
|
876 | + ->setPermissions((int) $data['permissions']) |
|
877 | 877 | ->setTarget($data['file_target']) |
878 | - ->setMailSend((bool)$data['mail_send']) |
|
878 | + ->setMailSend((bool) $data['mail_send']) |
|
879 | 879 | ->setToken($data['token']); |
880 | 880 | |
881 | 881 | $shareTime = new \DateTime(); |
882 | - $shareTime->setTimestamp((int)$data['stime']); |
|
882 | + $shareTime->setTimestamp((int) $data['stime']); |
|
883 | 883 | $share->setShareTime($shareTime); |
884 | 884 | $share->setSharedWith($data['share_with']); |
885 | 885 | $share->setPassword($data['password']); |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | } else { |
891 | 891 | //OLD SHARE |
892 | 892 | $share->setSharedBy($data['uid_owner']); |
893 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
893 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
894 | 894 | |
895 | 895 | $owner = $path->getOwner(); |
896 | 896 | $share->setShareOwner($owner->getUID()); |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | } |
904 | 904 | } |
905 | 905 | |
906 | - $share->setNodeId((int)$data['file_source']); |
|
906 | + $share->setNodeId((int) $data['file_source']); |
|
907 | 907 | $share->setNodeType($data['item_type']); |
908 | 908 | |
909 | 909 | $share->setProviderId($this->identifier()); |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | ); |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1025 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1026 | 1026 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
1027 | 1027 | |
1028 | 1028 | $qb->orderBy('id'); |
@@ -52,1016 +52,1016 @@ |
||
52 | 52 | */ |
53 | 53 | class ShareByMailProvider implements IShareProvider { |
54 | 54 | |
55 | - /** @var IDBConnection */ |
|
56 | - private $dbConnection; |
|
57 | - |
|
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
60 | - |
|
61 | - /** @var ISecureRandom */ |
|
62 | - private $secureRandom; |
|
63 | - |
|
64 | - /** @var IUserManager */ |
|
65 | - private $userManager; |
|
66 | - |
|
67 | - /** @var IRootFolder */ |
|
68 | - private $rootFolder; |
|
69 | - |
|
70 | - /** @var IL10N */ |
|
71 | - private $l; |
|
72 | - |
|
73 | - /** @var IMailer */ |
|
74 | - private $mailer; |
|
75 | - |
|
76 | - /** @var IURLGenerator */ |
|
77 | - private $urlGenerator; |
|
78 | - |
|
79 | - /** @var IManager */ |
|
80 | - private $activityManager; |
|
81 | - |
|
82 | - /** @var SettingsManager */ |
|
83 | - private $settingsManager; |
|
84 | - |
|
85 | - /** @var Defaults */ |
|
86 | - private $defaults; |
|
87 | - |
|
88 | - /** @var IHasher */ |
|
89 | - private $hasher; |
|
90 | - |
|
91 | - /** @var CapabilitiesManager */ |
|
92 | - private $capabilitiesManager; |
|
93 | - |
|
94 | - /** |
|
95 | - * Return the identifier of this provider. |
|
96 | - * |
|
97 | - * @return string Containing only [a-zA-Z0-9] |
|
98 | - */ |
|
99 | - public function identifier() { |
|
100 | - return 'ocMailShare'; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * DefaultShareProvider constructor. |
|
105 | - * |
|
106 | - * @param IDBConnection $connection |
|
107 | - * @param ISecureRandom $secureRandom |
|
108 | - * @param IUserManager $userManager |
|
109 | - * @param IRootFolder $rootFolder |
|
110 | - * @param IL10N $l |
|
111 | - * @param ILogger $logger |
|
112 | - * @param IMailer $mailer |
|
113 | - * @param IURLGenerator $urlGenerator |
|
114 | - * @param IManager $activityManager |
|
115 | - * @param SettingsManager $settingsManager |
|
116 | - * @param Defaults $defaults |
|
117 | - * @param IHasher $hasher |
|
118 | - * @param CapabilitiesManager $capabilitiesManager |
|
119 | - */ |
|
120 | - public function __construct( |
|
121 | - IDBConnection $connection, |
|
122 | - ISecureRandom $secureRandom, |
|
123 | - IUserManager $userManager, |
|
124 | - IRootFolder $rootFolder, |
|
125 | - IL10N $l, |
|
126 | - ILogger $logger, |
|
127 | - IMailer $mailer, |
|
128 | - IURLGenerator $urlGenerator, |
|
129 | - IManager $activityManager, |
|
130 | - SettingsManager $settingsManager, |
|
131 | - Defaults $defaults, |
|
132 | - IHasher $hasher, |
|
133 | - CapabilitiesManager $capabilitiesManager |
|
134 | - ) { |
|
135 | - $this->dbConnection = $connection; |
|
136 | - $this->secureRandom = $secureRandom; |
|
137 | - $this->userManager = $userManager; |
|
138 | - $this->rootFolder = $rootFolder; |
|
139 | - $this->l = $l; |
|
140 | - $this->logger = $logger; |
|
141 | - $this->mailer = $mailer; |
|
142 | - $this->urlGenerator = $urlGenerator; |
|
143 | - $this->activityManager = $activityManager; |
|
144 | - $this->settingsManager = $settingsManager; |
|
145 | - $this->defaults = $defaults; |
|
146 | - $this->hasher = $hasher; |
|
147 | - $this->capabilitiesManager = $capabilitiesManager; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Share a path |
|
152 | - * |
|
153 | - * @param IShare $share |
|
154 | - * @return IShare The share object |
|
155 | - * @throws ShareNotFound |
|
156 | - * @throws \Exception |
|
157 | - */ |
|
158 | - public function create(IShare $share) { |
|
159 | - |
|
160 | - $shareWith = $share->getSharedWith(); |
|
161 | - /* |
|
55 | + /** @var IDBConnection */ |
|
56 | + private $dbConnection; |
|
57 | + |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | + |
|
61 | + /** @var ISecureRandom */ |
|
62 | + private $secureRandom; |
|
63 | + |
|
64 | + /** @var IUserManager */ |
|
65 | + private $userManager; |
|
66 | + |
|
67 | + /** @var IRootFolder */ |
|
68 | + private $rootFolder; |
|
69 | + |
|
70 | + /** @var IL10N */ |
|
71 | + private $l; |
|
72 | + |
|
73 | + /** @var IMailer */ |
|
74 | + private $mailer; |
|
75 | + |
|
76 | + /** @var IURLGenerator */ |
|
77 | + private $urlGenerator; |
|
78 | + |
|
79 | + /** @var IManager */ |
|
80 | + private $activityManager; |
|
81 | + |
|
82 | + /** @var SettingsManager */ |
|
83 | + private $settingsManager; |
|
84 | + |
|
85 | + /** @var Defaults */ |
|
86 | + private $defaults; |
|
87 | + |
|
88 | + /** @var IHasher */ |
|
89 | + private $hasher; |
|
90 | + |
|
91 | + /** @var CapabilitiesManager */ |
|
92 | + private $capabilitiesManager; |
|
93 | + |
|
94 | + /** |
|
95 | + * Return the identifier of this provider. |
|
96 | + * |
|
97 | + * @return string Containing only [a-zA-Z0-9] |
|
98 | + */ |
|
99 | + public function identifier() { |
|
100 | + return 'ocMailShare'; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * DefaultShareProvider constructor. |
|
105 | + * |
|
106 | + * @param IDBConnection $connection |
|
107 | + * @param ISecureRandom $secureRandom |
|
108 | + * @param IUserManager $userManager |
|
109 | + * @param IRootFolder $rootFolder |
|
110 | + * @param IL10N $l |
|
111 | + * @param ILogger $logger |
|
112 | + * @param IMailer $mailer |
|
113 | + * @param IURLGenerator $urlGenerator |
|
114 | + * @param IManager $activityManager |
|
115 | + * @param SettingsManager $settingsManager |
|
116 | + * @param Defaults $defaults |
|
117 | + * @param IHasher $hasher |
|
118 | + * @param CapabilitiesManager $capabilitiesManager |
|
119 | + */ |
|
120 | + public function __construct( |
|
121 | + IDBConnection $connection, |
|
122 | + ISecureRandom $secureRandom, |
|
123 | + IUserManager $userManager, |
|
124 | + IRootFolder $rootFolder, |
|
125 | + IL10N $l, |
|
126 | + ILogger $logger, |
|
127 | + IMailer $mailer, |
|
128 | + IURLGenerator $urlGenerator, |
|
129 | + IManager $activityManager, |
|
130 | + SettingsManager $settingsManager, |
|
131 | + Defaults $defaults, |
|
132 | + IHasher $hasher, |
|
133 | + CapabilitiesManager $capabilitiesManager |
|
134 | + ) { |
|
135 | + $this->dbConnection = $connection; |
|
136 | + $this->secureRandom = $secureRandom; |
|
137 | + $this->userManager = $userManager; |
|
138 | + $this->rootFolder = $rootFolder; |
|
139 | + $this->l = $l; |
|
140 | + $this->logger = $logger; |
|
141 | + $this->mailer = $mailer; |
|
142 | + $this->urlGenerator = $urlGenerator; |
|
143 | + $this->activityManager = $activityManager; |
|
144 | + $this->settingsManager = $settingsManager; |
|
145 | + $this->defaults = $defaults; |
|
146 | + $this->hasher = $hasher; |
|
147 | + $this->capabilitiesManager = $capabilitiesManager; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Share a path |
|
152 | + * |
|
153 | + * @param IShare $share |
|
154 | + * @return IShare The share object |
|
155 | + * @throws ShareNotFound |
|
156 | + * @throws \Exception |
|
157 | + */ |
|
158 | + public function create(IShare $share) { |
|
159 | + |
|
160 | + $shareWith = $share->getSharedWith(); |
|
161 | + /* |
|
162 | 162 | * Check if file is not already shared with the remote user |
163 | 163 | */ |
164 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
165 | - if (!empty($alreadyShared)) { |
|
166 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
167 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
168 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
169 | - throw new \Exception($message_t); |
|
170 | - } |
|
171 | - |
|
172 | - // if the admin enforces a password for all mail shares we create a |
|
173 | - // random password and send it to the recipient |
|
174 | - $password = ''; |
|
175 | - $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
176 | - if ($passwordEnforced) { |
|
177 | - $password = $this->autoGeneratePassword($share); |
|
178 | - } |
|
179 | - |
|
180 | - $shareId = $this->createMailShare($share); |
|
181 | - $send = $this->sendPassword($share, $password); |
|
182 | - if ($passwordEnforced && $send === false) { |
|
183 | - $this->sendPasswordToOwner($share, $password); |
|
184 | - } |
|
185 | - |
|
186 | - $this->createShareActivity($share); |
|
187 | - $data = $this->getRawShare($shareId); |
|
188 | - |
|
189 | - return $this->createShareObject($data); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * auto generate password in case of password enforcement on mail shares |
|
195 | - * |
|
196 | - * @param IShare $share |
|
197 | - * @return string |
|
198 | - * @throws \Exception |
|
199 | - */ |
|
200 | - protected function autoGeneratePassword($share) { |
|
201 | - $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
202 | - $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
203 | - $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
204 | - |
|
205 | - if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
206 | - throw new \Exception( |
|
207 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
208 | - ); |
|
209 | - } |
|
210 | - |
|
211 | - $passwordPolicy = $this->getPasswordPolicy(); |
|
212 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
213 | - $passwordLength = 8; |
|
214 | - if (!empty($passwordPolicy)) { |
|
215 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
216 | - $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
217 | - } |
|
218 | - |
|
219 | - $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
220 | - |
|
221 | - $share->setPassword($this->hasher->hash($password)); |
|
222 | - |
|
223 | - return $password; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * get password policy |
|
228 | - * |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - protected function getPasswordPolicy() { |
|
232 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
233 | - if (isset($capabilities['password_policy'])) { |
|
234 | - return $capabilities['password_policy']; |
|
235 | - } |
|
236 | - |
|
237 | - return []; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * create activity if a file/folder was shared by mail |
|
242 | - * |
|
243 | - * @param IShare $share |
|
244 | - */ |
|
245 | - protected function createShareActivity(IShare $share) { |
|
246 | - |
|
247 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
248 | - |
|
249 | - $this->publishActivity( |
|
250 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
251 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
252 | - $share->getSharedBy(), |
|
253 | - $share->getNode()->getId(), |
|
254 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
255 | - ); |
|
256 | - |
|
257 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
258 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
259 | - $fileId = $share->getNode()->getId(); |
|
260 | - $nodes = $ownerFolder->getById($fileId); |
|
261 | - $ownerPath = $nodes[0]->getPath(); |
|
262 | - $this->publishActivity( |
|
263 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
264 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
265 | - $share->getShareOwner(), |
|
266 | - $fileId, |
|
267 | - $ownerFolder->getRelativePath($ownerPath) |
|
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * create activity if a file/folder was shared by mail |
|
275 | - * |
|
276 | - * @param IShare $share |
|
277 | - * @param string $sharedWith |
|
278 | - * @param bool $sendToSelf |
|
279 | - */ |
|
280 | - protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
281 | - |
|
282 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
283 | - |
|
284 | - if ($sendToSelf) { |
|
285 | - $this->publishActivity( |
|
286 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
287 | - [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
288 | - $share->getSharedBy(), |
|
289 | - $share->getNode()->getId(), |
|
290 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
291 | - ); |
|
292 | - } else { |
|
293 | - $this->publishActivity( |
|
294 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
295 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
296 | - $share->getSharedBy(), |
|
297 | - $share->getNode()->getId(), |
|
298 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
299 | - ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * publish activity if a file/folder was shared by mail |
|
306 | - * |
|
307 | - * @param $subject |
|
308 | - * @param $parameters |
|
309 | - * @param $affectedUser |
|
310 | - * @param $fileId |
|
311 | - * @param $filePath |
|
312 | - */ |
|
313 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
314 | - $event = $this->activityManager->generateEvent(); |
|
315 | - $event->setApp('sharebymail') |
|
316 | - ->setType('shared') |
|
317 | - ->setSubject($subject, $parameters) |
|
318 | - ->setAffectedUser($affectedUser) |
|
319 | - ->setObject('files', $fileId, $filePath); |
|
320 | - $this->activityManager->publish($event); |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param IShare $share |
|
326 | - * @return int |
|
327 | - * @throws \Exception |
|
328 | - */ |
|
329 | - protected function createMailShare(IShare $share) { |
|
330 | - $share->setToken($this->generateToken()); |
|
331 | - $shareId = $this->addShareToDB( |
|
332 | - $share->getNodeId(), |
|
333 | - $share->getNodeType(), |
|
334 | - $share->getSharedWith(), |
|
335 | - $share->getSharedBy(), |
|
336 | - $share->getShareOwner(), |
|
337 | - $share->getPermissions(), |
|
338 | - $share->getToken(), |
|
339 | - $share->getPassword() |
|
340 | - ); |
|
341 | - |
|
342 | - try { |
|
343 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
344 | - ['token' => $share->getToken()]); |
|
345 | - $this->sendMailNotification( |
|
346 | - $share->getNode()->getName(), |
|
347 | - $link, |
|
348 | - $share->getShareOwner(), |
|
349 | - $share->getSharedBy(), |
|
350 | - $share->getSharedWith() |
|
351 | - ); |
|
352 | - } catch (HintException $hintException) { |
|
353 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
354 | - $this->removeShareFromTable($shareId); |
|
355 | - throw $hintException; |
|
356 | - } catch (\Exception $e) { |
|
357 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
358 | - $this->removeShareFromTable($shareId); |
|
359 | - throw new HintException('Failed to send share by mail', |
|
360 | - $this->l->t('Failed to send share by E-mail')); |
|
361 | - } |
|
362 | - |
|
363 | - return $shareId; |
|
364 | - |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param string $filename |
|
369 | - * @param string $link |
|
370 | - * @param string $owner |
|
371 | - * @param string $initiator |
|
372 | - * @param string $shareWith |
|
373 | - * @throws \Exception If mail couldn't be sent |
|
374 | - */ |
|
375 | - protected function sendMailNotification($filename, |
|
376 | - $link, |
|
377 | - $owner, |
|
378 | - $initiator, |
|
379 | - $shareWith) { |
|
380 | - $ownerUser = $this->userManager->get($owner); |
|
381 | - $initiatorUser = $this->userManager->get($initiator); |
|
382 | - $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
383 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
384 | - if ($owner === $initiator) { |
|
385 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
386 | - } else { |
|
387 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
388 | - } |
|
389 | - |
|
390 | - $message = $this->mailer->createMessage(); |
|
391 | - |
|
392 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
393 | - |
|
394 | - $emailTemplate->addHeader(); |
|
395 | - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); |
|
396 | - if ($owner === $initiator) { |
|
397 | - $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
398 | - } else { |
|
399 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
400 | - } |
|
401 | - $emailTemplate->addBodyText( |
|
402 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
403 | - $text |
|
404 | - ); |
|
405 | - $emailTemplate->addBodyButton( |
|
406 | - $this->l->t('Open »%s«', [$filename]), |
|
407 | - $link |
|
408 | - ); |
|
409 | - |
|
410 | - $message->setTo([$shareWith]); |
|
411 | - |
|
412 | - // The "From" contains the sharers name |
|
413 | - $instanceName = $this->defaults->getName(); |
|
414 | - $senderName = $this->l->t( |
|
415 | - '%s via %s', |
|
416 | - [ |
|
417 | - $ownerDisplayName, |
|
418 | - $instanceName |
|
419 | - ] |
|
420 | - ); |
|
421 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
422 | - |
|
423 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
424 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
425 | - $ownerEmail = $ownerUser->getEMailAddress(); |
|
426 | - if($ownerEmail !== null) { |
|
427 | - $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
|
428 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
429 | - } else { |
|
430 | - $emailTemplate->addFooter(); |
|
431 | - } |
|
432 | - |
|
433 | - $message->setSubject($subject); |
|
434 | - $message->setPlainBody($emailTemplate->renderText()); |
|
435 | - $message->setHtmlBody($emailTemplate->renderHtml()); |
|
436 | - $this->mailer->send($message); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * send password to recipient of a mail share |
|
441 | - * |
|
442 | - * @param IShare $share |
|
443 | - * @param string $password |
|
444 | - * @return bool |
|
445 | - */ |
|
446 | - protected function sendPassword(IShare $share, $password) { |
|
447 | - |
|
448 | - $filename = $share->getNode()->getName(); |
|
449 | - $initiator = $share->getSharedBy(); |
|
450 | - $shareWith = $share->getSharedWith(); |
|
451 | - |
|
452 | - if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
453 | - return false; |
|
454 | - } |
|
455 | - |
|
456 | - $initiatorUser = $this->userManager->get($initiator); |
|
457 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
458 | - $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
459 | - |
|
460 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
461 | - $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
462 | - $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
463 | - |
|
464 | - $message = $this->mailer->createMessage(); |
|
465 | - |
|
466 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
467 | - $emailTemplate->addHeader(); |
|
468 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
469 | - $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
470 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
471 | - $emailTemplate->addFooter(); |
|
472 | - |
|
473 | - if ($initiatorEmailAddress !== null) { |
|
474 | - $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
475 | - } |
|
476 | - $message->setTo([$shareWith]); |
|
477 | - $message->setSubject($subject); |
|
478 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
479 | - $message->setHtmlBody($emailTemplate->renderHtml()); |
|
480 | - $this->mailer->send($message); |
|
481 | - |
|
482 | - $this->createPasswordSendActivity($share, $shareWith, false); |
|
483 | - |
|
484 | - return true; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * send auto generated password to the owner. This happens if the admin enforces |
|
489 | - * a password for mail shares and forbid to send the password by mail to the recipient |
|
490 | - * |
|
491 | - * @param IShare $share |
|
492 | - * @param string $password |
|
493 | - * @return bool |
|
494 | - * @throws \Exception |
|
495 | - */ |
|
496 | - protected function sendPasswordToOwner(IShare $share, $password) { |
|
497 | - |
|
498 | - $filename = $share->getNode()->getName(); |
|
499 | - $initiator = $this->userManager->get($share->getSharedBy()); |
|
500 | - $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
501 | - $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
502 | - $shareWith = $share->getSharedWith(); |
|
503 | - |
|
504 | - if ($initiatorEMailAddress === null) { |
|
505 | - throw new \Exception( |
|
506 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
507 | - ); |
|
508 | - } |
|
509 | - |
|
510 | - $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
511 | - $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
512 | - |
|
513 | - $message = $this->mailer->createMessage(); |
|
514 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
515 | - |
|
516 | - $emailTemplate->addHeader(); |
|
517 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
518 | - $emailTemplate->addBodyText($bodyPart); |
|
519 | - $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
520 | - $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
521 | - $emailTemplate->addFooter(); |
|
522 | - |
|
523 | - if ($initiatorEMailAddress) { |
|
524 | - $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
525 | - } |
|
526 | - $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
527 | - $message->setSubject($subject); |
|
528 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
529 | - $message->setHtmlBody($emailTemplate->renderHtml()); |
|
530 | - $this->mailer->send($message); |
|
531 | - |
|
532 | - $this->createPasswordSendActivity($share, $shareWith, true); |
|
533 | - |
|
534 | - return true; |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * generate share token |
|
539 | - * |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - protected function generateToken($size = 15) { |
|
543 | - $token = $this->secureRandom->generate( |
|
544 | - $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
545 | - return $token; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Get all children of this share |
|
550 | - * |
|
551 | - * @param IShare $parent |
|
552 | - * @return IShare[] |
|
553 | - */ |
|
554 | - public function getChildren(IShare $parent) { |
|
555 | - $children = []; |
|
556 | - |
|
557 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
558 | - $qb->select('*') |
|
559 | - ->from('share') |
|
560 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
561 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
562 | - ->orderBy('id'); |
|
563 | - |
|
564 | - $cursor = $qb->execute(); |
|
565 | - while($data = $cursor->fetch()) { |
|
566 | - $children[] = $this->createShareObject($data); |
|
567 | - } |
|
568 | - $cursor->closeCursor(); |
|
569 | - |
|
570 | - return $children; |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * add share to the database and return the ID |
|
575 | - * |
|
576 | - * @param int $itemSource |
|
577 | - * @param string $itemType |
|
578 | - * @param string $shareWith |
|
579 | - * @param string $sharedBy |
|
580 | - * @param string $uidOwner |
|
581 | - * @param int $permissions |
|
582 | - * @param string $token |
|
583 | - * @return int |
|
584 | - */ |
|
585 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
586 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
587 | - $qb->insert('share') |
|
588 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
589 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
590 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
591 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
592 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
593 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
594 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
595 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
596 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
597 | - ->setValue('password', $qb->createNamedParameter($password)) |
|
598 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
599 | - |
|
600 | - /* |
|
164 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
165 | + if (!empty($alreadyShared)) { |
|
166 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
167 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
168 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
169 | + throw new \Exception($message_t); |
|
170 | + } |
|
171 | + |
|
172 | + // if the admin enforces a password for all mail shares we create a |
|
173 | + // random password and send it to the recipient |
|
174 | + $password = ''; |
|
175 | + $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
176 | + if ($passwordEnforced) { |
|
177 | + $password = $this->autoGeneratePassword($share); |
|
178 | + } |
|
179 | + |
|
180 | + $shareId = $this->createMailShare($share); |
|
181 | + $send = $this->sendPassword($share, $password); |
|
182 | + if ($passwordEnforced && $send === false) { |
|
183 | + $this->sendPasswordToOwner($share, $password); |
|
184 | + } |
|
185 | + |
|
186 | + $this->createShareActivity($share); |
|
187 | + $data = $this->getRawShare($shareId); |
|
188 | + |
|
189 | + return $this->createShareObject($data); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * auto generate password in case of password enforcement on mail shares |
|
195 | + * |
|
196 | + * @param IShare $share |
|
197 | + * @return string |
|
198 | + * @throws \Exception |
|
199 | + */ |
|
200 | + protected function autoGeneratePassword($share) { |
|
201 | + $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
202 | + $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
203 | + $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
204 | + |
|
205 | + if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
206 | + throw new \Exception( |
|
207 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
208 | + ); |
|
209 | + } |
|
210 | + |
|
211 | + $passwordPolicy = $this->getPasswordPolicy(); |
|
212 | + $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
213 | + $passwordLength = 8; |
|
214 | + if (!empty($passwordPolicy)) { |
|
215 | + $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
216 | + $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
217 | + } |
|
218 | + |
|
219 | + $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
220 | + |
|
221 | + $share->setPassword($this->hasher->hash($password)); |
|
222 | + |
|
223 | + return $password; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * get password policy |
|
228 | + * |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + protected function getPasswordPolicy() { |
|
232 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
233 | + if (isset($capabilities['password_policy'])) { |
|
234 | + return $capabilities['password_policy']; |
|
235 | + } |
|
236 | + |
|
237 | + return []; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * create activity if a file/folder was shared by mail |
|
242 | + * |
|
243 | + * @param IShare $share |
|
244 | + */ |
|
245 | + protected function createShareActivity(IShare $share) { |
|
246 | + |
|
247 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
248 | + |
|
249 | + $this->publishActivity( |
|
250 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
251 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
252 | + $share->getSharedBy(), |
|
253 | + $share->getNode()->getId(), |
|
254 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
255 | + ); |
|
256 | + |
|
257 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
258 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
259 | + $fileId = $share->getNode()->getId(); |
|
260 | + $nodes = $ownerFolder->getById($fileId); |
|
261 | + $ownerPath = $nodes[0]->getPath(); |
|
262 | + $this->publishActivity( |
|
263 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
264 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
265 | + $share->getShareOwner(), |
|
266 | + $fileId, |
|
267 | + $ownerFolder->getRelativePath($ownerPath) |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * create activity if a file/folder was shared by mail |
|
275 | + * |
|
276 | + * @param IShare $share |
|
277 | + * @param string $sharedWith |
|
278 | + * @param bool $sendToSelf |
|
279 | + */ |
|
280 | + protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
281 | + |
|
282 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
283 | + |
|
284 | + if ($sendToSelf) { |
|
285 | + $this->publishActivity( |
|
286 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
287 | + [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
288 | + $share->getSharedBy(), |
|
289 | + $share->getNode()->getId(), |
|
290 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
291 | + ); |
|
292 | + } else { |
|
293 | + $this->publishActivity( |
|
294 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
295 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
296 | + $share->getSharedBy(), |
|
297 | + $share->getNode()->getId(), |
|
298 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
299 | + ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * publish activity if a file/folder was shared by mail |
|
306 | + * |
|
307 | + * @param $subject |
|
308 | + * @param $parameters |
|
309 | + * @param $affectedUser |
|
310 | + * @param $fileId |
|
311 | + * @param $filePath |
|
312 | + */ |
|
313 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
314 | + $event = $this->activityManager->generateEvent(); |
|
315 | + $event->setApp('sharebymail') |
|
316 | + ->setType('shared') |
|
317 | + ->setSubject($subject, $parameters) |
|
318 | + ->setAffectedUser($affectedUser) |
|
319 | + ->setObject('files', $fileId, $filePath); |
|
320 | + $this->activityManager->publish($event); |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param IShare $share |
|
326 | + * @return int |
|
327 | + * @throws \Exception |
|
328 | + */ |
|
329 | + protected function createMailShare(IShare $share) { |
|
330 | + $share->setToken($this->generateToken()); |
|
331 | + $shareId = $this->addShareToDB( |
|
332 | + $share->getNodeId(), |
|
333 | + $share->getNodeType(), |
|
334 | + $share->getSharedWith(), |
|
335 | + $share->getSharedBy(), |
|
336 | + $share->getShareOwner(), |
|
337 | + $share->getPermissions(), |
|
338 | + $share->getToken(), |
|
339 | + $share->getPassword() |
|
340 | + ); |
|
341 | + |
|
342 | + try { |
|
343 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
344 | + ['token' => $share->getToken()]); |
|
345 | + $this->sendMailNotification( |
|
346 | + $share->getNode()->getName(), |
|
347 | + $link, |
|
348 | + $share->getShareOwner(), |
|
349 | + $share->getSharedBy(), |
|
350 | + $share->getSharedWith() |
|
351 | + ); |
|
352 | + } catch (HintException $hintException) { |
|
353 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
354 | + $this->removeShareFromTable($shareId); |
|
355 | + throw $hintException; |
|
356 | + } catch (\Exception $e) { |
|
357 | + $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
358 | + $this->removeShareFromTable($shareId); |
|
359 | + throw new HintException('Failed to send share by mail', |
|
360 | + $this->l->t('Failed to send share by E-mail')); |
|
361 | + } |
|
362 | + |
|
363 | + return $shareId; |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param string $filename |
|
369 | + * @param string $link |
|
370 | + * @param string $owner |
|
371 | + * @param string $initiator |
|
372 | + * @param string $shareWith |
|
373 | + * @throws \Exception If mail couldn't be sent |
|
374 | + */ |
|
375 | + protected function sendMailNotification($filename, |
|
376 | + $link, |
|
377 | + $owner, |
|
378 | + $initiator, |
|
379 | + $shareWith) { |
|
380 | + $ownerUser = $this->userManager->get($owner); |
|
381 | + $initiatorUser = $this->userManager->get($initiator); |
|
382 | + $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
383 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
384 | + if ($owner === $initiator) { |
|
385 | + $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
386 | + } else { |
|
387 | + $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
388 | + } |
|
389 | + |
|
390 | + $message = $this->mailer->createMessage(); |
|
391 | + |
|
392 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
393 | + |
|
394 | + $emailTemplate->addHeader(); |
|
395 | + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); |
|
396 | + if ($owner === $initiator) { |
|
397 | + $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
398 | + } else { |
|
399 | + $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
400 | + } |
|
401 | + $emailTemplate->addBodyText( |
|
402 | + $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
403 | + $text |
|
404 | + ); |
|
405 | + $emailTemplate->addBodyButton( |
|
406 | + $this->l->t('Open »%s«', [$filename]), |
|
407 | + $link |
|
408 | + ); |
|
409 | + |
|
410 | + $message->setTo([$shareWith]); |
|
411 | + |
|
412 | + // The "From" contains the sharers name |
|
413 | + $instanceName = $this->defaults->getName(); |
|
414 | + $senderName = $this->l->t( |
|
415 | + '%s via %s', |
|
416 | + [ |
|
417 | + $ownerDisplayName, |
|
418 | + $instanceName |
|
419 | + ] |
|
420 | + ); |
|
421 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
422 | + |
|
423 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
424 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
425 | + $ownerEmail = $ownerUser->getEMailAddress(); |
|
426 | + if($ownerEmail !== null) { |
|
427 | + $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
|
428 | + $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
429 | + } else { |
|
430 | + $emailTemplate->addFooter(); |
|
431 | + } |
|
432 | + |
|
433 | + $message->setSubject($subject); |
|
434 | + $message->setPlainBody($emailTemplate->renderText()); |
|
435 | + $message->setHtmlBody($emailTemplate->renderHtml()); |
|
436 | + $this->mailer->send($message); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * send password to recipient of a mail share |
|
441 | + * |
|
442 | + * @param IShare $share |
|
443 | + * @param string $password |
|
444 | + * @return bool |
|
445 | + */ |
|
446 | + protected function sendPassword(IShare $share, $password) { |
|
447 | + |
|
448 | + $filename = $share->getNode()->getName(); |
|
449 | + $initiator = $share->getSharedBy(); |
|
450 | + $shareWith = $share->getSharedWith(); |
|
451 | + |
|
452 | + if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
453 | + return false; |
|
454 | + } |
|
455 | + |
|
456 | + $initiatorUser = $this->userManager->get($initiator); |
|
457 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
458 | + $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
459 | + |
|
460 | + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
461 | + $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
462 | + $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
463 | + |
|
464 | + $message = $this->mailer->createMessage(); |
|
465 | + |
|
466 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
467 | + $emailTemplate->addHeader(); |
|
468 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); |
|
469 | + $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
470 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
471 | + $emailTemplate->addFooter(); |
|
472 | + |
|
473 | + if ($initiatorEmailAddress !== null) { |
|
474 | + $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
475 | + } |
|
476 | + $message->setTo([$shareWith]); |
|
477 | + $message->setSubject($subject); |
|
478 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
479 | + $message->setHtmlBody($emailTemplate->renderHtml()); |
|
480 | + $this->mailer->send($message); |
|
481 | + |
|
482 | + $this->createPasswordSendActivity($share, $shareWith, false); |
|
483 | + |
|
484 | + return true; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * send auto generated password to the owner. This happens if the admin enforces |
|
489 | + * a password for mail shares and forbid to send the password by mail to the recipient |
|
490 | + * |
|
491 | + * @param IShare $share |
|
492 | + * @param string $password |
|
493 | + * @return bool |
|
494 | + * @throws \Exception |
|
495 | + */ |
|
496 | + protected function sendPasswordToOwner(IShare $share, $password) { |
|
497 | + |
|
498 | + $filename = $share->getNode()->getName(); |
|
499 | + $initiator = $this->userManager->get($share->getSharedBy()); |
|
500 | + $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
501 | + $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
502 | + $shareWith = $share->getSharedWith(); |
|
503 | + |
|
504 | + if ($initiatorEMailAddress === null) { |
|
505 | + throw new \Exception( |
|
506 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
507 | + ); |
|
508 | + } |
|
509 | + |
|
510 | + $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
511 | + $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
512 | + |
|
513 | + $message = $this->mailer->createMessage(); |
|
514 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
515 | + |
|
516 | + $emailTemplate->addHeader(); |
|
517 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
518 | + $emailTemplate->addBodyText($bodyPart); |
|
519 | + $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
520 | + $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
521 | + $emailTemplate->addFooter(); |
|
522 | + |
|
523 | + if ($initiatorEMailAddress) { |
|
524 | + $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
525 | + } |
|
526 | + $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
527 | + $message->setSubject($subject); |
|
528 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
529 | + $message->setHtmlBody($emailTemplate->renderHtml()); |
|
530 | + $this->mailer->send($message); |
|
531 | + |
|
532 | + $this->createPasswordSendActivity($share, $shareWith, true); |
|
533 | + |
|
534 | + return true; |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * generate share token |
|
539 | + * |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + protected function generateToken($size = 15) { |
|
543 | + $token = $this->secureRandom->generate( |
|
544 | + $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
545 | + return $token; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Get all children of this share |
|
550 | + * |
|
551 | + * @param IShare $parent |
|
552 | + * @return IShare[] |
|
553 | + */ |
|
554 | + public function getChildren(IShare $parent) { |
|
555 | + $children = []; |
|
556 | + |
|
557 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
558 | + $qb->select('*') |
|
559 | + ->from('share') |
|
560 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
561 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
562 | + ->orderBy('id'); |
|
563 | + |
|
564 | + $cursor = $qb->execute(); |
|
565 | + while($data = $cursor->fetch()) { |
|
566 | + $children[] = $this->createShareObject($data); |
|
567 | + } |
|
568 | + $cursor->closeCursor(); |
|
569 | + |
|
570 | + return $children; |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * add share to the database and return the ID |
|
575 | + * |
|
576 | + * @param int $itemSource |
|
577 | + * @param string $itemType |
|
578 | + * @param string $shareWith |
|
579 | + * @param string $sharedBy |
|
580 | + * @param string $uidOwner |
|
581 | + * @param int $permissions |
|
582 | + * @param string $token |
|
583 | + * @return int |
|
584 | + */ |
|
585 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
586 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
587 | + $qb->insert('share') |
|
588 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
589 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
590 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
591 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
592 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
593 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
594 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
595 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
596 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
597 | + ->setValue('password', $qb->createNamedParameter($password)) |
|
598 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
599 | + |
|
600 | + /* |
|
601 | 601 | * Added to fix https://github.com/owncloud/core/issues/22215 |
602 | 602 | * Can be removed once we get rid of ajax/share.php |
603 | 603 | */ |
604 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
604 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
605 | 605 | |
606 | - $qb->execute(); |
|
607 | - $id = $qb->getLastInsertId(); |
|
606 | + $qb->execute(); |
|
607 | + $id = $qb->getLastInsertId(); |
|
608 | 608 | |
609 | - return (int)$id; |
|
610 | - } |
|
609 | + return (int)$id; |
|
610 | + } |
|
611 | 611 | |
612 | - /** |
|
613 | - * Update a share |
|
614 | - * |
|
615 | - * @param IShare $share |
|
616 | - * @param string|null $plainTextPassword |
|
617 | - * @return IShare The share object |
|
618 | - */ |
|
619 | - public function update(IShare $share, $plainTextPassword = null) { |
|
612 | + /** |
|
613 | + * Update a share |
|
614 | + * |
|
615 | + * @param IShare $share |
|
616 | + * @param string|null $plainTextPassword |
|
617 | + * @return IShare The share object |
|
618 | + */ |
|
619 | + public function update(IShare $share, $plainTextPassword = null) { |
|
620 | 620 | |
621 | - $originalShare = $this->getShareById($share->getId()); |
|
621 | + $originalShare = $this->getShareById($share->getId()); |
|
622 | 622 | |
623 | - // a real password was given |
|
624 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
623 | + // a real password was given |
|
624 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
625 | 625 | |
626 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
627 | - $this->sendPassword($share, $plainTextPassword); |
|
628 | - } |
|
629 | - /* |
|
626 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
627 | + $this->sendPassword($share, $plainTextPassword); |
|
628 | + } |
|
629 | + /* |
|
630 | 630 | * We allow updating the permissions and password of mail shares |
631 | 631 | */ |
632 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
633 | - $qb->update('share') |
|
634 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
635 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
636 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
637 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
638 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
639 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
640 | - ->execute(); |
|
641 | - |
|
642 | - return $share; |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * @inheritdoc |
|
647 | - */ |
|
648 | - public function move(IShare $share, $recipient) { |
|
649 | - /** |
|
650 | - * nothing to do here, mail shares are only outgoing shares |
|
651 | - */ |
|
652 | - return $share; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Delete a share (owner unShares the file) |
|
657 | - * |
|
658 | - * @param IShare $share |
|
659 | - */ |
|
660 | - public function delete(IShare $share) { |
|
661 | - $this->removeShareFromTable($share->getId()); |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * @inheritdoc |
|
666 | - */ |
|
667 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
668 | - // nothing to do here, mail shares are only outgoing shares |
|
669 | - return; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * @inheritdoc |
|
674 | - */ |
|
675 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
676 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
677 | - $qb->select('*') |
|
678 | - ->from('share'); |
|
679 | - |
|
680 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
681 | - |
|
682 | - /** |
|
683 | - * Reshares for this user are shares where they are the owner. |
|
684 | - */ |
|
685 | - if ($reshares === false) { |
|
686 | - //Special case for old shares created via the web UI |
|
687 | - $or1 = $qb->expr()->andX( |
|
688 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
689 | - $qb->expr()->isNull('uid_initiator') |
|
690 | - ); |
|
691 | - |
|
692 | - $qb->andWhere( |
|
693 | - $qb->expr()->orX( |
|
694 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
695 | - $or1 |
|
696 | - ) |
|
697 | - ); |
|
698 | - } else { |
|
699 | - $qb->andWhere( |
|
700 | - $qb->expr()->orX( |
|
701 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
702 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
703 | - ) |
|
704 | - ); |
|
705 | - } |
|
706 | - |
|
707 | - if ($node !== null) { |
|
708 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
709 | - } |
|
710 | - |
|
711 | - if ($limit !== -1) { |
|
712 | - $qb->setMaxResults($limit); |
|
713 | - } |
|
714 | - |
|
715 | - $qb->setFirstResult($offset); |
|
716 | - $qb->orderBy('id'); |
|
717 | - |
|
718 | - $cursor = $qb->execute(); |
|
719 | - $shares = []; |
|
720 | - while($data = $cursor->fetch()) { |
|
721 | - $shares[] = $this->createShareObject($data); |
|
722 | - } |
|
723 | - $cursor->closeCursor(); |
|
724 | - |
|
725 | - return $shares; |
|
726 | - } |
|
727 | - |
|
728 | - /** |
|
729 | - * @inheritdoc |
|
730 | - */ |
|
731 | - public function getShareById($id, $recipientId = null) { |
|
732 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
733 | - |
|
734 | - $qb->select('*') |
|
735 | - ->from('share') |
|
736 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
737 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
738 | - |
|
739 | - $cursor = $qb->execute(); |
|
740 | - $data = $cursor->fetch(); |
|
741 | - $cursor->closeCursor(); |
|
742 | - |
|
743 | - if ($data === false) { |
|
744 | - throw new ShareNotFound(); |
|
745 | - } |
|
746 | - |
|
747 | - try { |
|
748 | - $share = $this->createShareObject($data); |
|
749 | - } catch (InvalidShare $e) { |
|
750 | - throw new ShareNotFound(); |
|
751 | - } |
|
752 | - |
|
753 | - return $share; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Get shares for a given path |
|
758 | - * |
|
759 | - * @param \OCP\Files\Node $path |
|
760 | - * @return IShare[] |
|
761 | - */ |
|
762 | - public function getSharesByPath(Node $path) { |
|
763 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
764 | - |
|
765 | - $cursor = $qb->select('*') |
|
766 | - ->from('share') |
|
767 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
768 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
769 | - ->execute(); |
|
770 | - |
|
771 | - $shares = []; |
|
772 | - while($data = $cursor->fetch()) { |
|
773 | - $shares[] = $this->createShareObject($data); |
|
774 | - } |
|
775 | - $cursor->closeCursor(); |
|
776 | - |
|
777 | - return $shares; |
|
778 | - } |
|
779 | - |
|
780 | - /** |
|
781 | - * @inheritdoc |
|
782 | - */ |
|
783 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
784 | - /** @var IShare[] $shares */ |
|
785 | - $shares = []; |
|
786 | - |
|
787 | - //Get shares directly with this user |
|
788 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
789 | - $qb->select('*') |
|
790 | - ->from('share'); |
|
791 | - |
|
792 | - // Order by id |
|
793 | - $qb->orderBy('id'); |
|
794 | - |
|
795 | - // Set limit and offset |
|
796 | - if ($limit !== -1) { |
|
797 | - $qb->setMaxResults($limit); |
|
798 | - } |
|
799 | - $qb->setFirstResult($offset); |
|
800 | - |
|
801 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
802 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
803 | - |
|
804 | - // Filter by node if provided |
|
805 | - if ($node !== null) { |
|
806 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
807 | - } |
|
808 | - |
|
809 | - $cursor = $qb->execute(); |
|
810 | - |
|
811 | - while($data = $cursor->fetch()) { |
|
812 | - $shares[] = $this->createShareObject($data); |
|
813 | - } |
|
814 | - $cursor->closeCursor(); |
|
815 | - |
|
816 | - |
|
817 | - return $shares; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Get a share by token |
|
822 | - * |
|
823 | - * @param string $token |
|
824 | - * @return IShare |
|
825 | - * @throws ShareNotFound |
|
826 | - */ |
|
827 | - public function getShareByToken($token) { |
|
828 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
829 | - |
|
830 | - $cursor = $qb->select('*') |
|
831 | - ->from('share') |
|
832 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
833 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
834 | - ->execute(); |
|
835 | - |
|
836 | - $data = $cursor->fetch(); |
|
837 | - |
|
838 | - if ($data === false) { |
|
839 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
840 | - } |
|
841 | - |
|
842 | - try { |
|
843 | - $share = $this->createShareObject($data); |
|
844 | - } catch (InvalidShare $e) { |
|
845 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
846 | - } |
|
847 | - |
|
848 | - return $share; |
|
849 | - } |
|
850 | - |
|
851 | - /** |
|
852 | - * remove share from table |
|
853 | - * |
|
854 | - * @param string $shareId |
|
855 | - */ |
|
856 | - protected function removeShareFromTable($shareId) { |
|
857 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
858 | - $qb->delete('share') |
|
859 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
860 | - $qb->execute(); |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * Create a share object from an database row |
|
865 | - * |
|
866 | - * @param array $data |
|
867 | - * @return IShare |
|
868 | - * @throws InvalidShare |
|
869 | - * @throws ShareNotFound |
|
870 | - */ |
|
871 | - protected function createShareObject($data) { |
|
872 | - |
|
873 | - $share = new Share($this->rootFolder, $this->userManager); |
|
874 | - $share->setId((int)$data['id']) |
|
875 | - ->setShareType((int)$data['share_type']) |
|
876 | - ->setPermissions((int)$data['permissions']) |
|
877 | - ->setTarget($data['file_target']) |
|
878 | - ->setMailSend((bool)$data['mail_send']) |
|
879 | - ->setToken($data['token']); |
|
880 | - |
|
881 | - $shareTime = new \DateTime(); |
|
882 | - $shareTime->setTimestamp((int)$data['stime']); |
|
883 | - $share->setShareTime($shareTime); |
|
884 | - $share->setSharedWith($data['share_with']); |
|
885 | - $share->setPassword($data['password']); |
|
886 | - |
|
887 | - if ($data['uid_initiator'] !== null) { |
|
888 | - $share->setShareOwner($data['uid_owner']); |
|
889 | - $share->setSharedBy($data['uid_initiator']); |
|
890 | - } else { |
|
891 | - //OLD SHARE |
|
892 | - $share->setSharedBy($data['uid_owner']); |
|
893 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
894 | - |
|
895 | - $owner = $path->getOwner(); |
|
896 | - $share->setShareOwner($owner->getUID()); |
|
897 | - } |
|
898 | - |
|
899 | - if ($data['expiration'] !== null) { |
|
900 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
901 | - if ($expiration !== false) { |
|
902 | - $share->setExpirationDate($expiration); |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - $share->setNodeId((int)$data['file_source']); |
|
907 | - $share->setNodeType($data['item_type']); |
|
908 | - |
|
909 | - $share->setProviderId($this->identifier()); |
|
910 | - |
|
911 | - return $share; |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Get the node with file $id for $user |
|
916 | - * |
|
917 | - * @param string $userId |
|
918 | - * @param int $id |
|
919 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
920 | - * @throws InvalidShare |
|
921 | - */ |
|
922 | - private function getNode($userId, $id) { |
|
923 | - try { |
|
924 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
925 | - } catch (NotFoundException $e) { |
|
926 | - throw new InvalidShare(); |
|
927 | - } |
|
928 | - |
|
929 | - $nodes = $userFolder->getById($id); |
|
930 | - |
|
931 | - if (empty($nodes)) { |
|
932 | - throw new InvalidShare(); |
|
933 | - } |
|
934 | - |
|
935 | - return $nodes[0]; |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * A user is deleted from the system |
|
940 | - * So clean up the relevant shares. |
|
941 | - * |
|
942 | - * @param string $uid |
|
943 | - * @param int $shareType |
|
944 | - */ |
|
945 | - public function userDeleted($uid, $shareType) { |
|
946 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
947 | - |
|
948 | - $qb->delete('share') |
|
949 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
950 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
951 | - ->execute(); |
|
952 | - } |
|
953 | - |
|
954 | - /** |
|
955 | - * This provider does not support group shares |
|
956 | - * |
|
957 | - * @param string $gid |
|
958 | - */ |
|
959 | - public function groupDeleted($gid) { |
|
960 | - return; |
|
961 | - } |
|
962 | - |
|
963 | - /** |
|
964 | - * This provider does not support group shares |
|
965 | - * |
|
966 | - * @param string $uid |
|
967 | - * @param string $gid |
|
968 | - */ |
|
969 | - public function userDeletedFromGroup($uid, $gid) { |
|
970 | - return; |
|
971 | - } |
|
972 | - |
|
973 | - /** |
|
974 | - * get database row of a give share |
|
975 | - * |
|
976 | - * @param $id |
|
977 | - * @return array |
|
978 | - * @throws ShareNotFound |
|
979 | - */ |
|
980 | - protected function getRawShare($id) { |
|
981 | - |
|
982 | - // Now fetch the inserted share and create a complete share object |
|
983 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
984 | - $qb->select('*') |
|
985 | - ->from('share') |
|
986 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
987 | - |
|
988 | - $cursor = $qb->execute(); |
|
989 | - $data = $cursor->fetch(); |
|
990 | - $cursor->closeCursor(); |
|
991 | - |
|
992 | - if ($data === false) { |
|
993 | - throw new ShareNotFound; |
|
994 | - } |
|
995 | - |
|
996 | - return $data; |
|
997 | - } |
|
998 | - |
|
999 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
1000 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1001 | - $qb->select('*') |
|
1002 | - ->from('share', 's') |
|
1003 | - ->andWhere($qb->expr()->orX( |
|
1004 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1005 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1006 | - )) |
|
1007 | - ->andWhere( |
|
1008 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
1009 | - ); |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Reshares for this user are shares where they are the owner. |
|
1013 | - */ |
|
1014 | - if ($reshares === false) { |
|
1015 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
1016 | - } else { |
|
1017 | - $qb->andWhere( |
|
1018 | - $qb->expr()->orX( |
|
1019 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
1020 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
1021 | - ) |
|
1022 | - ); |
|
1023 | - } |
|
1024 | - |
|
1025 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1026 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1027 | - |
|
1028 | - $qb->orderBy('id'); |
|
1029 | - |
|
1030 | - $cursor = $qb->execute(); |
|
1031 | - $shares = []; |
|
1032 | - while ($data = $cursor->fetch()) { |
|
1033 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1034 | - } |
|
1035 | - $cursor->closeCursor(); |
|
1036 | - |
|
1037 | - return $shares; |
|
1038 | - } |
|
1039 | - |
|
1040 | - /** |
|
1041 | - * @inheritdoc |
|
1042 | - */ |
|
1043 | - public function getAccessList($nodes, $currentAccess) { |
|
1044 | - $ids = []; |
|
1045 | - foreach ($nodes as $node) { |
|
1046 | - $ids[] = $node->getId(); |
|
1047 | - } |
|
1048 | - |
|
1049 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1050 | - $qb->select('share_with') |
|
1051 | - ->from('share') |
|
1052 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1053 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1054 | - ->andWhere($qb->expr()->orX( |
|
1055 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1056 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1057 | - )) |
|
1058 | - ->setMaxResults(1); |
|
1059 | - $cursor = $qb->execute(); |
|
1060 | - |
|
1061 | - $mail = $cursor->fetch() !== false; |
|
1062 | - $cursor->closeCursor(); |
|
1063 | - |
|
1064 | - return ['public' => $mail]; |
|
1065 | - } |
|
632 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
633 | + $qb->update('share') |
|
634 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
635 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
636 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
637 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
638 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
639 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
640 | + ->execute(); |
|
641 | + |
|
642 | + return $share; |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * @inheritdoc |
|
647 | + */ |
|
648 | + public function move(IShare $share, $recipient) { |
|
649 | + /** |
|
650 | + * nothing to do here, mail shares are only outgoing shares |
|
651 | + */ |
|
652 | + return $share; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Delete a share (owner unShares the file) |
|
657 | + * |
|
658 | + * @param IShare $share |
|
659 | + */ |
|
660 | + public function delete(IShare $share) { |
|
661 | + $this->removeShareFromTable($share->getId()); |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * @inheritdoc |
|
666 | + */ |
|
667 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
668 | + // nothing to do here, mail shares are only outgoing shares |
|
669 | + return; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * @inheritdoc |
|
674 | + */ |
|
675 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
676 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
677 | + $qb->select('*') |
|
678 | + ->from('share'); |
|
679 | + |
|
680 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
681 | + |
|
682 | + /** |
|
683 | + * Reshares for this user are shares where they are the owner. |
|
684 | + */ |
|
685 | + if ($reshares === false) { |
|
686 | + //Special case for old shares created via the web UI |
|
687 | + $or1 = $qb->expr()->andX( |
|
688 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
689 | + $qb->expr()->isNull('uid_initiator') |
|
690 | + ); |
|
691 | + |
|
692 | + $qb->andWhere( |
|
693 | + $qb->expr()->orX( |
|
694 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
695 | + $or1 |
|
696 | + ) |
|
697 | + ); |
|
698 | + } else { |
|
699 | + $qb->andWhere( |
|
700 | + $qb->expr()->orX( |
|
701 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
702 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
703 | + ) |
|
704 | + ); |
|
705 | + } |
|
706 | + |
|
707 | + if ($node !== null) { |
|
708 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
709 | + } |
|
710 | + |
|
711 | + if ($limit !== -1) { |
|
712 | + $qb->setMaxResults($limit); |
|
713 | + } |
|
714 | + |
|
715 | + $qb->setFirstResult($offset); |
|
716 | + $qb->orderBy('id'); |
|
717 | + |
|
718 | + $cursor = $qb->execute(); |
|
719 | + $shares = []; |
|
720 | + while($data = $cursor->fetch()) { |
|
721 | + $shares[] = $this->createShareObject($data); |
|
722 | + } |
|
723 | + $cursor->closeCursor(); |
|
724 | + |
|
725 | + return $shares; |
|
726 | + } |
|
727 | + |
|
728 | + /** |
|
729 | + * @inheritdoc |
|
730 | + */ |
|
731 | + public function getShareById($id, $recipientId = null) { |
|
732 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
733 | + |
|
734 | + $qb->select('*') |
|
735 | + ->from('share') |
|
736 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
737 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
738 | + |
|
739 | + $cursor = $qb->execute(); |
|
740 | + $data = $cursor->fetch(); |
|
741 | + $cursor->closeCursor(); |
|
742 | + |
|
743 | + if ($data === false) { |
|
744 | + throw new ShareNotFound(); |
|
745 | + } |
|
746 | + |
|
747 | + try { |
|
748 | + $share = $this->createShareObject($data); |
|
749 | + } catch (InvalidShare $e) { |
|
750 | + throw new ShareNotFound(); |
|
751 | + } |
|
752 | + |
|
753 | + return $share; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Get shares for a given path |
|
758 | + * |
|
759 | + * @param \OCP\Files\Node $path |
|
760 | + * @return IShare[] |
|
761 | + */ |
|
762 | + public function getSharesByPath(Node $path) { |
|
763 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
764 | + |
|
765 | + $cursor = $qb->select('*') |
|
766 | + ->from('share') |
|
767 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
768 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
769 | + ->execute(); |
|
770 | + |
|
771 | + $shares = []; |
|
772 | + while($data = $cursor->fetch()) { |
|
773 | + $shares[] = $this->createShareObject($data); |
|
774 | + } |
|
775 | + $cursor->closeCursor(); |
|
776 | + |
|
777 | + return $shares; |
|
778 | + } |
|
779 | + |
|
780 | + /** |
|
781 | + * @inheritdoc |
|
782 | + */ |
|
783 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
784 | + /** @var IShare[] $shares */ |
|
785 | + $shares = []; |
|
786 | + |
|
787 | + //Get shares directly with this user |
|
788 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
789 | + $qb->select('*') |
|
790 | + ->from('share'); |
|
791 | + |
|
792 | + // Order by id |
|
793 | + $qb->orderBy('id'); |
|
794 | + |
|
795 | + // Set limit and offset |
|
796 | + if ($limit !== -1) { |
|
797 | + $qb->setMaxResults($limit); |
|
798 | + } |
|
799 | + $qb->setFirstResult($offset); |
|
800 | + |
|
801 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
802 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
803 | + |
|
804 | + // Filter by node if provided |
|
805 | + if ($node !== null) { |
|
806 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
807 | + } |
|
808 | + |
|
809 | + $cursor = $qb->execute(); |
|
810 | + |
|
811 | + while($data = $cursor->fetch()) { |
|
812 | + $shares[] = $this->createShareObject($data); |
|
813 | + } |
|
814 | + $cursor->closeCursor(); |
|
815 | + |
|
816 | + |
|
817 | + return $shares; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Get a share by token |
|
822 | + * |
|
823 | + * @param string $token |
|
824 | + * @return IShare |
|
825 | + * @throws ShareNotFound |
|
826 | + */ |
|
827 | + public function getShareByToken($token) { |
|
828 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
829 | + |
|
830 | + $cursor = $qb->select('*') |
|
831 | + ->from('share') |
|
832 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
833 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
834 | + ->execute(); |
|
835 | + |
|
836 | + $data = $cursor->fetch(); |
|
837 | + |
|
838 | + if ($data === false) { |
|
839 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
840 | + } |
|
841 | + |
|
842 | + try { |
|
843 | + $share = $this->createShareObject($data); |
|
844 | + } catch (InvalidShare $e) { |
|
845 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
846 | + } |
|
847 | + |
|
848 | + return $share; |
|
849 | + } |
|
850 | + |
|
851 | + /** |
|
852 | + * remove share from table |
|
853 | + * |
|
854 | + * @param string $shareId |
|
855 | + */ |
|
856 | + protected function removeShareFromTable($shareId) { |
|
857 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
858 | + $qb->delete('share') |
|
859 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
860 | + $qb->execute(); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Create a share object from an database row |
|
865 | + * |
|
866 | + * @param array $data |
|
867 | + * @return IShare |
|
868 | + * @throws InvalidShare |
|
869 | + * @throws ShareNotFound |
|
870 | + */ |
|
871 | + protected function createShareObject($data) { |
|
872 | + |
|
873 | + $share = new Share($this->rootFolder, $this->userManager); |
|
874 | + $share->setId((int)$data['id']) |
|
875 | + ->setShareType((int)$data['share_type']) |
|
876 | + ->setPermissions((int)$data['permissions']) |
|
877 | + ->setTarget($data['file_target']) |
|
878 | + ->setMailSend((bool)$data['mail_send']) |
|
879 | + ->setToken($data['token']); |
|
880 | + |
|
881 | + $shareTime = new \DateTime(); |
|
882 | + $shareTime->setTimestamp((int)$data['stime']); |
|
883 | + $share->setShareTime($shareTime); |
|
884 | + $share->setSharedWith($data['share_with']); |
|
885 | + $share->setPassword($data['password']); |
|
886 | + |
|
887 | + if ($data['uid_initiator'] !== null) { |
|
888 | + $share->setShareOwner($data['uid_owner']); |
|
889 | + $share->setSharedBy($data['uid_initiator']); |
|
890 | + } else { |
|
891 | + //OLD SHARE |
|
892 | + $share->setSharedBy($data['uid_owner']); |
|
893 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
894 | + |
|
895 | + $owner = $path->getOwner(); |
|
896 | + $share->setShareOwner($owner->getUID()); |
|
897 | + } |
|
898 | + |
|
899 | + if ($data['expiration'] !== null) { |
|
900 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
901 | + if ($expiration !== false) { |
|
902 | + $share->setExpirationDate($expiration); |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + $share->setNodeId((int)$data['file_source']); |
|
907 | + $share->setNodeType($data['item_type']); |
|
908 | + |
|
909 | + $share->setProviderId($this->identifier()); |
|
910 | + |
|
911 | + return $share; |
|
912 | + } |
|
913 | + |
|
914 | + /** |
|
915 | + * Get the node with file $id for $user |
|
916 | + * |
|
917 | + * @param string $userId |
|
918 | + * @param int $id |
|
919 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
920 | + * @throws InvalidShare |
|
921 | + */ |
|
922 | + private function getNode($userId, $id) { |
|
923 | + try { |
|
924 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
925 | + } catch (NotFoundException $e) { |
|
926 | + throw new InvalidShare(); |
|
927 | + } |
|
928 | + |
|
929 | + $nodes = $userFolder->getById($id); |
|
930 | + |
|
931 | + if (empty($nodes)) { |
|
932 | + throw new InvalidShare(); |
|
933 | + } |
|
934 | + |
|
935 | + return $nodes[0]; |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * A user is deleted from the system |
|
940 | + * So clean up the relevant shares. |
|
941 | + * |
|
942 | + * @param string $uid |
|
943 | + * @param int $shareType |
|
944 | + */ |
|
945 | + public function userDeleted($uid, $shareType) { |
|
946 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
947 | + |
|
948 | + $qb->delete('share') |
|
949 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
950 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
951 | + ->execute(); |
|
952 | + } |
|
953 | + |
|
954 | + /** |
|
955 | + * This provider does not support group shares |
|
956 | + * |
|
957 | + * @param string $gid |
|
958 | + */ |
|
959 | + public function groupDeleted($gid) { |
|
960 | + return; |
|
961 | + } |
|
962 | + |
|
963 | + /** |
|
964 | + * This provider does not support group shares |
|
965 | + * |
|
966 | + * @param string $uid |
|
967 | + * @param string $gid |
|
968 | + */ |
|
969 | + public function userDeletedFromGroup($uid, $gid) { |
|
970 | + return; |
|
971 | + } |
|
972 | + |
|
973 | + /** |
|
974 | + * get database row of a give share |
|
975 | + * |
|
976 | + * @param $id |
|
977 | + * @return array |
|
978 | + * @throws ShareNotFound |
|
979 | + */ |
|
980 | + protected function getRawShare($id) { |
|
981 | + |
|
982 | + // Now fetch the inserted share and create a complete share object |
|
983 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
984 | + $qb->select('*') |
|
985 | + ->from('share') |
|
986 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
987 | + |
|
988 | + $cursor = $qb->execute(); |
|
989 | + $data = $cursor->fetch(); |
|
990 | + $cursor->closeCursor(); |
|
991 | + |
|
992 | + if ($data === false) { |
|
993 | + throw new ShareNotFound; |
|
994 | + } |
|
995 | + |
|
996 | + return $data; |
|
997 | + } |
|
998 | + |
|
999 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
1000 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1001 | + $qb->select('*') |
|
1002 | + ->from('share', 's') |
|
1003 | + ->andWhere($qb->expr()->orX( |
|
1004 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1005 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1006 | + )) |
|
1007 | + ->andWhere( |
|
1008 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
1009 | + ); |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Reshares for this user are shares where they are the owner. |
|
1013 | + */ |
|
1014 | + if ($reshares === false) { |
|
1015 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
1016 | + } else { |
|
1017 | + $qb->andWhere( |
|
1018 | + $qb->expr()->orX( |
|
1019 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
1020 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
1021 | + ) |
|
1022 | + ); |
|
1023 | + } |
|
1024 | + |
|
1025 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1026 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1027 | + |
|
1028 | + $qb->orderBy('id'); |
|
1029 | + |
|
1030 | + $cursor = $qb->execute(); |
|
1031 | + $shares = []; |
|
1032 | + while ($data = $cursor->fetch()) { |
|
1033 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1034 | + } |
|
1035 | + $cursor->closeCursor(); |
|
1036 | + |
|
1037 | + return $shares; |
|
1038 | + } |
|
1039 | + |
|
1040 | + /** |
|
1041 | + * @inheritdoc |
|
1042 | + */ |
|
1043 | + public function getAccessList($nodes, $currentAccess) { |
|
1044 | + $ids = []; |
|
1045 | + foreach ($nodes as $node) { |
|
1046 | + $ids[] = $node->getId(); |
|
1047 | + } |
|
1048 | + |
|
1049 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1050 | + $qb->select('share_with') |
|
1051 | + ->from('share') |
|
1052 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1053 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1054 | + ->andWhere($qb->expr()->orX( |
|
1055 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1056 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1057 | + )) |
|
1058 | + ->setMaxResults(1); |
|
1059 | + $cursor = $qb->execute(); |
|
1060 | + |
|
1061 | + $mail = $cursor->fetch() !== false; |
|
1062 | + $cursor->closeCursor(); |
|
1063 | + |
|
1064 | + return ['public' => $mail]; |
|
1065 | + } |
|
1066 | 1066 | |
1067 | 1067 | } |