@@ -32,97 +32,97 @@ |
||
32 | 32 | use OCP\Files\StorageNotAvailableException; |
33 | 33 | |
34 | 34 | class Scanner extends \OC\Files\Cache\Scanner { |
35 | - /** @var \OCA\Files_Sharing\External\Storage */ |
|
36 | - protected $storage; |
|
35 | + /** @var \OCA\Files_Sharing\External\Storage */ |
|
36 | + protected $storage; |
|
37 | 37 | |
38 | - /** {@inheritDoc} */ |
|
39 | - public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
40 | - if(!$this->storage->remoteIsOwnCloud()) { |
|
41 | - return parent::scan($path, $recursive, $recursive, $lock); |
|
42 | - } |
|
38 | + /** {@inheritDoc} */ |
|
39 | + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
|
40 | + if(!$this->storage->remoteIsOwnCloud()) { |
|
41 | + return parent::scan($path, $recursive, $recursive, $lock); |
|
42 | + } |
|
43 | 43 | |
44 | - $this->scanAll(); |
|
45 | - } |
|
44 | + $this->scanAll(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Scan a single file and store it in the cache. |
|
49 | - * If an exception happened while accessing the external storage, |
|
50 | - * the storage will be checked for availability and removed |
|
51 | - * if it is not available any more. |
|
52 | - * |
|
53 | - * @param string $file file to scan |
|
54 | - * @param int $reuseExisting |
|
55 | - * @param int $parentId |
|
56 | - * @param array | null $cacheData existing data in the cache for the file to be scanned |
|
57 | - * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
58 | - * @return array an array of metadata of the scanned file |
|
59 | - */ |
|
60 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
61 | - try { |
|
62 | - return parent::scanFile($file, $reuseExisting); |
|
63 | - } catch (ForbiddenException $e) { |
|
64 | - $this->storage->checkStorageAvailability(); |
|
65 | - } catch (NotFoundException $e) { |
|
66 | - // if the storage isn't found, the call to |
|
67 | - // checkStorageAvailable() will verify it and remove it |
|
68 | - // if appropriate |
|
69 | - $this->storage->checkStorageAvailability(); |
|
70 | - } catch (StorageInvalidException $e) { |
|
71 | - $this->storage->checkStorageAvailability(); |
|
72 | - } catch (StorageNotAvailableException $e) { |
|
73 | - $this->storage->checkStorageAvailability(); |
|
74 | - } |
|
75 | - } |
|
47 | + /** |
|
48 | + * Scan a single file and store it in the cache. |
|
49 | + * If an exception happened while accessing the external storage, |
|
50 | + * the storage will be checked for availability and removed |
|
51 | + * if it is not available any more. |
|
52 | + * |
|
53 | + * @param string $file file to scan |
|
54 | + * @param int $reuseExisting |
|
55 | + * @param int $parentId |
|
56 | + * @param array | null $cacheData existing data in the cache for the file to be scanned |
|
57 | + * @param bool $lock set to false to disable getting an additional read lock during scanning |
|
58 | + * @return array an array of metadata of the scanned file |
|
59 | + */ |
|
60 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
61 | + try { |
|
62 | + return parent::scanFile($file, $reuseExisting); |
|
63 | + } catch (ForbiddenException $e) { |
|
64 | + $this->storage->checkStorageAvailability(); |
|
65 | + } catch (NotFoundException $e) { |
|
66 | + // if the storage isn't found, the call to |
|
67 | + // checkStorageAvailable() will verify it and remove it |
|
68 | + // if appropriate |
|
69 | + $this->storage->checkStorageAvailability(); |
|
70 | + } catch (StorageInvalidException $e) { |
|
71 | + $this->storage->checkStorageAvailability(); |
|
72 | + } catch (StorageNotAvailableException $e) { |
|
73 | + $this->storage->checkStorageAvailability(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Checks the remote share for changes. |
|
79 | - * If changes are available, scan them and update |
|
80 | - * the cache. |
|
81 | - * @throws NotFoundException |
|
82 | - * @throws StorageInvalidException |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
85 | - public function scanAll() { |
|
86 | - try { |
|
87 | - $data = $this->storage->getShareInfo(); |
|
88 | - } catch (\Exception $e) { |
|
89 | - $this->storage->checkStorageAvailability(); |
|
90 | - throw new \Exception( |
|
91 | - 'Error while scanning remote share: "' . |
|
92 | - $this->storage->getRemote() . '" ' . |
|
93 | - $e->getMessage() |
|
94 | - ); |
|
95 | - } |
|
96 | - if ($data['status'] === 'success') { |
|
97 | - $this->addResult($data['data'], ''); |
|
98 | - } else { |
|
99 | - throw new \Exception( |
|
100 | - 'Error while scanning remote share: "' . |
|
101 | - $this->storage->getRemote() . '"' |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
77 | + /** |
|
78 | + * Checks the remote share for changes. |
|
79 | + * If changes are available, scan them and update |
|
80 | + * the cache. |
|
81 | + * @throws NotFoundException |
|
82 | + * @throws StorageInvalidException |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | + public function scanAll() { |
|
86 | + try { |
|
87 | + $data = $this->storage->getShareInfo(); |
|
88 | + } catch (\Exception $e) { |
|
89 | + $this->storage->checkStorageAvailability(); |
|
90 | + throw new \Exception( |
|
91 | + 'Error while scanning remote share: "' . |
|
92 | + $this->storage->getRemote() . '" ' . |
|
93 | + $e->getMessage() |
|
94 | + ); |
|
95 | + } |
|
96 | + if ($data['status'] === 'success') { |
|
97 | + $this->addResult($data['data'], ''); |
|
98 | + } else { |
|
99 | + throw new \Exception( |
|
100 | + 'Error while scanning remote share: "' . |
|
101 | + $this->storage->getRemote() . '"' |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param array $data |
|
108 | - * @param string $path |
|
109 | - */ |
|
110 | - private function addResult($data, $path) { |
|
111 | - $id = $this->cache->put($path, $data); |
|
112 | - if (isset($data['children'])) { |
|
113 | - $children = []; |
|
114 | - foreach ($data['children'] as $child) { |
|
115 | - $children[$child['name']] = true; |
|
116 | - $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
117 | - } |
|
106 | + /** |
|
107 | + * @param array $data |
|
108 | + * @param string $path |
|
109 | + */ |
|
110 | + private function addResult($data, $path) { |
|
111 | + $id = $this->cache->put($path, $data); |
|
112 | + if (isset($data['children'])) { |
|
113 | + $children = []; |
|
114 | + foreach ($data['children'] as $child) { |
|
115 | + $children[$child['name']] = true; |
|
116 | + $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
117 | + } |
|
118 | 118 | |
119 | - $existingCache = $this->cache->getFolderContentsById($id); |
|
120 | - foreach ($existingCache as $existingChild) { |
|
121 | - // if an existing child is not in the new data, remove it |
|
122 | - if (!isset($children[$existingChild['name']])) { |
|
123 | - $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
119 | + $existingCache = $this->cache->getFolderContentsById($id); |
|
120 | + foreach ($existingCache as $existingChild) { |
|
121 | + // if an existing child is not in the new data, remove it |
|
122 | + if (!isset($children[$existingChild['name']])) { |
|
123 | + $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | /** {@inheritDoc} */ |
39 | 39 | public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
40 | - if(!$this->storage->remoteIsOwnCloud()) { |
|
40 | + if (!$this->storage->remoteIsOwnCloud()) { |
|
41 | 41 | return parent::scan($path, $recursive, $recursive, $lock); |
42 | 42 | } |
43 | 43 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | } catch (\Exception $e) { |
89 | 89 | $this->storage->checkStorageAvailability(); |
90 | 90 | throw new \Exception( |
91 | - 'Error while scanning remote share: "' . |
|
92 | - $this->storage->getRemote() . '" ' . |
|
91 | + 'Error while scanning remote share: "'. |
|
92 | + $this->storage->getRemote().'" '. |
|
93 | 93 | $e->getMessage() |
94 | 94 | ); |
95 | 95 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | $this->addResult($data['data'], ''); |
98 | 98 | } else { |
99 | 99 | throw new \Exception( |
100 | - 'Error while scanning remote share: "' . |
|
101 | - $this->storage->getRemote() . '"' |
|
100 | + 'Error while scanning remote share: "'. |
|
101 | + $this->storage->getRemote().'"' |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $children = []; |
114 | 114 | foreach ($data['children'] as $child) { |
115 | 115 | $children[$child['name']] = true; |
116 | - $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); |
|
116 | + $this->addResult($child, ltrim($path.'/'.$child['name'], '/')); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | $existingCache = $this->cache->getFolderContentsById($id); |
120 | 120 | foreach ($existingCache as $existingChild) { |
121 | 121 | // if an existing child is not in the new data, remove it |
122 | 122 | if (!isset($children[$existingChild['name']])) { |
123 | - $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/')); |
|
123 | + $this->cache->remove(ltrim($path.'/'.$existingChild['name'], '/')); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -27,44 +27,44 @@ |
||
27 | 27 | use OCP\Federation\ICloudId; |
28 | 28 | |
29 | 29 | class Cache extends \OC\Files\Cache\Cache { |
30 | - /** @var ICloudId */ |
|
31 | - private $cloudId; |
|
32 | - private $remote; |
|
33 | - private $remoteUser; |
|
34 | - private $storage; |
|
30 | + /** @var ICloudId */ |
|
31 | + private $cloudId; |
|
32 | + private $remote; |
|
33 | + private $remoteUser; |
|
34 | + private $storage; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCA\Files_Sharing\External\Storage $storage |
|
38 | - * @param ICloudId $cloudId |
|
39 | - */ |
|
40 | - public function __construct($storage, ICloudId $cloudId) { |
|
41 | - $this->cloudId = $cloudId; |
|
42 | - $this->storage = $storage; |
|
43 | - list(, $remote) = explode('://', $cloudId->getRemote(), 2); |
|
44 | - $this->remote = $remote; |
|
45 | - $this->remoteUser = $cloudId->getUser(); |
|
46 | - parent::__construct($storage); |
|
47 | - } |
|
36 | + /** |
|
37 | + * @param \OCA\Files_Sharing\External\Storage $storage |
|
38 | + * @param ICloudId $cloudId |
|
39 | + */ |
|
40 | + public function __construct($storage, ICloudId $cloudId) { |
|
41 | + $this->cloudId = $cloudId; |
|
42 | + $this->storage = $storage; |
|
43 | + list(, $remote) = explode('://', $cloudId->getRemote(), 2); |
|
44 | + $this->remote = $remote; |
|
45 | + $this->remoteUser = $cloudId->getUser(); |
|
46 | + parent::__construct($storage); |
|
47 | + } |
|
48 | 48 | |
49 | - public function get($file) { |
|
50 | - $result = parent::get($file); |
|
51 | - if (!$result) { |
|
52 | - return false; |
|
53 | - } |
|
54 | - $result['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
55 | - if (!$file || $file === '') { |
|
56 | - $result['is_share_mount_point'] = true; |
|
57 | - $mountPoint = rtrim($this->storage->getMountPoint()); |
|
58 | - $result['name'] = basename($mountPoint); |
|
59 | - } |
|
60 | - return $result; |
|
61 | - } |
|
49 | + public function get($file) { |
|
50 | + $result = parent::get($file); |
|
51 | + if (!$result) { |
|
52 | + return false; |
|
53 | + } |
|
54 | + $result['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
55 | + if (!$file || $file === '') { |
|
56 | + $result['is_share_mount_point'] = true; |
|
57 | + $mountPoint = rtrim($this->storage->getMountPoint()); |
|
58 | + $result['name'] = basename($mountPoint); |
|
59 | + } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | |
63 | - public function getFolderContentsById($id) { |
|
64 | - $results = parent::getFolderContentsById($id); |
|
65 | - foreach ($results as &$file) { |
|
66 | - $file['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
67 | - } |
|
68 | - return $results; |
|
69 | - } |
|
63 | + public function getFolderContentsById($id) { |
|
64 | + $results = parent::getFolderContentsById($id); |
|
65 | + foreach ($results as &$file) { |
|
66 | + $file['displayname_owner'] = $this->cloudId->getDisplayId(); |
|
67 | + } |
|
68 | + return $results; |
|
69 | + } |
|
70 | 70 | } |
@@ -29,59 +29,59 @@ |
||
29 | 29 | use OCP\IUser; |
30 | 30 | |
31 | 31 | class MountProvider implements IMountProvider { |
32 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
32 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var \OCP\IDBConnection |
|
36 | - */ |
|
37 | - private $connection; |
|
34 | + /** |
|
35 | + * @var \OCP\IDBConnection |
|
36 | + */ |
|
37 | + private $connection; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var callable |
|
41 | - */ |
|
42 | - private $managerProvider; |
|
39 | + /** |
|
40 | + * @var callable |
|
41 | + */ |
|
42 | + private $managerProvider; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var ICloudIdManager |
|
46 | - */ |
|
47 | - private $cloudIdManager; |
|
44 | + /** |
|
45 | + * @var ICloudIdManager |
|
46 | + */ |
|
47 | + private $cloudIdManager; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param \OCP\IDBConnection $connection |
|
51 | - * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
52 | - * @param ICloudIdManager $cloudIdManager |
|
53 | - */ |
|
54 | - public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) { |
|
55 | - $this->connection = $connection; |
|
56 | - $this->managerProvider = $managerProvider; |
|
57 | - $this->cloudIdManager = $cloudIdManager; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param \OCP\IDBConnection $connection |
|
51 | + * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
52 | + * @param ICloudIdManager $cloudIdManager |
|
53 | + */ |
|
54 | + public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) { |
|
55 | + $this->connection = $connection; |
|
56 | + $this->managerProvider = $managerProvider; |
|
57 | + $this->cloudIdManager = $cloudIdManager; |
|
58 | + } |
|
59 | 59 | |
60 | - public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
61 | - $managerProvider = $this->managerProvider; |
|
62 | - $manager = $managerProvider(); |
|
63 | - $data['manager'] = $manager; |
|
64 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
65 | - $data['mountpoint'] = $mountPoint; |
|
66 | - $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
67 | - $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
|
68 | - $data['HttpClientService'] = \OC::$server->getHTTPClientService(); |
|
69 | - return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
70 | - } |
|
60 | + public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
61 | + $managerProvider = $this->managerProvider; |
|
62 | + $manager = $managerProvider(); |
|
63 | + $data['manager'] = $manager; |
|
64 | + $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
65 | + $data['mountpoint'] = $mountPoint; |
|
66 | + $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
67 | + $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
|
68 | + $data['HttpClientService'] = \OC::$server->getHTTPClientService(); |
|
69 | + return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
70 | + } |
|
71 | 71 | |
72 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
73 | - $query = $this->connection->prepare(' |
|
72 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
73 | + $query = $this->connection->prepare(' |
|
74 | 74 | SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` |
75 | 75 | FROM `*PREFIX*share_external` |
76 | 76 | WHERE `user` = ? AND `accepted` = ? |
77 | 77 | '); |
78 | - $query->execute([$user->getUID(), 1]); |
|
79 | - $mounts = []; |
|
80 | - while ($row = $query->fetch()) { |
|
81 | - $row['manager'] = $this; |
|
82 | - $row['token'] = $row['share_token']; |
|
83 | - $mounts[] = $this->getMount($user, $row, $loader); |
|
84 | - } |
|
85 | - return $mounts; |
|
86 | - } |
|
78 | + $query->execute([$user->getUID(), 1]); |
|
79 | + $mounts = []; |
|
80 | + while ($row = $query->fetch()) { |
|
81 | + $row['manager'] = $this; |
|
82 | + $row['token'] = $row['share_token']; |
|
83 | + $mounts[] = $this->getMount($user, $row, $loader); |
|
84 | + } |
|
85 | + return $mounts; |
|
86 | + } |
|
87 | 87 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | $managerProvider = $this->managerProvider; |
62 | 62 | $manager = $managerProvider(); |
63 | 63 | $data['manager'] = $manager; |
64 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
64 | + $mountPoint = '/'.$user->getUID().'/files/'.ltrim($data['mountpoint'], '/'); |
|
65 | 65 | $data['mountpoint'] = $mountPoint; |
66 | 66 | $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
67 | 67 | $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); |
@@ -23,12 +23,12 @@ |
||
23 | 23 | namespace OCA\Files_Sharing\External; |
24 | 24 | |
25 | 25 | class Watcher extends \OC\Files\Cache\Watcher { |
26 | - /** |
|
27 | - * remove deleted files in $path from the cache |
|
28 | - * |
|
29 | - * @param string $path |
|
30 | - */ |
|
31 | - public function cleanFolder($path) { |
|
32 | - // not needed, the scanner takes care of this |
|
33 | - } |
|
26 | + /** |
|
27 | + * remove deleted files in $path from the cache |
|
28 | + * |
|
29 | + * @param string $path |
|
30 | + */ |
|
31 | + public function cleanFolder($path) { |
|
32 | + // not needed, the scanner takes care of this |
|
33 | + } |
|
34 | 34 | } |
@@ -29,43 +29,43 @@ |
||
29 | 29 | |
30 | 30 | class Mount extends MountPoint implements MoveableMount { |
31 | 31 | |
32 | - /** |
|
33 | - * @var \OCA\Files_Sharing\External\Manager |
|
34 | - */ |
|
35 | - protected $manager; |
|
32 | + /** |
|
33 | + * @var \OCA\Files_Sharing\External\Manager |
|
34 | + */ |
|
35 | + protected $manager; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string|\OC\Files\Storage\Storage $storage |
|
39 | - * @param string $mountpoint |
|
40 | - * @param array $options |
|
41 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | - */ |
|
44 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | - parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | - $this->manager = $manager; |
|
47 | - } |
|
37 | + /** |
|
38 | + * @param string|\OC\Files\Storage\Storage $storage |
|
39 | + * @param string $mountpoint |
|
40 | + * @param array $options |
|
41 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | + */ |
|
44 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | + parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | + $this->manager = $manager; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Move the mount point to $target |
|
51 | - * |
|
52 | - * @param string $target the target mount point |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function moveMount($target) { |
|
56 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | - $this->setMountPoint($target); |
|
49 | + /** |
|
50 | + * Move the mount point to $target |
|
51 | + * |
|
52 | + * @param string $target the target mount point |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function moveMount($target) { |
|
56 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | + $this->setMountPoint($target); |
|
58 | 58 | |
59 | - return $result; |
|
60 | - } |
|
59 | + return $result; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Remove the mount points |
|
64 | - * |
|
65 | - * @return mixed |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function removeMount() { |
|
69 | - return $this->manager->removeShare($this->mountPoint); |
|
70 | - } |
|
62 | + /** |
|
63 | + * Remove the mount points |
|
64 | + * |
|
65 | + * @return mixed |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function removeMount() { |
|
69 | + return $this->manager->removeShare($this->mountPoint); |
|
70 | + } |
|
71 | 71 | } |
@@ -27,81 +27,81 @@ |
||
27 | 27 | |
28 | 28 | class Updater { |
29 | 29 | |
30 | - /** |
|
31 | - * @param array $params |
|
32 | - */ |
|
33 | - static public function renameHook($params) { |
|
34 | - self::renameChildren($params['oldpath'], $params['newpath']); |
|
35 | - self::moveShareToShare($params['newpath']); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Fix for https://github.com/owncloud/core/issues/20769 |
|
40 | - * |
|
41 | - * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
42 | - * In this case we need to update the parent of the moved share. Since they are |
|
43 | - * effectively handing over ownership of the file the rest of the code needs to know |
|
44 | - * they need to build up the reshare tree. |
|
45 | - * |
|
46 | - * @param string $path |
|
47 | - */ |
|
48 | - static private function moveShareToShare($path) { |
|
49 | - $userFolder = \OC::$server->getUserFolder(); |
|
50 | - |
|
51 | - // If the user folder can't be constructed (e.g. link share) just return. |
|
52 | - if ($userFolder === null) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - $src = $userFolder->get($path); |
|
57 | - |
|
58 | - $shareManager = \OC::$server->getShareManager(); |
|
59 | - |
|
60 | - $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
61 | - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
62 | - |
|
63 | - // If the path we move is not a share we don't care |
|
64 | - if (empty($shares)) { |
|
65 | - return; |
|
66 | - } |
|
67 | - |
|
68 | - // Check if the destination is inside a share |
|
69 | - $mountManager = \OC::$server->getMountManager(); |
|
70 | - $dstMount = $mountManager->find($src->getPath()); |
|
71 | - if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - $newOwner = $dstMount->getShare()->getShareOwner(); |
|
76 | - |
|
77 | - //Ownership is moved over |
|
78 | - foreach ($shares as $share) { |
|
79 | - /** @var \OCP\Share\IShare $share */ |
|
80 | - $share->setShareOwner($newOwner); |
|
81 | - $shareManager->updateShare($share); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * rename mount point from the children if the parent was renamed |
|
87 | - * |
|
88 | - * @param string $oldPath old path relative to data/user/files |
|
89 | - * @param string $newPath new path relative to data/user/files |
|
90 | - */ |
|
91 | - static private function renameChildren($oldPath, $newPath) { |
|
92 | - |
|
93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
95 | - |
|
96 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
98 | - foreach ($mountedShares as $mount) { |
|
99 | - if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
100 | - $mountPoint = $mount->getMountPoint(); |
|
101 | - $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
102 | - $mount->moveMount($target); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
30 | + /** |
|
31 | + * @param array $params |
|
32 | + */ |
|
33 | + static public function renameHook($params) { |
|
34 | + self::renameChildren($params['oldpath'], $params['newpath']); |
|
35 | + self::moveShareToShare($params['newpath']); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Fix for https://github.com/owncloud/core/issues/20769 |
|
40 | + * |
|
41 | + * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
42 | + * In this case we need to update the parent of the moved share. Since they are |
|
43 | + * effectively handing over ownership of the file the rest of the code needs to know |
|
44 | + * they need to build up the reshare tree. |
|
45 | + * |
|
46 | + * @param string $path |
|
47 | + */ |
|
48 | + static private function moveShareToShare($path) { |
|
49 | + $userFolder = \OC::$server->getUserFolder(); |
|
50 | + |
|
51 | + // If the user folder can't be constructed (e.g. link share) just return. |
|
52 | + if ($userFolder === null) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + $src = $userFolder->get($path); |
|
57 | + |
|
58 | + $shareManager = \OC::$server->getShareManager(); |
|
59 | + |
|
60 | + $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
61 | + $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
62 | + |
|
63 | + // If the path we move is not a share we don't care |
|
64 | + if (empty($shares)) { |
|
65 | + return; |
|
66 | + } |
|
67 | + |
|
68 | + // Check if the destination is inside a share |
|
69 | + $mountManager = \OC::$server->getMountManager(); |
|
70 | + $dstMount = $mountManager->find($src->getPath()); |
|
71 | + if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + $newOwner = $dstMount->getShare()->getShareOwner(); |
|
76 | + |
|
77 | + //Ownership is moved over |
|
78 | + foreach ($shares as $share) { |
|
79 | + /** @var \OCP\Share\IShare $share */ |
|
80 | + $share->setShareOwner($newOwner); |
|
81 | + $shareManager->updateShare($share); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * rename mount point from the children if the parent was renamed |
|
87 | + * |
|
88 | + * @param string $oldPath old path relative to data/user/files |
|
89 | + * @param string $newPath new path relative to data/user/files |
|
90 | + */ |
|
91 | + static private function renameChildren($oldPath, $newPath) { |
|
92 | + |
|
93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
95 | + |
|
96 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
97 | + $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
98 | + foreach ($mountedShares as $mount) { |
|
99 | + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
100 | + $mountPoint = $mount->getMountPoint(); |
|
101 | + $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
102 | + $mount->moveMount($target); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |
@@ -90,11 +90,11 @@ |
||
90 | 90 | */ |
91 | 91 | static private function renameChildren($oldPath, $newPath) { |
92 | 92 | |
93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$newPath); |
|
94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
95 | 95 | |
96 | 96 | $mountManager = \OC\Files\Filesystem::getMountManager(); |
97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
97 | + $mountedShares = $mountManager->findIn('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
98 | 98 | foreach ($mountedShares as $mount) { |
99 | 99 | if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
100 | 100 | $mountPoint = $mount->getMountPoint(); |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | class DeleteOrphanedSharesJob extends TimedJob { |
33 | 33 | |
34 | - /** |
|
35 | - * Default interval in minutes |
|
36 | - * |
|
37 | - * @var int $defaultIntervalMin |
|
38 | - **/ |
|
39 | - protected $defaultIntervalMin = 15; |
|
34 | + /** |
|
35 | + * Default interval in minutes |
|
36 | + * |
|
37 | + * @var int $defaultIntervalMin |
|
38 | + **/ |
|
39 | + protected $defaultIntervalMin = 15; |
|
40 | 40 | |
41 | - /** |
|
42 | - * sets the correct interval for this timed job |
|
43 | - */ |
|
44 | - public function __construct(){ |
|
45 | - $this->interval = $this->defaultIntervalMin * 60; |
|
46 | - } |
|
41 | + /** |
|
42 | + * sets the correct interval for this timed job |
|
43 | + */ |
|
44 | + public function __construct(){ |
|
45 | + $this->interval = $this->defaultIntervalMin * 60; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Makes the background job do its work |
|
50 | - * |
|
51 | - * @param array $argument unused argument |
|
52 | - */ |
|
53 | - public function run($argument) { |
|
54 | - $connection = \OC::$server->getDatabaseConnection(); |
|
55 | - $logger = \OC::$server->getLogger(); |
|
48 | + /** |
|
49 | + * Makes the background job do its work |
|
50 | + * |
|
51 | + * @param array $argument unused argument |
|
52 | + */ |
|
53 | + public function run($argument) { |
|
54 | + $connection = \OC::$server->getDatabaseConnection(); |
|
55 | + $logger = \OC::$server->getLogger(); |
|
56 | 56 | |
57 | - $sql = |
|
58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
57 | + $sql = |
|
58 | + 'DELETE FROM `*PREFIX*share` ' . |
|
59 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
61 | 61 | |
62 | - $deletedEntries = $connection->executeUpdate($sql); |
|
63 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | - } |
|
62 | + $deletedEntries = $connection->executeUpdate($sql); |
|
63 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * sets the correct interval for this timed job |
43 | 43 | */ |
44 | - public function __construct(){ |
|
44 | + public function __construct() { |
|
45 | 45 | $this->interval = $this->defaultIntervalMin * 60; |
46 | 46 | } |
47 | 47 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $logger = \OC::$server->getLogger(); |
56 | 56 | |
57 | 57 | $sql = |
58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
58 | + 'DELETE FROM `*PREFIX*share` '. |
|
59 | + 'WHERE `item_type` in (\'file\', \'folder\') '. |
|
60 | 60 | 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
61 | 61 | |
62 | 62 | $deletedEntries = $connection->executeUpdate($sql); |
@@ -10,43 +10,43 @@ |
||
10 | 10 | use OCP\Share\IManager; |
11 | 11 | |
12 | 12 | class OCSShareAPIMiddleware extends Middleware { |
13 | - /** @var IManager */ |
|
14 | - private $shareManager; |
|
15 | - /** @var IL10N */ |
|
16 | - private $l; |
|
13 | + /** @var IManager */ |
|
14 | + private $shareManager; |
|
15 | + /** @var IL10N */ |
|
16 | + private $l; |
|
17 | 17 | |
18 | - public function __construct(IManager $shareManager, |
|
19 | - IL10N $l) { |
|
20 | - $this->shareManager = $shareManager; |
|
21 | - $this->l = $l; |
|
22 | - } |
|
18 | + public function __construct(IManager $shareManager, |
|
19 | + IL10N $l) { |
|
20 | + $this->shareManager = $shareManager; |
|
21 | + $this->l = $l; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param \OCP\AppFramework\Controller $controller |
|
26 | - * @param string $methodName |
|
27 | - * |
|
28 | - * @throws OCSNotFoundException |
|
29 | - */ |
|
30 | - public function beforeController($controller, $methodName) { |
|
31 | - if ($controller instanceof ShareAPIController) { |
|
32 | - if (!$this->shareManager->shareApiEnabled()) { |
|
33 | - throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
34 | - } |
|
35 | - } |
|
36 | - } |
|
24 | + /** |
|
25 | + * @param \OCP\AppFramework\Controller $controller |
|
26 | + * @param string $methodName |
|
27 | + * |
|
28 | + * @throws OCSNotFoundException |
|
29 | + */ |
|
30 | + public function beforeController($controller, $methodName) { |
|
31 | + if ($controller instanceof ShareAPIController) { |
|
32 | + if (!$this->shareManager->shareApiEnabled()) { |
|
33 | + throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
34 | + } |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param \OCP\AppFramework\Controller $controller |
|
40 | - * @param string $methodName |
|
41 | - * @param Response $response |
|
42 | - * @return Response |
|
43 | - */ |
|
44 | - public function afterController($controller, $methodName, Response $response) { |
|
45 | - if ($controller instanceof ShareAPIController) { |
|
46 | - /** @var ShareAPIController $controller */ |
|
47 | - $controller->cleanup(); |
|
48 | - } |
|
38 | + /** |
|
39 | + * @param \OCP\AppFramework\Controller $controller |
|
40 | + * @param string $methodName |
|
41 | + * @param Response $response |
|
42 | + * @return Response |
|
43 | + */ |
|
44 | + public function afterController($controller, $methodName, Response $response) { |
|
45 | + if ($controller instanceof ShareAPIController) { |
|
46 | + /** @var ShareAPIController $controller */ |
|
47 | + $controller->cleanup(); |
|
48 | + } |
|
49 | 49 | |
50 | - return $response; |
|
51 | - } |
|
50 | + return $response; |
|
51 | + } |
|
52 | 52 | } |
@@ -45,20 +45,20 @@ discard block |
||
45 | 45 | */ |
46 | 46 | class SharingCheckMiddleware extends Middleware { |
47 | 47 | |
48 | - /** @var string */ |
|
49 | - protected $appName; |
|
50 | - /** @var IConfig */ |
|
51 | - protected $config; |
|
52 | - /** @var IAppManager */ |
|
53 | - protected $appManager; |
|
54 | - /** @var IControllerMethodReflector */ |
|
55 | - protected $reflector; |
|
56 | - /** @var IManager */ |
|
57 | - protected $shareManager; |
|
58 | - /** @var IRequest */ |
|
59 | - protected $request; |
|
60 | - |
|
61 | - /*** |
|
48 | + /** @var string */ |
|
49 | + protected $appName; |
|
50 | + /** @var IConfig */ |
|
51 | + protected $config; |
|
52 | + /** @var IAppManager */ |
|
53 | + protected $appManager; |
|
54 | + /** @var IControllerMethodReflector */ |
|
55 | + protected $reflector; |
|
56 | + /** @var IManager */ |
|
57 | + protected $shareManager; |
|
58 | + /** @var IRequest */ |
|
59 | + protected $request; |
|
60 | + |
|
61 | + /*** |
|
62 | 62 | * @param string $appName |
63 | 63 | * @param IConfig $config |
64 | 64 | * @param IAppManager $appManager |
@@ -66,117 +66,117 @@ discard block |
||
66 | 66 | * @param IManager $shareManager |
67 | 67 | * @param IRequest $request |
68 | 68 | */ |
69 | - public function __construct($appName, |
|
70 | - IConfig $config, |
|
71 | - IAppManager $appManager, |
|
72 | - IControllerMethodReflector $reflector, |
|
73 | - IManager $shareManager, |
|
74 | - IRequest $request |
|
75 | - ) { |
|
76 | - $this->appName = $appName; |
|
77 | - $this->config = $config; |
|
78 | - $this->appManager = $appManager; |
|
79 | - $this->reflector = $reflector; |
|
80 | - $this->shareManager = $shareManager; |
|
81 | - $this->request = $request; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check if sharing is enabled before the controllers is executed |
|
86 | - * |
|
87 | - * @param \OCP\AppFramework\Controller $controller |
|
88 | - * @param string $methodName |
|
89 | - * @throws NotFoundException |
|
90 | - * @throws S2SException |
|
91 | - */ |
|
92 | - public function beforeController($controller, $methodName) { |
|
93 | - if(!$this->isSharingEnabled()) { |
|
94 | - throw new NotFoundException('Sharing is disabled.'); |
|
95 | - } |
|
96 | - |
|
97 | - if ($controller instanceof ExternalSharesController && |
|
98 | - !$this->externalSharesChecks()) { |
|
99 | - throw new S2SException('Federated sharing not allowed'); |
|
100 | - } else if ($controller instanceof ShareController) { |
|
101 | - $token = $this->request->getParam('token'); |
|
102 | - $share = $this->shareManager->getShareByToken($token); |
|
103 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
104 | - && !$this->isLinkSharingEnabled()) { |
|
105 | - throw new NotFoundException('Link sharing is disabled'); |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Return 404 page in case of a not found exception |
|
112 | - * |
|
113 | - * @param \OCP\AppFramework\Controller $controller |
|
114 | - * @param string $methodName |
|
115 | - * @param \Exception $exception |
|
116 | - * @return NotFoundResponse |
|
117 | - * @throws \Exception |
|
118 | - */ |
|
119 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
120 | - if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
121 | - return new NotFoundResponse(); |
|
122 | - } |
|
123 | - |
|
124 | - if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
125 | - return new JSONResponse($exception->getMessage(), 405); |
|
126 | - } |
|
127 | - |
|
128 | - throw $exception; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Checks for externalshares controller |
|
133 | - * @return bool |
|
134 | - */ |
|
135 | - private function externalSharesChecks() { |
|
136 | - |
|
137 | - if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
138 | - $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
143 | - $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
144 | - return false; |
|
145 | - } |
|
146 | - |
|
147 | - return true; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Check whether sharing is enabled |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - private function isSharingEnabled() { |
|
155 | - // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
156 | - // Check whether the sharing application is enabled |
|
157 | - if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
158 | - return false; |
|
159 | - } |
|
160 | - |
|
161 | - return true; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Check if link sharing is allowed |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - private function isLinkSharingEnabled() { |
|
169 | - // Check if the shareAPI is enabled |
|
170 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
171 | - return false; |
|
172 | - } |
|
173 | - |
|
174 | - // Check whether public sharing is enabled |
|
175 | - if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - return true; |
|
180 | - } |
|
69 | + public function __construct($appName, |
|
70 | + IConfig $config, |
|
71 | + IAppManager $appManager, |
|
72 | + IControllerMethodReflector $reflector, |
|
73 | + IManager $shareManager, |
|
74 | + IRequest $request |
|
75 | + ) { |
|
76 | + $this->appName = $appName; |
|
77 | + $this->config = $config; |
|
78 | + $this->appManager = $appManager; |
|
79 | + $this->reflector = $reflector; |
|
80 | + $this->shareManager = $shareManager; |
|
81 | + $this->request = $request; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check if sharing is enabled before the controllers is executed |
|
86 | + * |
|
87 | + * @param \OCP\AppFramework\Controller $controller |
|
88 | + * @param string $methodName |
|
89 | + * @throws NotFoundException |
|
90 | + * @throws S2SException |
|
91 | + */ |
|
92 | + public function beforeController($controller, $methodName) { |
|
93 | + if(!$this->isSharingEnabled()) { |
|
94 | + throw new NotFoundException('Sharing is disabled.'); |
|
95 | + } |
|
96 | + |
|
97 | + if ($controller instanceof ExternalSharesController && |
|
98 | + !$this->externalSharesChecks()) { |
|
99 | + throw new S2SException('Federated sharing not allowed'); |
|
100 | + } else if ($controller instanceof ShareController) { |
|
101 | + $token = $this->request->getParam('token'); |
|
102 | + $share = $this->shareManager->getShareByToken($token); |
|
103 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
104 | + && !$this->isLinkSharingEnabled()) { |
|
105 | + throw new NotFoundException('Link sharing is disabled'); |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Return 404 page in case of a not found exception |
|
112 | + * |
|
113 | + * @param \OCP\AppFramework\Controller $controller |
|
114 | + * @param string $methodName |
|
115 | + * @param \Exception $exception |
|
116 | + * @return NotFoundResponse |
|
117 | + * @throws \Exception |
|
118 | + */ |
|
119 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
120 | + if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
121 | + return new NotFoundResponse(); |
|
122 | + } |
|
123 | + |
|
124 | + if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
125 | + return new JSONResponse($exception->getMessage(), 405); |
|
126 | + } |
|
127 | + |
|
128 | + throw $exception; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Checks for externalshares controller |
|
133 | + * @return bool |
|
134 | + */ |
|
135 | + private function externalSharesChecks() { |
|
136 | + |
|
137 | + if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
138 | + $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
143 | + $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
144 | + return false; |
|
145 | + } |
|
146 | + |
|
147 | + return true; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Check whether sharing is enabled |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + private function isSharingEnabled() { |
|
155 | + // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
156 | + // Check whether the sharing application is enabled |
|
157 | + if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
158 | + return false; |
|
159 | + } |
|
160 | + |
|
161 | + return true; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Check if link sharing is allowed |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + private function isLinkSharingEnabled() { |
|
169 | + // Check if the shareAPI is enabled |
|
170 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
171 | + return false; |
|
172 | + } |
|
173 | + |
|
174 | + // Check whether public sharing is enabled |
|
175 | + if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + return true; |
|
180 | + } |
|
181 | 181 | |
182 | 182 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @throws S2SException |
91 | 91 | */ |
92 | 92 | public function beforeController($controller, $methodName) { |
93 | - if(!$this->isSharingEnabled()) { |
|
93 | + if (!$this->isSharingEnabled()) { |
|
94 | 94 | throw new NotFoundException('Sharing is disabled.'); |
95 | 95 | } |
96 | 96 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @throws \Exception |
118 | 118 | */ |
119 | 119 | public function afterException($controller, $methodName, \Exception $exception) { |
120 | - if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
120 | + if (is_a($exception, '\OCP\Files\NotFoundException')) { |
|
121 | 121 | return new NotFoundResponse(); |
122 | 122 | } |
123 | 123 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | private function isSharingEnabled() { |
155 | 155 | // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
156 | 156 | // Check whether the sharing application is enabled |
157 | - if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
157 | + if (!$this->appManager->isEnabledForUser($this->appName)) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | // Check whether public sharing is enabled |
175 | - if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
175 | + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 |