@@ -50,579 +50,579 @@ |
||
| 50 | 50 | use OCP\Share\IShare; |
| 51 | 51 | |
| 52 | 52 | class Manager { |
| 53 | - public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 54 | - |
|
| 55 | - /** @var string|null */ |
|
| 56 | - private $uid; |
|
| 57 | - |
|
| 58 | - /** @var IDBConnection */ |
|
| 59 | - private $connection; |
|
| 60 | - |
|
| 61 | - /** @var \OC\Files\Mount\Manager */ |
|
| 62 | - private $mountManager; |
|
| 63 | - |
|
| 64 | - /** @var IStorageFactory */ |
|
| 65 | - private $storageLoader; |
|
| 66 | - |
|
| 67 | - /** @var IClientService */ |
|
| 68 | - private $clientService; |
|
| 69 | - |
|
| 70 | - /** @var IManager */ |
|
| 71 | - private $notificationManager; |
|
| 72 | - |
|
| 73 | - /** @var IDiscoveryService */ |
|
| 74 | - private $discoveryService; |
|
| 75 | - |
|
| 76 | - /** @var ICloudFederationProviderManager */ |
|
| 77 | - private $cloudFederationProviderManager; |
|
| 78 | - |
|
| 79 | - /** @var ICloudFederationFactory */ |
|
| 80 | - private $cloudFederationFactory; |
|
| 81 | - |
|
| 82 | - /** @var IGroupManager */ |
|
| 83 | - private $groupManager; |
|
| 84 | - |
|
| 85 | - /** @var IUserManager */ |
|
| 86 | - private $userManager; |
|
| 87 | - |
|
| 88 | - /** @var IEventDispatcher */ |
|
| 89 | - private $eventDispatcher; |
|
| 90 | - |
|
| 91 | - public function __construct(IDBConnection $connection, |
|
| 92 | - \OC\Files\Mount\Manager $mountManager, |
|
| 93 | - IStorageFactory $storageLoader, |
|
| 94 | - IClientService $clientService, |
|
| 95 | - IManager $notificationManager, |
|
| 96 | - IDiscoveryService $discoveryService, |
|
| 97 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 98 | - ICloudFederationFactory $cloudFederationFactory, |
|
| 99 | - IGroupManager $groupManager, |
|
| 100 | - IUserManager $userManager, |
|
| 101 | - ?string $uid, |
|
| 102 | - IEventDispatcher $eventDispatcher) { |
|
| 103 | - $this->connection = $connection; |
|
| 104 | - $this->mountManager = $mountManager; |
|
| 105 | - $this->storageLoader = $storageLoader; |
|
| 106 | - $this->clientService = $clientService; |
|
| 107 | - $this->uid = $uid; |
|
| 108 | - $this->notificationManager = $notificationManager; |
|
| 109 | - $this->discoveryService = $discoveryService; |
|
| 110 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 111 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 112 | - $this->groupManager = $groupManager; |
|
| 113 | - $this->userManager = $userManager; |
|
| 114 | - $this->eventDispatcher = $eventDispatcher; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * add new server-to-server share |
|
| 119 | - * |
|
| 120 | - * @param string $remote |
|
| 121 | - * @param string $token |
|
| 122 | - * @param string $password |
|
| 123 | - * @param string $name |
|
| 124 | - * @param string $owner |
|
| 125 | - * @param int $shareType |
|
| 126 | - * @param boolean $accepted |
|
| 127 | - * @param string $user |
|
| 128 | - * @param int $remoteId |
|
| 129 | - * @param int $parent |
|
| 130 | - * @return Mount|null |
|
| 131 | - * @throws \Doctrine\DBAL\DBALException |
|
| 132 | - */ |
|
| 133 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
| 134 | - $user = $user ? $user : $this->uid; |
|
| 135 | - $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; |
|
| 136 | - $name = Filesystem::normalizePath('/' . $name); |
|
| 137 | - |
|
| 138 | - if ($accepted !== IShare::STATUS_ACCEPTED) { |
|
| 139 | - // To avoid conflicts with the mount point generation later, |
|
| 140 | - // we only use a temporary mount point name here. The real |
|
| 141 | - // mount point name will be generated when accepting the share, |
|
| 142 | - // using the original share item name. |
|
| 143 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 144 | - $mountPoint = $tmpMountPointName; |
|
| 145 | - $hash = md5($tmpMountPointName); |
|
| 146 | - $data = [ |
|
| 147 | - 'remote' => $remote, |
|
| 148 | - 'share_token' => $token, |
|
| 149 | - 'password' => $password, |
|
| 150 | - 'name' => $name, |
|
| 151 | - 'owner' => $owner, |
|
| 152 | - 'user' => $user, |
|
| 153 | - 'mountpoint' => $mountPoint, |
|
| 154 | - 'mountpoint_hash' => $hash, |
|
| 155 | - 'accepted' => $accepted, |
|
| 156 | - 'remote_id' => $remoteId, |
|
| 157 | - 'share_type' => $shareType, |
|
| 158 | - ]; |
|
| 159 | - |
|
| 160 | - $i = 1; |
|
| 161 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 162 | - // The external share already exists for the user |
|
| 163 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 164 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 165 | - $i++; |
|
| 166 | - } |
|
| 167 | - return null; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 171 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 172 | - $hash = md5($mountPoint); |
|
| 173 | - |
|
| 174 | - $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); |
|
| 175 | - |
|
| 176 | - $options = [ |
|
| 177 | - 'remote' => $remote, |
|
| 178 | - 'token' => $token, |
|
| 179 | - 'password' => $password, |
|
| 180 | - 'mountpoint' => $mountPoint, |
|
| 181 | - 'owner' => $owner |
|
| 182 | - ]; |
|
| 183 | - return $this->mountShare($options); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * write remote share to the database |
|
| 188 | - * |
|
| 189 | - * @param $remote |
|
| 190 | - * @param $token |
|
| 191 | - * @param $password |
|
| 192 | - * @param $name |
|
| 193 | - * @param $owner |
|
| 194 | - * @param $user |
|
| 195 | - * @param $mountPoint |
|
| 196 | - * @param $hash |
|
| 197 | - * @param $accepted |
|
| 198 | - * @param $remoteId |
|
| 199 | - * @param $parent |
|
| 200 | - * @param $shareType |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) { |
|
| 204 | - $query = $this->connection->prepare(' |
|
| 53 | + public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 54 | + |
|
| 55 | + /** @var string|null */ |
|
| 56 | + private $uid; |
|
| 57 | + |
|
| 58 | + /** @var IDBConnection */ |
|
| 59 | + private $connection; |
|
| 60 | + |
|
| 61 | + /** @var \OC\Files\Mount\Manager */ |
|
| 62 | + private $mountManager; |
|
| 63 | + |
|
| 64 | + /** @var IStorageFactory */ |
|
| 65 | + private $storageLoader; |
|
| 66 | + |
|
| 67 | + /** @var IClientService */ |
|
| 68 | + private $clientService; |
|
| 69 | + |
|
| 70 | + /** @var IManager */ |
|
| 71 | + private $notificationManager; |
|
| 72 | + |
|
| 73 | + /** @var IDiscoveryService */ |
|
| 74 | + private $discoveryService; |
|
| 75 | + |
|
| 76 | + /** @var ICloudFederationProviderManager */ |
|
| 77 | + private $cloudFederationProviderManager; |
|
| 78 | + |
|
| 79 | + /** @var ICloudFederationFactory */ |
|
| 80 | + private $cloudFederationFactory; |
|
| 81 | + |
|
| 82 | + /** @var IGroupManager */ |
|
| 83 | + private $groupManager; |
|
| 84 | + |
|
| 85 | + /** @var IUserManager */ |
|
| 86 | + private $userManager; |
|
| 87 | + |
|
| 88 | + /** @var IEventDispatcher */ |
|
| 89 | + private $eventDispatcher; |
|
| 90 | + |
|
| 91 | + public function __construct(IDBConnection $connection, |
|
| 92 | + \OC\Files\Mount\Manager $mountManager, |
|
| 93 | + IStorageFactory $storageLoader, |
|
| 94 | + IClientService $clientService, |
|
| 95 | + IManager $notificationManager, |
|
| 96 | + IDiscoveryService $discoveryService, |
|
| 97 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 98 | + ICloudFederationFactory $cloudFederationFactory, |
|
| 99 | + IGroupManager $groupManager, |
|
| 100 | + IUserManager $userManager, |
|
| 101 | + ?string $uid, |
|
| 102 | + IEventDispatcher $eventDispatcher) { |
|
| 103 | + $this->connection = $connection; |
|
| 104 | + $this->mountManager = $mountManager; |
|
| 105 | + $this->storageLoader = $storageLoader; |
|
| 106 | + $this->clientService = $clientService; |
|
| 107 | + $this->uid = $uid; |
|
| 108 | + $this->notificationManager = $notificationManager; |
|
| 109 | + $this->discoveryService = $discoveryService; |
|
| 110 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 111 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 112 | + $this->groupManager = $groupManager; |
|
| 113 | + $this->userManager = $userManager; |
|
| 114 | + $this->eventDispatcher = $eventDispatcher; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * add new server-to-server share |
|
| 119 | + * |
|
| 120 | + * @param string $remote |
|
| 121 | + * @param string $token |
|
| 122 | + * @param string $password |
|
| 123 | + * @param string $name |
|
| 124 | + * @param string $owner |
|
| 125 | + * @param int $shareType |
|
| 126 | + * @param boolean $accepted |
|
| 127 | + * @param string $user |
|
| 128 | + * @param int $remoteId |
|
| 129 | + * @param int $parent |
|
| 130 | + * @return Mount|null |
|
| 131 | + * @throws \Doctrine\DBAL\DBALException |
|
| 132 | + */ |
|
| 133 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
| 134 | + $user = $user ? $user : $this->uid; |
|
| 135 | + $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; |
|
| 136 | + $name = Filesystem::normalizePath('/' . $name); |
|
| 137 | + |
|
| 138 | + if ($accepted !== IShare::STATUS_ACCEPTED) { |
|
| 139 | + // To avoid conflicts with the mount point generation later, |
|
| 140 | + // we only use a temporary mount point name here. The real |
|
| 141 | + // mount point name will be generated when accepting the share, |
|
| 142 | + // using the original share item name. |
|
| 143 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 144 | + $mountPoint = $tmpMountPointName; |
|
| 145 | + $hash = md5($tmpMountPointName); |
|
| 146 | + $data = [ |
|
| 147 | + 'remote' => $remote, |
|
| 148 | + 'share_token' => $token, |
|
| 149 | + 'password' => $password, |
|
| 150 | + 'name' => $name, |
|
| 151 | + 'owner' => $owner, |
|
| 152 | + 'user' => $user, |
|
| 153 | + 'mountpoint' => $mountPoint, |
|
| 154 | + 'mountpoint_hash' => $hash, |
|
| 155 | + 'accepted' => $accepted, |
|
| 156 | + 'remote_id' => $remoteId, |
|
| 157 | + 'share_type' => $shareType, |
|
| 158 | + ]; |
|
| 159 | + |
|
| 160 | + $i = 1; |
|
| 161 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 162 | + // The external share already exists for the user |
|
| 163 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 164 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 165 | + $i++; |
|
| 166 | + } |
|
| 167 | + return null; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 171 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 172 | + $hash = md5($mountPoint); |
|
| 173 | + |
|
| 174 | + $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); |
|
| 175 | + |
|
| 176 | + $options = [ |
|
| 177 | + 'remote' => $remote, |
|
| 178 | + 'token' => $token, |
|
| 179 | + 'password' => $password, |
|
| 180 | + 'mountpoint' => $mountPoint, |
|
| 181 | + 'owner' => $owner |
|
| 182 | + ]; |
|
| 183 | + return $this->mountShare($options); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * write remote share to the database |
|
| 188 | + * |
|
| 189 | + * @param $remote |
|
| 190 | + * @param $token |
|
| 191 | + * @param $password |
|
| 192 | + * @param $name |
|
| 193 | + * @param $owner |
|
| 194 | + * @param $user |
|
| 195 | + * @param $mountPoint |
|
| 196 | + * @param $hash |
|
| 197 | + * @param $accepted |
|
| 198 | + * @param $remoteId |
|
| 199 | + * @param $parent |
|
| 200 | + * @param $shareType |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) { |
|
| 204 | + $query = $this->connection->prepare(' |
|
| 205 | 205 | INSERT INTO `*PREFIX*share_external` |
| 206 | 206 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) |
| 207 | 207 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 208 | 208 | '); |
| 209 | - return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * get share |
|
| 214 | - * |
|
| 215 | - * @param int $id share id |
|
| 216 | - * @return mixed share of false |
|
| 217 | - */ |
|
| 218 | - public function getShare($id) { |
|
| 219 | - $getShare = $this->connection->prepare(' |
|
| 209 | + return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * get share |
|
| 214 | + * |
|
| 215 | + * @param int $id share id |
|
| 216 | + * @return mixed share of false |
|
| 217 | + */ |
|
| 218 | + public function getShare($id) { |
|
| 219 | + $getShare = $this->connection->prepare(' |
|
| 220 | 220 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted`, `parent`, `share_type`, `password`, `mountpoint_hash` |
| 221 | 221 | FROM `*PREFIX*share_external` |
| 222 | 222 | WHERE `id` = ?'); |
| 223 | - $result = $getShare->execute([$id]); |
|
| 224 | - |
|
| 225 | - $share = $result ? $getShare->fetch() : []; |
|
| 226 | - |
|
| 227 | - $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); |
|
| 228 | - |
|
| 229 | - // check if the user is allowed to access it |
|
| 230 | - if ($validShare && (int)$share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
| 231 | - return $share; |
|
| 232 | - } elseif ($validShare && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 233 | - $user = $this->userManager->get($this->uid); |
|
| 234 | - if ($this->groupManager->get($share['user'])->inGroup($user)) { |
|
| 235 | - return $share; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * accept server-to-server share |
|
| 244 | - * |
|
| 245 | - * @param int $id |
|
| 246 | - * @return bool True if the share could be accepted, false otherwise |
|
| 247 | - */ |
|
| 248 | - public function acceptShare($id) { |
|
| 249 | - $share = $this->getShare($id); |
|
| 250 | - $result = false; |
|
| 251 | - |
|
| 252 | - if ($share) { |
|
| 253 | - \OC_Util::setupFS($this->uid); |
|
| 254 | - $shareFolder = Helper::getShareFolder(); |
|
| 255 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
| 256 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 257 | - $hash = md5($mountPoint); |
|
| 258 | - $userShareAccepted = false; |
|
| 259 | - |
|
| 260 | - if ((int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 261 | - $acceptShare = $this->connection->prepare(' |
|
| 223 | + $result = $getShare->execute([$id]); |
|
| 224 | + |
|
| 225 | + $share = $result ? $getShare->fetch() : []; |
|
| 226 | + |
|
| 227 | + $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); |
|
| 228 | + |
|
| 229 | + // check if the user is allowed to access it |
|
| 230 | + if ($validShare && (int)$share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
| 231 | + return $share; |
|
| 232 | + } elseif ($validShare && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 233 | + $user = $this->userManager->get($this->uid); |
|
| 234 | + if ($this->groupManager->get($share['user'])->inGroup($user)) { |
|
| 235 | + return $share; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * accept server-to-server share |
|
| 244 | + * |
|
| 245 | + * @param int $id |
|
| 246 | + * @return bool True if the share could be accepted, false otherwise |
|
| 247 | + */ |
|
| 248 | + public function acceptShare($id) { |
|
| 249 | + $share = $this->getShare($id); |
|
| 250 | + $result = false; |
|
| 251 | + |
|
| 252 | + if ($share) { |
|
| 253 | + \OC_Util::setupFS($this->uid); |
|
| 254 | + $shareFolder = Helper::getShareFolder(); |
|
| 255 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
| 256 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 257 | + $hash = md5($mountPoint); |
|
| 258 | + $userShareAccepted = false; |
|
| 259 | + |
|
| 260 | + if ((int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 261 | + $acceptShare = $this->connection->prepare(' |
|
| 262 | 262 | UPDATE `*PREFIX*share_external` |
| 263 | 263 | SET `accepted` = ?, |
| 264 | 264 | `mountpoint` = ?, |
| 265 | 265 | `mountpoint_hash` = ? |
| 266 | 266 | WHERE `id` = ? AND `user` = ?'); |
| 267 | - $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); |
|
| 268 | - } else { |
|
| 269 | - $result = $this->writeShareToDb( |
|
| 270 | - $share['remote'], |
|
| 271 | - $share['share_token'], |
|
| 272 | - $share['password'], |
|
| 273 | - $share['name'], |
|
| 274 | - $share['owner'], |
|
| 275 | - $this->uid, |
|
| 276 | - $mountPoint, $hash, 1, |
|
| 277 | - $share['remote_id'], |
|
| 278 | - $id, |
|
| 279 | - $share['share_type']); |
|
| 280 | - } |
|
| 281 | - if ($userShareAccepted === true) { |
|
| 282 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 283 | - $event = new FederatedShareAddedEvent($share['remote']); |
|
| 284 | - $this->eventDispatcher->dispatchTyped($event); |
|
| 285 | - $result = true; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // Make sure the user has no notification for something that does not exist anymore. |
|
| 290 | - $this->processNotification($id); |
|
| 291 | - |
|
| 292 | - return $result; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * decline server-to-server share |
|
| 297 | - * |
|
| 298 | - * @param int $id |
|
| 299 | - * @return bool True if the share could be declined, false otherwise |
|
| 300 | - */ |
|
| 301 | - public function declineShare($id) { |
|
| 302 | - $share = $this->getShare($id); |
|
| 303 | - $result = false; |
|
| 304 | - |
|
| 305 | - if ($share && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 306 | - $removeShare = $this->connection->prepare(' |
|
| 267 | + $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); |
|
| 268 | + } else { |
|
| 269 | + $result = $this->writeShareToDb( |
|
| 270 | + $share['remote'], |
|
| 271 | + $share['share_token'], |
|
| 272 | + $share['password'], |
|
| 273 | + $share['name'], |
|
| 274 | + $share['owner'], |
|
| 275 | + $this->uid, |
|
| 276 | + $mountPoint, $hash, 1, |
|
| 277 | + $share['remote_id'], |
|
| 278 | + $id, |
|
| 279 | + $share['share_type']); |
|
| 280 | + } |
|
| 281 | + if ($userShareAccepted === true) { |
|
| 282 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 283 | + $event = new FederatedShareAddedEvent($share['remote']); |
|
| 284 | + $this->eventDispatcher->dispatchTyped($event); |
|
| 285 | + $result = true; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // Make sure the user has no notification for something that does not exist anymore. |
|
| 290 | + $this->processNotification($id); |
|
| 291 | + |
|
| 292 | + return $result; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * decline server-to-server share |
|
| 297 | + * |
|
| 298 | + * @param int $id |
|
| 299 | + * @return bool True if the share could be declined, false otherwise |
|
| 300 | + */ |
|
| 301 | + public function declineShare($id) { |
|
| 302 | + $share = $this->getShare($id); |
|
| 303 | + $result = false; |
|
| 304 | + |
|
| 305 | + if ($share && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 306 | + $removeShare = $this->connection->prepare(' |
|
| 307 | 307 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
| 308 | - $removeShare->execute([$id, $this->uid]); |
|
| 309 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 310 | - |
|
| 311 | - $this->processNotification($id); |
|
| 312 | - $result = true; |
|
| 313 | - } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 314 | - $result = $this->writeShareToDb( |
|
| 315 | - $share['remote'], |
|
| 316 | - $share['share_token'], |
|
| 317 | - $share['password'], |
|
| 318 | - $share['name'], |
|
| 319 | - $share['owner'], |
|
| 320 | - $this->uid, |
|
| 321 | - $share['mountpoint'], |
|
| 322 | - $share['mountpoint_hash'], |
|
| 323 | - 0, |
|
| 324 | - $share['remote_id'], |
|
| 325 | - $id, |
|
| 326 | - $share['share_type']); |
|
| 327 | - $this->processNotification($id); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - return $result; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param int $remoteShare |
|
| 335 | - */ |
|
| 336 | - public function processNotification($remoteShare) { |
|
| 337 | - $filter = $this->notificationManager->createNotification(); |
|
| 338 | - $filter->setApp('files_sharing') |
|
| 339 | - ->setUser($this->uid) |
|
| 340 | - ->setObject('remote_share', (int) $remoteShare); |
|
| 341 | - $this->notificationManager->markProcessed($filter); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * inform remote server whether server-to-server share was accepted/declined |
|
| 346 | - * |
|
| 347 | - * @param string $remote |
|
| 348 | - * @param string $token |
|
| 349 | - * @param int $remoteId Share id on the remote host |
|
| 350 | - * @param string $feedback |
|
| 351 | - * @return boolean |
|
| 352 | - */ |
|
| 353 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 354 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
| 355 | - |
|
| 356 | - if ($result === true) { |
|
| 357 | - return true; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
| 361 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 362 | - |
|
| 363 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; |
|
| 364 | - $fields = ['token' => $token]; |
|
| 365 | - |
|
| 366 | - $client = $this->clientService->newClient(); |
|
| 367 | - |
|
| 368 | - try { |
|
| 369 | - $response = $client->post( |
|
| 370 | - $url, |
|
| 371 | - [ |
|
| 372 | - 'body' => $fields, |
|
| 373 | - 'connect_timeout' => 10, |
|
| 374 | - ] |
|
| 375 | - ); |
|
| 376 | - } catch (\Exception $e) { |
|
| 377 | - return false; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $status = json_decode($response->getBody(), true); |
|
| 381 | - |
|
| 382 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * try send accept message to ocm end-point |
|
| 387 | - * |
|
| 388 | - * @param string $remoteDomain |
|
| 389 | - * @param string $token |
|
| 390 | - * @param $remoteId id of the share |
|
| 391 | - * @param string $feedback |
|
| 392 | - * @return bool |
|
| 393 | - */ |
|
| 394 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 395 | - switch ($feedback) { |
|
| 396 | - case 'accept': |
|
| 397 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 398 | - $notification->setMessage( |
|
| 399 | - 'SHARE_ACCEPTED', |
|
| 400 | - 'file', |
|
| 401 | - $remoteId, |
|
| 402 | - [ |
|
| 403 | - 'sharedSecret' => $token, |
|
| 404 | - 'message' => 'Recipient accept the share' |
|
| 405 | - ] |
|
| 406 | - |
|
| 407 | - ); |
|
| 408 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 409 | - case 'decline': |
|
| 410 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 411 | - $notification->setMessage( |
|
| 412 | - 'SHARE_DECLINED', |
|
| 413 | - 'file', |
|
| 414 | - $remoteId, |
|
| 415 | - [ |
|
| 416 | - 'sharedSecret' => $token, |
|
| 417 | - 'message' => 'Recipient declined the share' |
|
| 418 | - ] |
|
| 419 | - |
|
| 420 | - ); |
|
| 421 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * remove '/user/files' from the path and trailing slashes |
|
| 430 | - * |
|
| 431 | - * @param string $path |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - protected function stripPath($path) { |
|
| 435 | - $prefix = '/' . $this->uid . '/files'; |
|
| 436 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - public function getMount($data) { |
|
| 440 | - $data['manager'] = $this; |
|
| 441 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 442 | - $data['mountpoint'] = $mountPoint; |
|
| 443 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 444 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * @param array $data |
|
| 449 | - * @return Mount |
|
| 450 | - */ |
|
| 451 | - protected function mountShare($data) { |
|
| 452 | - $mount = $this->getMount($data); |
|
| 453 | - $this->mountManager->addMount($mount); |
|
| 454 | - return $mount; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * @return \OC\Files\Mount\Manager |
|
| 459 | - */ |
|
| 460 | - public function getMountManager() { |
|
| 461 | - return $this->mountManager; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * @param string $source |
|
| 466 | - * @param string $target |
|
| 467 | - * @return bool |
|
| 468 | - */ |
|
| 469 | - public function setMountPoint($source, $target) { |
|
| 470 | - $source = $this->stripPath($source); |
|
| 471 | - $target = $this->stripPath($target); |
|
| 472 | - $sourceHash = md5($source); |
|
| 473 | - $targetHash = md5($target); |
|
| 474 | - |
|
| 475 | - $query = $this->connection->prepare(' |
|
| 308 | + $removeShare->execute([$id, $this->uid]); |
|
| 309 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 310 | + |
|
| 311 | + $this->processNotification($id); |
|
| 312 | + $result = true; |
|
| 313 | + } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 314 | + $result = $this->writeShareToDb( |
|
| 315 | + $share['remote'], |
|
| 316 | + $share['share_token'], |
|
| 317 | + $share['password'], |
|
| 318 | + $share['name'], |
|
| 319 | + $share['owner'], |
|
| 320 | + $this->uid, |
|
| 321 | + $share['mountpoint'], |
|
| 322 | + $share['mountpoint_hash'], |
|
| 323 | + 0, |
|
| 324 | + $share['remote_id'], |
|
| 325 | + $id, |
|
| 326 | + $share['share_type']); |
|
| 327 | + $this->processNotification($id); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + return $result; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param int $remoteShare |
|
| 335 | + */ |
|
| 336 | + public function processNotification($remoteShare) { |
|
| 337 | + $filter = $this->notificationManager->createNotification(); |
|
| 338 | + $filter->setApp('files_sharing') |
|
| 339 | + ->setUser($this->uid) |
|
| 340 | + ->setObject('remote_share', (int) $remoteShare); |
|
| 341 | + $this->notificationManager->markProcessed($filter); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * inform remote server whether server-to-server share was accepted/declined |
|
| 346 | + * |
|
| 347 | + * @param string $remote |
|
| 348 | + * @param string $token |
|
| 349 | + * @param int $remoteId Share id on the remote host |
|
| 350 | + * @param string $feedback |
|
| 351 | + * @return boolean |
|
| 352 | + */ |
|
| 353 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 354 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
| 355 | + |
|
| 356 | + if ($result === true) { |
|
| 357 | + return true; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
| 361 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 362 | + |
|
| 363 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; |
|
| 364 | + $fields = ['token' => $token]; |
|
| 365 | + |
|
| 366 | + $client = $this->clientService->newClient(); |
|
| 367 | + |
|
| 368 | + try { |
|
| 369 | + $response = $client->post( |
|
| 370 | + $url, |
|
| 371 | + [ |
|
| 372 | + 'body' => $fields, |
|
| 373 | + 'connect_timeout' => 10, |
|
| 374 | + ] |
|
| 375 | + ); |
|
| 376 | + } catch (\Exception $e) { |
|
| 377 | + return false; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $status = json_decode($response->getBody(), true); |
|
| 381 | + |
|
| 382 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * try send accept message to ocm end-point |
|
| 387 | + * |
|
| 388 | + * @param string $remoteDomain |
|
| 389 | + * @param string $token |
|
| 390 | + * @param $remoteId id of the share |
|
| 391 | + * @param string $feedback |
|
| 392 | + * @return bool |
|
| 393 | + */ |
|
| 394 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 395 | + switch ($feedback) { |
|
| 396 | + case 'accept': |
|
| 397 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 398 | + $notification->setMessage( |
|
| 399 | + 'SHARE_ACCEPTED', |
|
| 400 | + 'file', |
|
| 401 | + $remoteId, |
|
| 402 | + [ |
|
| 403 | + 'sharedSecret' => $token, |
|
| 404 | + 'message' => 'Recipient accept the share' |
|
| 405 | + ] |
|
| 406 | + |
|
| 407 | + ); |
|
| 408 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 409 | + case 'decline': |
|
| 410 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 411 | + $notification->setMessage( |
|
| 412 | + 'SHARE_DECLINED', |
|
| 413 | + 'file', |
|
| 414 | + $remoteId, |
|
| 415 | + [ |
|
| 416 | + 'sharedSecret' => $token, |
|
| 417 | + 'message' => 'Recipient declined the share' |
|
| 418 | + ] |
|
| 419 | + |
|
| 420 | + ); |
|
| 421 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * remove '/user/files' from the path and trailing slashes |
|
| 430 | + * |
|
| 431 | + * @param string $path |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + protected function stripPath($path) { |
|
| 435 | + $prefix = '/' . $this->uid . '/files'; |
|
| 436 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + public function getMount($data) { |
|
| 440 | + $data['manager'] = $this; |
|
| 441 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 442 | + $data['mountpoint'] = $mountPoint; |
|
| 443 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 444 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @param array $data |
|
| 449 | + * @return Mount |
|
| 450 | + */ |
|
| 451 | + protected function mountShare($data) { |
|
| 452 | + $mount = $this->getMount($data); |
|
| 453 | + $this->mountManager->addMount($mount); |
|
| 454 | + return $mount; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * @return \OC\Files\Mount\Manager |
|
| 459 | + */ |
|
| 460 | + public function getMountManager() { |
|
| 461 | + return $this->mountManager; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * @param string $source |
|
| 466 | + * @param string $target |
|
| 467 | + * @return bool |
|
| 468 | + */ |
|
| 469 | + public function setMountPoint($source, $target) { |
|
| 470 | + $source = $this->stripPath($source); |
|
| 471 | + $target = $this->stripPath($target); |
|
| 472 | + $sourceHash = md5($source); |
|
| 473 | + $targetHash = md5($target); |
|
| 474 | + |
|
| 475 | + $query = $this->connection->prepare(' |
|
| 476 | 476 | UPDATE `*PREFIX*share_external` |
| 477 | 477 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
| 478 | 478 | WHERE `mountpoint_hash` = ? |
| 479 | 479 | AND `user` = ? |
| 480 | 480 | '); |
| 481 | - $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
| 481 | + $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
| 482 | 482 | |
| 483 | - return $result; |
|
| 484 | - } |
|
| 483 | + return $result; |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - public function removeShare($mountPoint) { |
|
| 487 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 488 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 486 | + public function removeShare($mountPoint) { |
|
| 487 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 488 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 489 | 489 | |
| 490 | - $mountPoint = $this->stripPath($mountPoint); |
|
| 491 | - $hash = md5($mountPoint); |
|
| 490 | + $mountPoint = $this->stripPath($mountPoint); |
|
| 491 | + $hash = md5($mountPoint); |
|
| 492 | 492 | |
| 493 | - $getShare = $this->connection->prepare(' |
|
| 493 | + $getShare = $this->connection->prepare(' |
|
| 494 | 494 | SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id` |
| 495 | 495 | FROM `*PREFIX*share_external` |
| 496 | 496 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
| 497 | - $result = $getShare->execute([$hash, $this->uid]); |
|
| 498 | - |
|
| 499 | - $share = $getShare->fetch(); |
|
| 500 | - $getShare->closeCursor(); |
|
| 501 | - if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 502 | - try { |
|
| 503 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 504 | - } catch (\Throwable $e) { |
|
| 505 | - // if we fail to notify the remote (probably cause the remote is down) |
|
| 506 | - // we still want the share to be gone to prevent undeletable remotes |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - $query = $this->connection->prepare(' |
|
| 497 | + $result = $getShare->execute([$hash, $this->uid]); |
|
| 498 | + |
|
| 499 | + $share = $getShare->fetch(); |
|
| 500 | + $getShare->closeCursor(); |
|
| 501 | + if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 502 | + try { |
|
| 503 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 504 | + } catch (\Throwable $e) { |
|
| 505 | + // if we fail to notify the remote (probably cause the remote is down) |
|
| 506 | + // we still want the share to be gone to prevent undeletable remotes |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + $query = $this->connection->prepare(' |
|
| 510 | 510 | DELETE FROM `*PREFIX*share_external` |
| 511 | 511 | WHERE `id` = ? |
| 512 | 512 | '); |
| 513 | - $result = (bool)$query->execute([(int)$share['id']]); |
|
| 514 | - } elseif ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 515 | - $query = $this->connection->prepare(' |
|
| 513 | + $result = (bool)$query->execute([(int)$share['id']]); |
|
| 514 | + } elseif ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 515 | + $query = $this->connection->prepare(' |
|
| 516 | 516 | UPDATE `*PREFIX*share_external` |
| 517 | 517 | SET `accepted` = ? |
| 518 | 518 | WHERE `id` = ?'); |
| 519 | - $result = (bool)$query->execute([0, (int)$share['id']]); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - if ($result) { |
|
| 523 | - $this->removeReShares($id); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - return $result; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
| 531 | - * |
|
| 532 | - * @param $mountPointId |
|
| 533 | - */ |
|
| 534 | - protected function removeReShares($mountPointId) { |
|
| 535 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
| 536 | - $query = $this->connection->getQueryBuilder(); |
|
| 537 | - $selectQuery->select('id')->from('share') |
|
| 538 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 539 | - $select = $selectQuery->getSQL(); |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - $query->delete('federated_reshares') |
|
| 543 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 544 | - $query->execute(); |
|
| 545 | - |
|
| 546 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 547 | - $deleteReShares->delete('share') |
|
| 548 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 549 | - $deleteReShares->execute(); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * remove all shares for user $uid if the user was deleted |
|
| 554 | - * |
|
| 555 | - * @param string $uid |
|
| 556 | - * @return bool |
|
| 557 | - */ |
|
| 558 | - public function removeUserShares($uid) { |
|
| 559 | - $getShare = $this->connection->prepare(' |
|
| 519 | + $result = (bool)$query->execute([0, (int)$share['id']]); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + if ($result) { |
|
| 523 | + $this->removeReShares($id); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + return $result; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
| 531 | + * |
|
| 532 | + * @param $mountPointId |
|
| 533 | + */ |
|
| 534 | + protected function removeReShares($mountPointId) { |
|
| 535 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
| 536 | + $query = $this->connection->getQueryBuilder(); |
|
| 537 | + $selectQuery->select('id')->from('share') |
|
| 538 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 539 | + $select = $selectQuery->getSQL(); |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + $query->delete('federated_reshares') |
|
| 543 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 544 | + $query->execute(); |
|
| 545 | + |
|
| 546 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 547 | + $deleteReShares->delete('share') |
|
| 548 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 549 | + $deleteReShares->execute(); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * remove all shares for user $uid if the user was deleted |
|
| 554 | + * |
|
| 555 | + * @param string $uid |
|
| 556 | + * @return bool |
|
| 557 | + */ |
|
| 558 | + public function removeUserShares($uid) { |
|
| 559 | + $getShare = $this->connection->prepare(' |
|
| 560 | 560 | SELECT `remote`, `share_token`, `remote_id` |
| 561 | 561 | FROM `*PREFIX*share_external` |
| 562 | 562 | WHERE `user` = ?'); |
| 563 | - $result = $getShare->execute([$uid]); |
|
| 563 | + $result = $getShare->execute([$uid]); |
|
| 564 | 564 | |
| 565 | - if ($result) { |
|
| 566 | - $shares = $getShare->fetchAll(); |
|
| 567 | - foreach ($shares as $share) { |
|
| 568 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 569 | - } |
|
| 570 | - } |
|
| 565 | + if ($result) { |
|
| 566 | + $shares = $getShare->fetchAll(); |
|
| 567 | + foreach ($shares as $share) { |
|
| 568 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - $query = $this->connection->prepare(' |
|
| 572 | + $query = $this->connection->prepare(' |
|
| 573 | 573 | DELETE FROM `*PREFIX*share_external` |
| 574 | 574 | WHERE `user` = ? |
| 575 | 575 | '); |
| 576 | - return (bool)$query->execute([$uid]); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * return a list of shares which are not yet accepted by the user |
|
| 581 | - * |
|
| 582 | - * @return array list of open server-to-server shares |
|
| 583 | - */ |
|
| 584 | - public function getOpenShares() { |
|
| 585 | - return $this->getShares(false); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * return a list of shares which are accepted by the user |
|
| 590 | - * |
|
| 591 | - * @return array list of accepted server-to-server shares |
|
| 592 | - */ |
|
| 593 | - public function getAcceptedShares() { |
|
| 594 | - return $this->getShares(true); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * return a list of shares for the user |
|
| 599 | - * |
|
| 600 | - * @param bool|null $accepted True for accepted only, |
|
| 601 | - * false for not accepted, |
|
| 602 | - * null for all shares of the user |
|
| 603 | - * @return array list of open server-to-server shares |
|
| 604 | - */ |
|
| 605 | - private function getShares($accepted) { |
|
| 606 | - $user = $this->userManager->get($this->uid); |
|
| 607 | - $groups = $this->groupManager->getUserGroups($user); |
|
| 608 | - $userGroups = []; |
|
| 609 | - foreach ($groups as $group) { |
|
| 610 | - $userGroups[] = $group->getGID(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 576 | + return (bool)$query->execute([$uid]); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * return a list of shares which are not yet accepted by the user |
|
| 581 | + * |
|
| 582 | + * @return array list of open server-to-server shares |
|
| 583 | + */ |
|
| 584 | + public function getOpenShares() { |
|
| 585 | + return $this->getShares(false); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * return a list of shares which are accepted by the user |
|
| 590 | + * |
|
| 591 | + * @return array list of accepted server-to-server shares |
|
| 592 | + */ |
|
| 593 | + public function getAcceptedShares() { |
|
| 594 | + return $this->getShares(true); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * return a list of shares for the user |
|
| 599 | + * |
|
| 600 | + * @param bool|null $accepted True for accepted only, |
|
| 601 | + * false for not accepted, |
|
| 602 | + * null for all shares of the user |
|
| 603 | + * @return array list of open server-to-server shares |
|
| 604 | + */ |
|
| 605 | + private function getShares($accepted) { |
|
| 606 | + $user = $this->userManager->get($this->uid); |
|
| 607 | + $groups = $this->groupManager->getUserGroups($user); |
|
| 608 | + $userGroups = []; |
|
| 609 | + foreach ($groups as $group) { |
|
| 610 | + $userGroups[] = $group->getGID(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 614 | 614 | FROM `*PREFIX*share_external` |
| 615 | 615 | WHERE (`user` = ? OR `user` IN (?))'; |
| 616 | - $parameters = [$this->uid, implode(',',$userGroups)]; |
|
| 617 | - if (!is_null($accepted)) { |
|
| 618 | - $query .= ' AND `accepted` = ?'; |
|
| 619 | - $parameters[] = (int) $accepted; |
|
| 620 | - } |
|
| 621 | - $query .= ' ORDER BY `id` ASC'; |
|
| 622 | - |
|
| 623 | - $shares = $this->connection->prepare($query); |
|
| 624 | - $result = $shares->execute($parameters); |
|
| 625 | - |
|
| 626 | - return $result ? $shares->fetchAll() : []; |
|
| 627 | - } |
|
| 616 | + $parameters = [$this->uid, implode(',',$userGroups)]; |
|
| 617 | + if (!is_null($accepted)) { |
|
| 618 | + $query .= ' AND `accepted` = ?'; |
|
| 619 | + $parameters[] = (int) $accepted; |
|
| 620 | + } |
|
| 621 | + $query .= ' ORDER BY `id` ASC'; |
|
| 622 | + |
|
| 623 | + $shares = $this->connection->prepare($query); |
|
| 624 | + $result = $shares->execute($parameters); |
|
| 625 | + |
|
| 626 | + return $result ? $shares->fetchAll() : []; |
|
| 627 | + } |
|
| 628 | 628 | } |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | * @return Mount|null |
| 131 | 131 | * @throws \Doctrine\DBAL\DBALException |
| 132 | 132 | */ |
| 133 | - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { |
|
| 133 | + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted = false, $user = null, $remoteId = -1, $parent = -1) { |
|
| 134 | 134 | $user = $user ? $user : $this->uid; |
| 135 | 135 | $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; |
| 136 | - $name = Filesystem::normalizePath('/' . $name); |
|
| 136 | + $name = Filesystem::normalizePath('/'.$name); |
|
| 137 | 137 | |
| 138 | 138 | if ($accepted !== IShare::STATUS_ACCEPTED) { |
| 139 | 139 | // To avoid conflicts with the mount point generation later, |
| 140 | 140 | // we only use a temporary mount point name here. The real |
| 141 | 141 | // mount point name will be generated when accepting the share, |
| 142 | 142 | // using the original share item name. |
| 143 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 143 | + $tmpMountPointName = '{{TemporaryMountPointName#'.$name.'}}'; |
|
| 144 | 144 | $mountPoint = $tmpMountPointName; |
| 145 | 145 | $hash = md5($tmpMountPointName); |
| 146 | 146 | $data = [ |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $i = 1; |
| 161 | 161 | while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
| 162 | 162 | // The external share already exists for the user |
| 163 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 163 | + $data['mountpoint'] = $tmpMountPointName.'-'.$i; |
|
| 164 | 164 | $data['mountpoint_hash'] = md5($data['mountpoint']); |
| 165 | 165 | $i++; |
| 166 | 166 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $mountPoint = Files::buildNotExistingFileName('/', $name); |
| 171 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 171 | + $mountPoint = Filesystem::normalizePath('/'.$mountPoint); |
|
| 172 | 172 | $hash = md5($mountPoint); |
| 173 | 173 | |
| 174 | 174 | $this->writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType); |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); |
| 228 | 228 | |
| 229 | 229 | // check if the user is allowed to access it |
| 230 | - if ($validShare && (int)$share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
| 230 | + if ($validShare && (int) $share['share_type'] === IShare::TYPE_USER && $share['user'] === $this->uid) { |
|
| 231 | 231 | return $share; |
| 232 | - } elseif ($validShare && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 232 | + } elseif ($validShare && (int) $share['share_type'] === IShare::TYPE_GROUP) { |
|
| 233 | 233 | $user = $this->userManager->get($this->uid); |
| 234 | 234 | if ($this->groupManager->get($share['user'])->inGroup($user)) { |
| 235 | 235 | return $share; |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | $hash = md5($mountPoint); |
| 258 | 258 | $userShareAccepted = false; |
| 259 | 259 | |
| 260 | - if ((int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 260 | + if ((int) $share['share_type'] === IShare::TYPE_USER) { |
|
| 261 | 261 | $acceptShare = $this->connection->prepare(' |
| 262 | 262 | UPDATE `*PREFIX*share_external` |
| 263 | 263 | SET `accepted` = ?, |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | $share = $this->getShare($id); |
| 303 | 303 | $result = false; |
| 304 | 304 | |
| 305 | - if ($share && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 305 | + if ($share && (int) $share['share_type'] === IShare::TYPE_USER) { |
|
| 306 | 306 | $removeShare = $this->connection->prepare(' |
| 307 | 307 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
| 308 | 308 | $removeShare->execute([$id, $this->uid]); |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | $this->processNotification($id); |
| 312 | 312 | $result = true; |
| 313 | - } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 313 | + } elseif ($share && (int) $share['share_type'] === IShare::TYPE_GROUP) { |
|
| 314 | 314 | $result = $this->writeShareToDb( |
| 315 | 315 | $share['remote'], |
| 316 | 316 | $share['share_token'], |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
| 361 | 361 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
| 362 | 362 | |
| 363 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT; |
|
| 363 | + $url = rtrim($remote, '/').$endpoint.'/'.$remoteId.'/'.$feedback.'?format='.Share::RESPONSE_FORMAT; |
|
| 364 | 364 | $fields = ['token' => $token]; |
| 365 | 365 | |
| 366 | 366 | $client = $this->clientService->newClient(); |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | * @return string |
| 433 | 433 | */ |
| 434 | 434 | protected function stripPath($path) { |
| 435 | - $prefix = '/' . $this->uid . '/files'; |
|
| 435 | + $prefix = '/'.$this->uid.'/files'; |
|
| 436 | 436 | return rtrim(substr($path, strlen($prefix)), '/'); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | public function getMount($data) { |
| 440 | 440 | $data['manager'] = $this; |
| 441 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 441 | + $mountPoint = '/'.$this->uid.'/files'.$data['mountpoint']; |
|
| 442 | 442 | $data['mountpoint'] = $mountPoint; |
| 443 | 443 | $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
| 444 | 444 | return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | WHERE `mountpoint_hash` = ? |
| 479 | 479 | AND `user` = ? |
| 480 | 480 | '); |
| 481 | - $result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
| 481 | + $result = (bool) $query->execute([$target, $targetHash, $sourceHash, $this->uid]); |
|
| 482 | 482 | |
| 483 | 483 | return $result; |
| 484 | 484 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | $share = $getShare->fetch(); |
| 500 | 500 | $getShare->closeCursor(); |
| 501 | - if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { |
|
| 501 | + if ($result && $share !== false && (int) $share['share_type'] === IShare::TYPE_USER) { |
|
| 502 | 502 | try { |
| 503 | 503 | $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
| 504 | 504 | } catch (\Throwable $e) { |
@@ -510,13 +510,13 @@ discard block |
||
| 510 | 510 | DELETE FROM `*PREFIX*share_external` |
| 511 | 511 | WHERE `id` = ? |
| 512 | 512 | '); |
| 513 | - $result = (bool)$query->execute([(int)$share['id']]); |
|
| 514 | - } elseif ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_GROUP) { |
|
| 513 | + $result = (bool) $query->execute([(int) $share['id']]); |
|
| 514 | + } elseif ($result && $share !== false && (int) $share['share_type'] === IShare::TYPE_GROUP) { |
|
| 515 | 515 | $query = $this->connection->prepare(' |
| 516 | 516 | UPDATE `*PREFIX*share_external` |
| 517 | 517 | SET `accepted` = ? |
| 518 | 518 | WHERE `id` = ?'); |
| 519 | - $result = (bool)$query->execute([0, (int)$share['id']]); |
|
| 519 | + $result = (bool) $query->execute([0, (int) $share['id']]); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | if ($result) { |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | |
| 542 | 542 | $query->delete('federated_reshares') |
| 543 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 543 | + ->where($query->expr()->in('share_id', $query->createFunction('('.$select.')'))); |
|
| 544 | 544 | $query->execute(); |
| 545 | 545 | |
| 546 | 546 | $deleteReShares = $this->connection->getQueryBuilder(); |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | DELETE FROM `*PREFIX*share_external` |
| 574 | 574 | WHERE `user` = ? |
| 575 | 575 | '); |
| 576 | - return (bool)$query->execute([$uid]); |
|
| 576 | + return (bool) $query->execute([$uid]); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
| 614 | 614 | FROM `*PREFIX*share_external` |
| 615 | 615 | WHERE (`user` = ? OR `user` IN (?))'; |
| 616 | - $parameters = [$this->uid, implode(',',$userGroups)]; |
|
| 616 | + $parameters = [$this->uid, implode(',', $userGroups)]; |
|
| 617 | 617 | if (!is_null($accepted)) { |
| 618 | 618 | $query .= ' AND `accepted` = ?'; |
| 619 | 619 | $parameters[] = (int) $accepted; |