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