Completed
Push — master ( c65848...a5c801 )
by Blizzz
112:32 queued 99:32
created
apps/files_sharing/lib/ExpireSharesJob.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -29,49 +29,49 @@
 block discarded – undo
29 29
  */
30 30
 class ExpireSharesJob extends TimedJob {
31 31
 
32
-	/**
33
-	 * sets the correct interval for this timed job
34
-	 */
35
-	public function __construct() {
36
-		// Run once a day
37
-		$this->setInterval(24 * 60 * 60);
38
-	}
32
+    /**
33
+     * sets the correct interval for this timed job
34
+     */
35
+    public function __construct() {
36
+        // Run once a day
37
+        $this->setInterval(24 * 60 * 60);
38
+    }
39 39
 
40
-	/**
41
-	 * Makes the background job do its work
42
-	 *
43
-	 * @param array $argument unused argument
44
-	 */
45
-	public function run($argument) {
46
-		$connection = \OC::$server->getDatabaseConnection();
47
-		$logger = \OC::$server->getLogger();
40
+    /**
41
+     * Makes the background job do its work
42
+     *
43
+     * @param array $argument unused argument
44
+     */
45
+    public function run($argument) {
46
+        $connection = \OC::$server->getDatabaseConnection();
47
+        $logger = \OC::$server->getLogger();
48 48
 
49
-		//Current time
50
-		$now = new \DateTime();
51
-		$now = $now->format('Y-m-d H:i:s');
49
+        //Current time
50
+        $now = new \DateTime();
51
+        $now = $now->format('Y-m-d H:i:s');
52 52
 
53
-		/*
53
+        /*
54 54
 		 * Expire file link shares only (for now)
55 55
 		 */
56
-		$qb = $connection->getQueryBuilder();
57
-		$qb->select('id', 'file_source', 'uid_owner', 'item_type')
58
-			->from('share')
59
-			->where(
60
-				$qb->expr()->andX(
61
-					$qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)),
62
-					$qb->expr()->lte('expiration', $qb->expr()->literal($now)),
63
-					$qb->expr()->orX(
64
-						$qb->expr()->eq('item_type', $qb->expr()->literal('file')),
65
-						$qb->expr()->eq('item_type', $qb->expr()->literal('folder'))
66
-					)
67
-				)
68
-			);
56
+        $qb = $connection->getQueryBuilder();
57
+        $qb->select('id', 'file_source', 'uid_owner', 'item_type')
58
+            ->from('share')
59
+            ->where(
60
+                $qb->expr()->andX(
61
+                    $qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)),
62
+                    $qb->expr()->lte('expiration', $qb->expr()->literal($now)),
63
+                    $qb->expr()->orX(
64
+                        $qb->expr()->eq('item_type', $qb->expr()->literal('file')),
65
+                        $qb->expr()->eq('item_type', $qb->expr()->literal('folder'))
66
+                    )
67
+                )
68
+            );
69 69
 
70
-		$shares = $qb->execute();
71
-		while($share = $shares->fetch()) {
72
-			\OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
73
-		}
74
-		$shares->closeCursor();
75
-	}
70
+        $shares = $qb->execute();
71
+        while($share = $shares->fetch()) {
72
+            \OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
73
+        }
74
+        $shares->closeCursor();
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 			);
69 69
 
70 70
 		$shares = $qb->execute();
71
-		while($share = $shares->fetch()) {
71
+		while ($share = $shares->fetch()) {
72 72
 			\OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
73 73
 		}
74 74
 		$shares->closeCursor();
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ExternalSharesController.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -39,112 +39,112 @@
 block discarded – undo
39 39
  */
40 40
 class ExternalSharesController extends Controller {
41 41
 
42
-	/** @var \OCA\Files_Sharing\External\Manager */
43
-	private $externalManager;
44
-	/** @var IClientService */
45
-	private $clientService;
42
+    /** @var \OCA\Files_Sharing\External\Manager */
43
+    private $externalManager;
44
+    /** @var IClientService */
45
+    private $clientService;
46 46
 
47
-	/**
48
-	 * @param string $appName
49
-	 * @param IRequest $request
50
-	 * @param \OCA\Files_Sharing\External\Manager $externalManager
51
-	 * @param IClientService $clientService
52
-	 */
53
-	public function __construct($appName,
54
-								IRequest $request,
55
-								\OCA\Files_Sharing\External\Manager $externalManager,
56
-								IClientService $clientService) {
57
-		parent::__construct($appName, $request);
58
-		$this->externalManager = $externalManager;
59
-		$this->clientService = $clientService;
60
-	}
47
+    /**
48
+     * @param string $appName
49
+     * @param IRequest $request
50
+     * @param \OCA\Files_Sharing\External\Manager $externalManager
51
+     * @param IClientService $clientService
52
+     */
53
+    public function __construct($appName,
54
+                                IRequest $request,
55
+                                \OCA\Files_Sharing\External\Manager $externalManager,
56
+                                IClientService $clientService) {
57
+        parent::__construct($appName, $request);
58
+        $this->externalManager = $externalManager;
59
+        $this->clientService = $clientService;
60
+    }
61 61
 
62
-	/**
63
-	 * @NoAdminRequired
64
-	 * @NoOutgoingFederatedSharingRequired
65
-	 *
66
-	 * @return JSONResponse
67
-	 */
68
-	public function index() {
69
-		return new JSONResponse($this->externalManager->getOpenShares());
70
-	}
62
+    /**
63
+     * @NoAdminRequired
64
+     * @NoOutgoingFederatedSharingRequired
65
+     *
66
+     * @return JSONResponse
67
+     */
68
+    public function index() {
69
+        return new JSONResponse($this->externalManager->getOpenShares());
70
+    }
71 71
 
72
-	/**
73
-	 * @NoAdminRequired
74
-	 * @NoOutgoingFederatedSharingRequired
75
-	 *
76
-	 * @param int $id
77
-	 * @return JSONResponse
78
-	 */
79
-	public function create($id) {
80
-		$this->externalManager->acceptShare($id);
81
-		return new JSONResponse();
82
-	}
72
+    /**
73
+     * @NoAdminRequired
74
+     * @NoOutgoingFederatedSharingRequired
75
+     *
76
+     * @param int $id
77
+     * @return JSONResponse
78
+     */
79
+    public function create($id) {
80
+        $this->externalManager->acceptShare($id);
81
+        return new JSONResponse();
82
+    }
83 83
 
84
-	/**
85
-	 * @NoAdminRequired
86
-	 * @NoOutgoingFederatedSharingRequired
87
-	 *
88
-	 * @param integer $id
89
-	 * @return JSONResponse
90
-	 */
91
-	public function destroy($id) {
92
-		$this->externalManager->declineShare($id);
93
-		return new JSONResponse();
94
-	}
84
+    /**
85
+     * @NoAdminRequired
86
+     * @NoOutgoingFederatedSharingRequired
87
+     *
88
+     * @param integer $id
89
+     * @return JSONResponse
90
+     */
91
+    public function destroy($id) {
92
+        $this->externalManager->declineShare($id);
93
+        return new JSONResponse();
94
+    }
95 95
 
96
-	/**
97
-	 * Test whether the specified remote is accessible
98
-	 *
99
-	 * @param string $remote
100
-	 * @param bool $checkVersion
101
-	 * @return bool
102
-	 */
103
-	protected function testUrl($remote, $checkVersion = false) {
104
-		try {
105
-			$client = $this->clientService->newClient();
106
-			$response = json_decode($client->get(
107
-				$remote,
108
-				[
109
-					'timeout' => 3,
110
-					'connect_timeout' => 3,
111
-				]
112
-			)->getBody());
96
+    /**
97
+     * Test whether the specified remote is accessible
98
+     *
99
+     * @param string $remote
100
+     * @param bool $checkVersion
101
+     * @return bool
102
+     */
103
+    protected function testUrl($remote, $checkVersion = false) {
104
+        try {
105
+            $client = $this->clientService->newClient();
106
+            $response = json_decode($client->get(
107
+                $remote,
108
+                [
109
+                    'timeout' => 3,
110
+                    'connect_timeout' => 3,
111
+                ]
112
+            )->getBody());
113 113
 
114
-			if ($checkVersion) {
115
-				return !empty($response->version) && version_compare($response->version, '7.0.0', '>=');
116
-			} else {
117
-				return is_object($response);
118
-			}
119
-		} catch (\Exception $e) {
120
-			return false;
121
-		}
122
-	}
114
+            if ($checkVersion) {
115
+                return !empty($response->version) && version_compare($response->version, '7.0.0', '>=');
116
+            } else {
117
+                return is_object($response);
118
+            }
119
+        } catch (\Exception $e) {
120
+            return false;
121
+        }
122
+    }
123 123
 
124
-	/**
125
-	 * @PublicPage
126
-	 * @NoOutgoingFederatedSharingRequired
127
-	 * @NoIncomingFederatedSharingRequired
128
-	 *
129
-	 * @param string $remote
130
-	 * @return DataResponse
131
-	 */
132
-	public function testRemote($remote) {
133
-		if (
134
-			$this->testUrl('https://' . $remote . '/ocs-provider/') ||
135
-			$this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
136
-			$this->testUrl('https://' . $remote . '/status.php', true)
137
-		) {
138
-			return new DataResponse('https');
139
-		} elseif (
140
-			$this->testUrl('http://' . $remote . '/ocs-provider/') ||
141
-			$this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
142
-			$this->testUrl('http://' . $remote . '/status.php', true)
143
-		) {
144
-			return new DataResponse('http');
145
-		} else {
146
-			return new DataResponse(false);
147
-		}
148
-	}
124
+    /**
125
+     * @PublicPage
126
+     * @NoOutgoingFederatedSharingRequired
127
+     * @NoIncomingFederatedSharingRequired
128
+     *
129
+     * @param string $remote
130
+     * @return DataResponse
131
+     */
132
+    public function testRemote($remote) {
133
+        if (
134
+            $this->testUrl('https://' . $remote . '/ocs-provider/') ||
135
+            $this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
136
+            $this->testUrl('https://' . $remote . '/status.php', true)
137
+        ) {
138
+            return new DataResponse('https');
139
+        } elseif (
140
+            $this->testUrl('http://' . $remote . '/ocs-provider/') ||
141
+            $this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
142
+            $this->testUrl('http://' . $remote . '/status.php', true)
143
+        ) {
144
+            return new DataResponse('http');
145
+        } else {
146
+            return new DataResponse(false);
147
+        }
148
+    }
149 149
 
150 150
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -131,15 +131,15 @@
 block discarded – undo
131 131
 	 */
132 132
 	public function testRemote($remote) {
133 133
 		if (
134
-			$this->testUrl('https://' . $remote . '/ocs-provider/') ||
135
-			$this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
136
-			$this->testUrl('https://' . $remote . '/status.php', true)
134
+			$this->testUrl('https://'.$remote.'/ocs-provider/') ||
135
+			$this->testUrl('https://'.$remote.'/ocs-provider/index.php') ||
136
+			$this->testUrl('https://'.$remote.'/status.php', true)
137 137
 		) {
138 138
 			return new DataResponse('https');
139 139
 		} elseif (
140
-			$this->testUrl('http://' . $remote . '/ocs-provider/') ||
141
-			$this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
142
-			$this->testUrl('http://' . $remote . '/status.php', true)
140
+			$this->testUrl('http://'.$remote.'/ocs-provider/') ||
141
+			$this->testUrl('http://'.$remote.'/ocs-provider/index.php') ||
142
+			$this->testUrl('http://'.$remote.'/status.php', true)
143 143
 		) {
144 144
 			return new DataResponse('http');
145 145
 		} else {
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareAPIController.php 2 patches
Indentation   +807 added lines, -807 removed lines patch added patch discarded remove patch
@@ -51,820 +51,820 @@
 block discarded – undo
51 51
  */
52 52
 class ShareAPIController extends OCSController {
53 53
 
54
-	/** @var IManager */
55
-	private $shareManager;
56
-	/** @var IGroupManager */
57
-	private $groupManager;
58
-	/** @var IUserManager */
59
-	private $userManager;
60
-	/** @var IRequest */
61
-	protected $request;
62
-	/** @var IRootFolder */
63
-	private $rootFolder;
64
-	/** @var IURLGenerator */
65
-	private $urlGenerator;
66
-	/** @var string */
67
-	private $currentUser;
68
-	/** @var IL10N */
69
-	private $l;
70
-	/** @var \OCP\Files\Node */
71
-	private $lockedNode;
72
-
73
-	/**
74
-	 * Share20OCS constructor.
75
-	 *
76
-	 * @param string $appName
77
-	 * @param IRequest $request
78
-	 * @param IManager $shareManager
79
-	 * @param IGroupManager $groupManager
80
-	 * @param IUserManager $userManager
81
-	 * @param IRootFolder $rootFolder
82
-	 * @param IURLGenerator $urlGenerator
83
-	 * @param string $userId
84
-	 * @param IL10N $l10n
85
-	 */
86
-	public function __construct(
87
-		$appName,
88
-		IRequest $request,
89
-		IManager $shareManager,
90
-		IGroupManager $groupManager,
91
-		IUserManager $userManager,
92
-		IRootFolder $rootFolder,
93
-		IURLGenerator $urlGenerator,
94
-		$userId,
95
-		IL10N $l10n
96
-	) {
97
-		parent::__construct($appName, $request);
98
-
99
-		$this->shareManager = $shareManager;
100
-		$this->userManager = $userManager;
101
-		$this->groupManager = $groupManager;
102
-		$this->request = $request;
103
-		$this->rootFolder = $rootFolder;
104
-		$this->urlGenerator = $urlGenerator;
105
-		$this->currentUser = $userId;
106
-		$this->l = $l10n;
107
-	}
108
-
109
-	/**
110
-	 * Convert an IShare to an array for OCS output
111
-	 *
112
-	 * @param \OCP\Share\IShare $share
113
-	 * @param Node|null $recipientNode
114
-	 * @return array
115
-	 * @throws NotFoundException In case the node can't be resolved.
116
-	 */
117
-	protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) {
118
-		$sharedBy = $this->userManager->get($share->getSharedBy());
119
-		$shareOwner = $this->userManager->get($share->getShareOwner());
120
-
121
-		$result = [
122
-			'id' => $share->getId(),
123
-			'share_type' => $share->getShareType(),
124
-			'uid_owner' => $share->getSharedBy(),
125
-			'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
126
-			'permissions' => $share->getPermissions(),
127
-			'stime' => $share->getShareTime()->getTimestamp(),
128
-			'parent' => null,
129
-			'expiration' => null,
130
-			'token' => null,
131
-			'uid_file_owner' => $share->getShareOwner(),
132
-			'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
133
-		];
134
-
135
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
136
-		if ($recipientNode) {
137
-			$node = $recipientNode;
138
-		} else {
139
-			$nodes = $userFolder->getById($share->getNodeId());
140
-
141
-			if (empty($nodes)) {
142
-				// fallback to guessing the path
143
-				$node = $userFolder->get($share->getTarget());
144
-				if ($node === null) {
145
-					throw new NotFoundException();
146
-				}
147
-			} else {
148
-				$node = $nodes[0];
149
-			}
150
-		}
151
-
152
-		$result['path'] = $userFolder->getRelativePath($node->getPath());
153
-		if ($node instanceOf \OCP\Files\Folder) {
154
-			$result['item_type'] = 'folder';
155
-		} else {
156
-			$result['item_type'] = 'file';
157
-		}
158
-		$result['mimetype'] = $node->getMimetype();
159
-		$result['storage_id'] = $node->getStorage()->getId();
160
-		$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
161
-		$result['item_source'] = $node->getId();
162
-		$result['file_source'] = $node->getId();
163
-		$result['file_parent'] = $node->getParent()->getId();
164
-		$result['file_target'] = $share->getTarget();
165
-
166
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
167
-			$sharedWith = $this->userManager->get($share->getSharedWith());
168
-			$result['share_with'] = $share->getSharedWith();
169
-			$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
170
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
171
-			$group = $this->groupManager->get($share->getSharedWith());
172
-			$result['share_with'] = $share->getSharedWith();
173
-			$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
174
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
175
-
176
-			$result['share_with'] = $share->getPassword();
177
-			$result['share_with_displayname'] = $share->getPassword();
178
-
179
-			$result['token'] = $share->getToken();
180
-			$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
181
-
182
-			$expiration = $share->getExpirationDate();
183
-			if ($expiration !== null) {
184
-				$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
185
-			}
186
-
187
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
188
-			$result['share_with'] = $share->getSharedWith();
189
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
190
-			$result['token'] = $share->getToken();
191
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
192
-			$result['share_with'] = $share->getSharedWith();
193
-			$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
194
-			$result['token'] = $share->getToken();
195
-		}
196
-
197
-		$result['mail_send'] = $share->getMailSend() ? 1 : 0;
198
-
199
-		return $result;
200
-	}
201
-
202
-	/**
203
-	 * Check if one of the users address books knows the exact property, if
204
-	 * yes we return the full name.
205
-	 *
206
-	 * @param string $query
207
-	 * @param string $property
208
-	 * @return string
209
-	 */
210
-	private function getDisplayNameFromAddressBook($query, $property) {
211
-		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
212
-		$result = \OC::$server->getContactsManager()->search($query, [$property]);
213
-		foreach ($result as $r) {
214
-			foreach($r[$property] as $value) {
215
-				if ($value === $query) {
216
-					return $r['FN'];
217
-				}
218
-			}
219
-		}
220
-
221
-		return $query;
222
-	}
223
-
224
-	/**
225
-	 * Get a specific share by id
226
-	 *
227
-	 * @NoAdminRequired
228
-	 *
229
-	 * @param string $id
230
-	 * @return DataResponse
231
-	 * @throws OCSNotFoundException
232
-	 */
233
-	public function getShare($id) {
234
-		try {
235
-			$share = $this->getShareById($id);
236
-		} catch (ShareNotFound $e) {
237
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
238
-		}
239
-
240
-		if ($this->canAccessShare($share)) {
241
-			try {
242
-				$share = $this->formatShare($share);
243
-				return new DataResponse([$share]);
244
-			} catch (NotFoundException $e) {
245
-				//Fall trough
246
-			}
247
-		}
248
-
249
-		throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
250
-	}
251
-
252
-	/**
253
-	 * Delete a share
254
-	 *
255
-	 * @NoAdminRequired
256
-	 *
257
-	 * @param string $id
258
-	 * @return DataResponse
259
-	 * @throws OCSNotFoundException
260
-	 */
261
-	public function deleteShare($id) {
262
-		try {
263
-			$share = $this->getShareById($id);
264
-		} catch (ShareNotFound $e) {
265
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
266
-		}
267
-
268
-		try {
269
-			$this->lock($share->getNode());
270
-		} catch (LockedException $e) {
271
-			throw new OCSNotFoundException($this->l->t('could not delete share'));
272
-		}
273
-
274
-		if (!$this->canAccessShare($share)) {
275
-			throw new OCSNotFoundException($this->l->t('Could not delete share'));
276
-		}
277
-
278
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
279
-			$share->getShareOwner() !== $this->currentUser &&
280
-			$share->getSharedBy() !== $this->currentUser) {
281
-			$this->shareManager->deleteFromSelf($share, $this->currentUser);
282
-		} else {
283
-			$this->shareManager->deleteShare($share);
284
-		}
285
-
286
-		return new DataResponse();
287
-	}
288
-
289
-	/**
290
-	 * @NoAdminRequired
291
-	 *
292
-	 * @param string $path
293
-	 * @param int $permissions
294
-	 * @param int $shareType
295
-	 * @param string $shareWith
296
-	 * @param string $publicUpload
297
-	 * @param string $password
298
-	 * @param string $expireDate
299
-	 *
300
-	 * @return DataResponse
301
-	 * @throws OCSNotFoundException
302
-	 * @throws OCSForbiddenException
303
-	 * @throws OCSBadRequestException
304
-	 * @throws OCSException
305
-	 */
306
-	public function createShare(
307
-		$path = null,
308
-		$permissions = \OCP\Constants::PERMISSION_ALL,
309
-		$shareType = -1,
310
-		$shareWith = null,
311
-		$publicUpload = 'false',
312
-		$password = '',
313
-		$expireDate = ''
314
-	) {
315
-		$share = $this->shareManager->newShare();
316
-
317
-		// Verify path
318
-		if ($path === null) {
319
-			throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
320
-		}
321
-
322
-		$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
323
-		try {
324
-			$path = $userFolder->get($path);
325
-		} catch (NotFoundException $e) {
326
-			throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
327
-		}
328
-
329
-		$share->setNode($path);
330
-
331
-		try {
332
-			$this->lock($share->getNode());
333
-		} catch (LockedException $e) {
334
-			throw new OCSNotFoundException($this->l->t('Could not create share'));
335
-		}
336
-
337
-		if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
338
-			throw new OCSNotFoundException($this->l->t('invalid permissions'));
339
-		}
340
-
341
-		// Shares always require read permissions
342
-		$permissions |= \OCP\Constants::PERMISSION_READ;
343
-
344
-		if ($path instanceof \OCP\Files\File) {
345
-			// Single file shares should never have delete or create permissions
346
-			$permissions &= ~\OCP\Constants::PERMISSION_DELETE;
347
-			$permissions &= ~\OCP\Constants::PERMISSION_CREATE;
348
-		}
349
-
350
-		/*
54
+    /** @var IManager */
55
+    private $shareManager;
56
+    /** @var IGroupManager */
57
+    private $groupManager;
58
+    /** @var IUserManager */
59
+    private $userManager;
60
+    /** @var IRequest */
61
+    protected $request;
62
+    /** @var IRootFolder */
63
+    private $rootFolder;
64
+    /** @var IURLGenerator */
65
+    private $urlGenerator;
66
+    /** @var string */
67
+    private $currentUser;
68
+    /** @var IL10N */
69
+    private $l;
70
+    /** @var \OCP\Files\Node */
71
+    private $lockedNode;
72
+
73
+    /**
74
+     * Share20OCS constructor.
75
+     *
76
+     * @param string $appName
77
+     * @param IRequest $request
78
+     * @param IManager $shareManager
79
+     * @param IGroupManager $groupManager
80
+     * @param IUserManager $userManager
81
+     * @param IRootFolder $rootFolder
82
+     * @param IURLGenerator $urlGenerator
83
+     * @param string $userId
84
+     * @param IL10N $l10n
85
+     */
86
+    public function __construct(
87
+        $appName,
88
+        IRequest $request,
89
+        IManager $shareManager,
90
+        IGroupManager $groupManager,
91
+        IUserManager $userManager,
92
+        IRootFolder $rootFolder,
93
+        IURLGenerator $urlGenerator,
94
+        $userId,
95
+        IL10N $l10n
96
+    ) {
97
+        parent::__construct($appName, $request);
98
+
99
+        $this->shareManager = $shareManager;
100
+        $this->userManager = $userManager;
101
+        $this->groupManager = $groupManager;
102
+        $this->request = $request;
103
+        $this->rootFolder = $rootFolder;
104
+        $this->urlGenerator = $urlGenerator;
105
+        $this->currentUser = $userId;
106
+        $this->l = $l10n;
107
+    }
108
+
109
+    /**
110
+     * Convert an IShare to an array for OCS output
111
+     *
112
+     * @param \OCP\Share\IShare $share
113
+     * @param Node|null $recipientNode
114
+     * @return array
115
+     * @throws NotFoundException In case the node can't be resolved.
116
+     */
117
+    protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) {
118
+        $sharedBy = $this->userManager->get($share->getSharedBy());
119
+        $shareOwner = $this->userManager->get($share->getShareOwner());
120
+
121
+        $result = [
122
+            'id' => $share->getId(),
123
+            'share_type' => $share->getShareType(),
124
+            'uid_owner' => $share->getSharedBy(),
125
+            'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(),
126
+            'permissions' => $share->getPermissions(),
127
+            'stime' => $share->getShareTime()->getTimestamp(),
128
+            'parent' => null,
129
+            'expiration' => null,
130
+            'token' => null,
131
+            'uid_file_owner' => $share->getShareOwner(),
132
+            'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
133
+        ];
134
+
135
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
136
+        if ($recipientNode) {
137
+            $node = $recipientNode;
138
+        } else {
139
+            $nodes = $userFolder->getById($share->getNodeId());
140
+
141
+            if (empty($nodes)) {
142
+                // fallback to guessing the path
143
+                $node = $userFolder->get($share->getTarget());
144
+                if ($node === null) {
145
+                    throw new NotFoundException();
146
+                }
147
+            } else {
148
+                $node = $nodes[0];
149
+            }
150
+        }
151
+
152
+        $result['path'] = $userFolder->getRelativePath($node->getPath());
153
+        if ($node instanceOf \OCP\Files\Folder) {
154
+            $result['item_type'] = 'folder';
155
+        } else {
156
+            $result['item_type'] = 'file';
157
+        }
158
+        $result['mimetype'] = $node->getMimetype();
159
+        $result['storage_id'] = $node->getStorage()->getId();
160
+        $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
161
+        $result['item_source'] = $node->getId();
162
+        $result['file_source'] = $node->getId();
163
+        $result['file_parent'] = $node->getParent()->getId();
164
+        $result['file_target'] = $share->getTarget();
165
+
166
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
167
+            $sharedWith = $this->userManager->get($share->getSharedWith());
168
+            $result['share_with'] = $share->getSharedWith();
169
+            $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
170
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
171
+            $group = $this->groupManager->get($share->getSharedWith());
172
+            $result['share_with'] = $share->getSharedWith();
173
+            $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
174
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
175
+
176
+            $result['share_with'] = $share->getPassword();
177
+            $result['share_with_displayname'] = $share->getPassword();
178
+
179
+            $result['token'] = $share->getToken();
180
+            $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
181
+
182
+            $expiration = $share->getExpirationDate();
183
+            if ($expiration !== null) {
184
+                $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
185
+            }
186
+
187
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
188
+            $result['share_with'] = $share->getSharedWith();
189
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
190
+            $result['token'] = $share->getToken();
191
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
192
+            $result['share_with'] = $share->getSharedWith();
193
+            $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
194
+            $result['token'] = $share->getToken();
195
+        }
196
+
197
+        $result['mail_send'] = $share->getMailSend() ? 1 : 0;
198
+
199
+        return $result;
200
+    }
201
+
202
+    /**
203
+     * Check if one of the users address books knows the exact property, if
204
+     * yes we return the full name.
205
+     *
206
+     * @param string $query
207
+     * @param string $property
208
+     * @return string
209
+     */
210
+    private function getDisplayNameFromAddressBook($query, $property) {
211
+        // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
212
+        $result = \OC::$server->getContactsManager()->search($query, [$property]);
213
+        foreach ($result as $r) {
214
+            foreach($r[$property] as $value) {
215
+                if ($value === $query) {
216
+                    return $r['FN'];
217
+                }
218
+            }
219
+        }
220
+
221
+        return $query;
222
+    }
223
+
224
+    /**
225
+     * Get a specific share by id
226
+     *
227
+     * @NoAdminRequired
228
+     *
229
+     * @param string $id
230
+     * @return DataResponse
231
+     * @throws OCSNotFoundException
232
+     */
233
+    public function getShare($id) {
234
+        try {
235
+            $share = $this->getShareById($id);
236
+        } catch (ShareNotFound $e) {
237
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
238
+        }
239
+
240
+        if ($this->canAccessShare($share)) {
241
+            try {
242
+                $share = $this->formatShare($share);
243
+                return new DataResponse([$share]);
244
+            } catch (NotFoundException $e) {
245
+                //Fall trough
246
+            }
247
+        }
248
+
249
+        throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
250
+    }
251
+
252
+    /**
253
+     * Delete a share
254
+     *
255
+     * @NoAdminRequired
256
+     *
257
+     * @param string $id
258
+     * @return DataResponse
259
+     * @throws OCSNotFoundException
260
+     */
261
+    public function deleteShare($id) {
262
+        try {
263
+            $share = $this->getShareById($id);
264
+        } catch (ShareNotFound $e) {
265
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
266
+        }
267
+
268
+        try {
269
+            $this->lock($share->getNode());
270
+        } catch (LockedException $e) {
271
+            throw new OCSNotFoundException($this->l->t('could not delete share'));
272
+        }
273
+
274
+        if (!$this->canAccessShare($share)) {
275
+            throw new OCSNotFoundException($this->l->t('Could not delete share'));
276
+        }
277
+
278
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP &&
279
+            $share->getShareOwner() !== $this->currentUser &&
280
+            $share->getSharedBy() !== $this->currentUser) {
281
+            $this->shareManager->deleteFromSelf($share, $this->currentUser);
282
+        } else {
283
+            $this->shareManager->deleteShare($share);
284
+        }
285
+
286
+        return new DataResponse();
287
+    }
288
+
289
+    /**
290
+     * @NoAdminRequired
291
+     *
292
+     * @param string $path
293
+     * @param int $permissions
294
+     * @param int $shareType
295
+     * @param string $shareWith
296
+     * @param string $publicUpload
297
+     * @param string $password
298
+     * @param string $expireDate
299
+     *
300
+     * @return DataResponse
301
+     * @throws OCSNotFoundException
302
+     * @throws OCSForbiddenException
303
+     * @throws OCSBadRequestException
304
+     * @throws OCSException
305
+     */
306
+    public function createShare(
307
+        $path = null,
308
+        $permissions = \OCP\Constants::PERMISSION_ALL,
309
+        $shareType = -1,
310
+        $shareWith = null,
311
+        $publicUpload = 'false',
312
+        $password = '',
313
+        $expireDate = ''
314
+    ) {
315
+        $share = $this->shareManager->newShare();
316
+
317
+        // Verify path
318
+        if ($path === null) {
319
+            throw new OCSNotFoundException($this->l->t('Please specify a file or folder path'));
320
+        }
321
+
322
+        $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
323
+        try {
324
+            $path = $userFolder->get($path);
325
+        } catch (NotFoundException $e) {
326
+            throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
327
+        }
328
+
329
+        $share->setNode($path);
330
+
331
+        try {
332
+            $this->lock($share->getNode());
333
+        } catch (LockedException $e) {
334
+            throw new OCSNotFoundException($this->l->t('Could not create share'));
335
+        }
336
+
337
+        if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
338
+            throw new OCSNotFoundException($this->l->t('invalid permissions'));
339
+        }
340
+
341
+        // Shares always require read permissions
342
+        $permissions |= \OCP\Constants::PERMISSION_READ;
343
+
344
+        if ($path instanceof \OCP\Files\File) {
345
+            // Single file shares should never have delete or create permissions
346
+            $permissions &= ~\OCP\Constants::PERMISSION_DELETE;
347
+            $permissions &= ~\OCP\Constants::PERMISSION_CREATE;
348
+        }
349
+
350
+        /*
351 351
 		 * Hack for https://github.com/owncloud/core/issues/22587
352 352
 		 * We check the permissions via webdav. But the permissions of the mount point
353 353
 		 * do not equal the share permissions. Here we fix that for federated mounts.
354 354
 		 */
355
-		if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
356
-			$permissions &= ~($permissions & ~$path->getPermissions());
357
-		}
358
-
359
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
360
-			// Valid user is required to share
361
-			if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
362
-				throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
363
-			}
364
-			$share->setSharedWith($shareWith);
365
-			$share->setPermissions($permissions);
366
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
367
-			if (!$this->shareManager->allowGroupSharing()) {
368
-				throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
369
-			}
370
-
371
-			// Valid group is required to share
372
-			if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
373
-				throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
374
-			}
375
-			$share->setSharedWith($shareWith);
376
-			$share->setPermissions($permissions);
377
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
378
-			//Can we even share links?
379
-			if (!$this->shareManager->shareApiAllowLinks()) {
380
-				throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
381
-			}
382
-
383
-			/*
355
+        if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
356
+            $permissions &= ~($permissions & ~$path->getPermissions());
357
+        }
358
+
359
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
360
+            // Valid user is required to share
361
+            if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
362
+                throw new OCSNotFoundException($this->l->t('Please specify a valid user'));
363
+            }
364
+            $share->setSharedWith($shareWith);
365
+            $share->setPermissions($permissions);
366
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
367
+            if (!$this->shareManager->allowGroupSharing()) {
368
+                throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator'));
369
+            }
370
+
371
+            // Valid group is required to share
372
+            if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
373
+                throw new OCSNotFoundException($this->l->t('Please specify a valid group'));
374
+            }
375
+            $share->setSharedWith($shareWith);
376
+            $share->setPermissions($permissions);
377
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
378
+            //Can we even share links?
379
+            if (!$this->shareManager->shareApiAllowLinks()) {
380
+                throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
381
+            }
382
+
383
+            /*
384 384
 			 * For now we only allow 1 link share.
385 385
 			 * Return the existing link share if this is a duplicate
386 386
 			 */
387
-			$existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0);
388
-			if (!empty($existingShares)) {
389
-				return new DataResponse($this->formatShare($existingShares[0]));
390
-			}
391
-
392
-			if ($publicUpload === 'true') {
393
-				// Check if public upload is allowed
394
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
395
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
396
-				}
397
-
398
-				// Public upload can only be set for folders
399
-				if ($path instanceof \OCP\Files\File) {
400
-					throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
401
-				}
402
-
403
-				$share->setPermissions(
404
-					\OCP\Constants::PERMISSION_READ |
405
-					\OCP\Constants::PERMISSION_CREATE |
406
-					\OCP\Constants::PERMISSION_UPDATE |
407
-					\OCP\Constants::PERMISSION_DELETE
408
-				);
409
-			} else {
410
-				$share->setPermissions(\OCP\Constants::PERMISSION_READ);
411
-			}
412
-
413
-			// Set password
414
-			if ($password !== '') {
415
-				$share->setPassword($password);
416
-			}
417
-
418
-			//Expire date
419
-			if ($expireDate !== '') {
420
-				try {
421
-					$expireDate = $this->parseDate($expireDate);
422
-					$share->setExpirationDate($expireDate);
423
-				} catch (\Exception $e) {
424
-					throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
425
-				}
426
-			}
427
-
428
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
429
-			if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
430
-				throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
431
-			}
432
-
433
-			$share->setSharedWith($shareWith);
434
-			$share->setPermissions($permissions);
435
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
436
-			if ($share->getNodeType() === 'file') {
437
-				$share->setPermissions(\OCP\Constants::PERMISSION_READ);
438
-			} else {
439
-				$share->setPermissions(
440
-					\OCP\Constants::PERMISSION_READ |
441
-					\OCP\Constants::PERMISSION_CREATE |
442
-					\OCP\Constants::PERMISSION_UPDATE |
443
-					\OCP\Constants::PERMISSION_DELETE);
444
-			}
445
-			$share->setSharedWith($shareWith);
446
-		} else {
447
-			throw new OCSBadRequestException($this->l->t('Unknown share type'));
448
-		}
449
-
450
-		$share->setShareType($shareType);
451
-		$share->setSharedBy($this->currentUser);
452
-
453
-		try {
454
-			$share = $this->shareManager->createShare($share);
455
-		} catch (GenericShareException $e) {
456
-			$code = $e->getCode() === 0 ? 403 : $e->getCode();
457
-			throw new OCSException($e->getHint(), $code);
458
-		} catch (\Exception $e) {
459
-			throw new OCSForbiddenException($e->getMessage());
460
-		}
461
-
462
-		$output = $this->formatShare($share);
463
-
464
-		return new DataResponse($output);
465
-	}
466
-
467
-	/**
468
-	 * @param \OCP\Files\File|\OCP\Files\Folder $node
469
-	 * @return DataResponse
470
-	 */
471
-	private function getSharedWithMe($node = null) {
472
-		$userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
473
-		$groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
474
-
475
-		$shares = array_merge($userShares, $groupShares);
476
-
477
-		$shares = array_filter($shares, function (IShare $share) {
478
-			return $share->getShareOwner() !== $this->currentUser;
479
-		});
480
-
481
-		$formatted = [];
482
-		foreach ($shares as $share) {
483
-			if ($this->canAccessShare($share)) {
484
-				try {
485
-					$formatted[] = $this->formatShare($share);
486
-				} catch (NotFoundException $e) {
487
-					// Ignore this share
488
-				}
489
-			}
490
-		}
491
-
492
-		return new DataResponse($formatted);
493
-	}
494
-
495
-	/**
496
-	 * @param \OCP\Files\Folder $folder
497
-	 * @return DataResponse
498
-	 * @throws OCSBadRequestException
499
-	 */
500
-	private function getSharesInDir($folder) {
501
-		if (!($folder instanceof \OCP\Files\Folder)) {
502
-			throw new OCSBadRequestException($this->l->t('Not a directory'));
503
-		}
504
-
505
-		$nodes = $folder->getDirectoryListing();
506
-		/** @var \OCP\Share\IShare[] $shares */
507
-		$shares = [];
508
-		foreach ($nodes as $node) {
509
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0));
510
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
511
-			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0));
512
-			if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
513
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
514
-			}
515
-			if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
516
-				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
517
-			}
518
-		}
519
-
520
-		$formatted = [];
521
-		foreach ($shares as $share) {
522
-			try {
523
-				$formatted[] = $this->formatShare($share);
524
-			} catch (NotFoundException $e) {
525
-				//Ignore this share
526
-			}
527
-		}
528
-
529
-		return new DataResponse($formatted);
530
-	}
531
-
532
-	/**
533
-	 * The getShares function.
534
-	 *
535
-	 * @NoAdminRequired
536
-	 *
537
-	 * @param string $shared_with_me
538
-	 * @param string $reshares
539
-	 * @param string $subfiles
540
-	 * @param string $path
541
-	 *
542
-	 * - Get shares by the current user
543
-	 * - Get shares by the current user and reshares (?reshares=true)
544
-	 * - Get shares with the current user (?shared_with_me=true)
545
-	 * - Get shares for a specific path (?path=...)
546
-	 * - Get all shares in a folder (?subfiles=true&path=..)
547
-	 *
548
-	 * @return DataResponse
549
-	 * @throws OCSNotFoundException
550
-	 */
551
-	public function getShares(
552
-		$shared_with_me = 'false',
553
-		$reshares = 'false',
554
-		$subfiles = 'false',
555
-		$path = null
556
-	) {
557
-
558
-		if ($path !== null) {
559
-			$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
560
-			try {
561
-				$path = $userFolder->get($path);
562
-				$this->lock($path);
563
-			} catch (\OCP\Files\NotFoundException $e) {
564
-				throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
565
-			} catch (LockedException $e) {
566
-				throw new OCSNotFoundException($this->l->t('Could not lock path'));
567
-			}
568
-		}
569
-
570
-		if ($shared_with_me === 'true') {
571
-			$result = $this->getSharedWithMe($path);
572
-			return $result;
573
-		}
574
-
575
-		if ($subfiles === 'true') {
576
-			$result = $this->getSharesInDir($path);
577
-			return $result;
578
-		}
579
-
580
-		if ($reshares === 'true') {
581
-			$reshares = true;
582
-		} else {
583
-			$reshares = false;
584
-		}
585
-
586
-		// Get all shares
587
-		$userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
588
-		$groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
589
-		$linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
590
-		if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
591
-			$mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
592
-		} else {
593
-			$mailShares = [];
594
-		}
595
-		$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares);
596
-
597
-		if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
598
-			$federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
599
-			$shares = array_merge($shares, $federatedShares);
600
-		}
601
-
602
-		$formatted = [];
603
-		foreach ($shares as $share) {
604
-			try {
605
-				$formatted[] = $this->formatShare($share, $path);
606
-			} catch (NotFoundException $e) {
607
-				//Ignore share
608
-			}
609
-		}
610
-
611
-		return new DataResponse($formatted);
612
-	}
613
-
614
-	/**
615
-	 * @NoAdminRequired
616
-	 *
617
-	 * @param int $id
618
-	 * @param int $permissions
619
-	 * @param string $password
620
-	 * @param string $publicUpload
621
-	 * @param string $expireDate
622
-	 * @return DataResponse
623
-	 * @throws OCSNotFoundException
624
-	 * @throws OCSBadRequestException
625
-	 * @throws OCSForbiddenException
626
-	 */
627
-	public function updateShare(
628
-		$id,
629
-		$permissions = null,
630
-		$password = null,
631
-		$publicUpload = null,
632
-		$expireDate = null
633
-	) {
634
-		try {
635
-			$share = $this->getShareById($id);
636
-		} catch (ShareNotFound $e) {
637
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
638
-		}
639
-
640
-		$this->lock($share->getNode());
641
-
642
-		if (!$this->canAccessShare($share, false)) {
643
-			throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
644
-		}
645
-
646
-		/*
387
+            $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0);
388
+            if (!empty($existingShares)) {
389
+                return new DataResponse($this->formatShare($existingShares[0]));
390
+            }
391
+
392
+            if ($publicUpload === 'true') {
393
+                // Check if public upload is allowed
394
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
395
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
396
+                }
397
+
398
+                // Public upload can only be set for folders
399
+                if ($path instanceof \OCP\Files\File) {
400
+                    throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders'));
401
+                }
402
+
403
+                $share->setPermissions(
404
+                    \OCP\Constants::PERMISSION_READ |
405
+                    \OCP\Constants::PERMISSION_CREATE |
406
+                    \OCP\Constants::PERMISSION_UPDATE |
407
+                    \OCP\Constants::PERMISSION_DELETE
408
+                );
409
+            } else {
410
+                $share->setPermissions(\OCP\Constants::PERMISSION_READ);
411
+            }
412
+
413
+            // Set password
414
+            if ($password !== '') {
415
+                $share->setPassword($password);
416
+            }
417
+
418
+            //Expire date
419
+            if ($expireDate !== '') {
420
+                try {
421
+                    $expireDate = $this->parseDate($expireDate);
422
+                    $share->setExpirationDate($expireDate);
423
+                } catch (\Exception $e) {
424
+                    throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
425
+                }
426
+            }
427
+
428
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
429
+            if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
430
+                throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType]));
431
+            }
432
+
433
+            $share->setSharedWith($shareWith);
434
+            $share->setPermissions($permissions);
435
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
436
+            if ($share->getNodeType() === 'file') {
437
+                $share->setPermissions(\OCP\Constants::PERMISSION_READ);
438
+            } else {
439
+                $share->setPermissions(
440
+                    \OCP\Constants::PERMISSION_READ |
441
+                    \OCP\Constants::PERMISSION_CREATE |
442
+                    \OCP\Constants::PERMISSION_UPDATE |
443
+                    \OCP\Constants::PERMISSION_DELETE);
444
+            }
445
+            $share->setSharedWith($shareWith);
446
+        } else {
447
+            throw new OCSBadRequestException($this->l->t('Unknown share type'));
448
+        }
449
+
450
+        $share->setShareType($shareType);
451
+        $share->setSharedBy($this->currentUser);
452
+
453
+        try {
454
+            $share = $this->shareManager->createShare($share);
455
+        } catch (GenericShareException $e) {
456
+            $code = $e->getCode() === 0 ? 403 : $e->getCode();
457
+            throw new OCSException($e->getHint(), $code);
458
+        } catch (\Exception $e) {
459
+            throw new OCSForbiddenException($e->getMessage());
460
+        }
461
+
462
+        $output = $this->formatShare($share);
463
+
464
+        return new DataResponse($output);
465
+    }
466
+
467
+    /**
468
+     * @param \OCP\Files\File|\OCP\Files\Folder $node
469
+     * @return DataResponse
470
+     */
471
+    private function getSharedWithMe($node = null) {
472
+        $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
473
+        $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
474
+
475
+        $shares = array_merge($userShares, $groupShares);
476
+
477
+        $shares = array_filter($shares, function (IShare $share) {
478
+            return $share->getShareOwner() !== $this->currentUser;
479
+        });
480
+
481
+        $formatted = [];
482
+        foreach ($shares as $share) {
483
+            if ($this->canAccessShare($share)) {
484
+                try {
485
+                    $formatted[] = $this->formatShare($share);
486
+                } catch (NotFoundException $e) {
487
+                    // Ignore this share
488
+                }
489
+            }
490
+        }
491
+
492
+        return new DataResponse($formatted);
493
+    }
494
+
495
+    /**
496
+     * @param \OCP\Files\Folder $folder
497
+     * @return DataResponse
498
+     * @throws OCSBadRequestException
499
+     */
500
+    private function getSharesInDir($folder) {
501
+        if (!($folder instanceof \OCP\Files\Folder)) {
502
+            throw new OCSBadRequestException($this->l->t('Not a directory'));
503
+        }
504
+
505
+        $nodes = $folder->getDirectoryListing();
506
+        /** @var \OCP\Share\IShare[] $shares */
507
+        $shares = [];
508
+        foreach ($nodes as $node) {
509
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0));
510
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
511
+            $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0));
512
+            if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
513
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
514
+            }
515
+            if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
516
+                $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
517
+            }
518
+        }
519
+
520
+        $formatted = [];
521
+        foreach ($shares as $share) {
522
+            try {
523
+                $formatted[] = $this->formatShare($share);
524
+            } catch (NotFoundException $e) {
525
+                //Ignore this share
526
+            }
527
+        }
528
+
529
+        return new DataResponse($formatted);
530
+    }
531
+
532
+    /**
533
+     * The getShares function.
534
+     *
535
+     * @NoAdminRequired
536
+     *
537
+     * @param string $shared_with_me
538
+     * @param string $reshares
539
+     * @param string $subfiles
540
+     * @param string $path
541
+     *
542
+     * - Get shares by the current user
543
+     * - Get shares by the current user and reshares (?reshares=true)
544
+     * - Get shares with the current user (?shared_with_me=true)
545
+     * - Get shares for a specific path (?path=...)
546
+     * - Get all shares in a folder (?subfiles=true&path=..)
547
+     *
548
+     * @return DataResponse
549
+     * @throws OCSNotFoundException
550
+     */
551
+    public function getShares(
552
+        $shared_with_me = 'false',
553
+        $reshares = 'false',
554
+        $subfiles = 'false',
555
+        $path = null
556
+    ) {
557
+
558
+        if ($path !== null) {
559
+            $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
560
+            try {
561
+                $path = $userFolder->get($path);
562
+                $this->lock($path);
563
+            } catch (\OCP\Files\NotFoundException $e) {
564
+                throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
565
+            } catch (LockedException $e) {
566
+                throw new OCSNotFoundException($this->l->t('Could not lock path'));
567
+            }
568
+        }
569
+
570
+        if ($shared_with_me === 'true') {
571
+            $result = $this->getSharedWithMe($path);
572
+            return $result;
573
+        }
574
+
575
+        if ($subfiles === 'true') {
576
+            $result = $this->getSharesInDir($path);
577
+            return $result;
578
+        }
579
+
580
+        if ($reshares === 'true') {
581
+            $reshares = true;
582
+        } else {
583
+            $reshares = false;
584
+        }
585
+
586
+        // Get all shares
587
+        $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0);
588
+        $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0);
589
+        $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0);
590
+        if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
591
+            $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0);
592
+        } else {
593
+            $mailShares = [];
594
+        }
595
+        $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares);
596
+
597
+        if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
598
+            $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
599
+            $shares = array_merge($shares, $federatedShares);
600
+        }
601
+
602
+        $formatted = [];
603
+        foreach ($shares as $share) {
604
+            try {
605
+                $formatted[] = $this->formatShare($share, $path);
606
+            } catch (NotFoundException $e) {
607
+                //Ignore share
608
+            }
609
+        }
610
+
611
+        return new DataResponse($formatted);
612
+    }
613
+
614
+    /**
615
+     * @NoAdminRequired
616
+     *
617
+     * @param int $id
618
+     * @param int $permissions
619
+     * @param string $password
620
+     * @param string $publicUpload
621
+     * @param string $expireDate
622
+     * @return DataResponse
623
+     * @throws OCSNotFoundException
624
+     * @throws OCSBadRequestException
625
+     * @throws OCSForbiddenException
626
+     */
627
+    public function updateShare(
628
+        $id,
629
+        $permissions = null,
630
+        $password = null,
631
+        $publicUpload = null,
632
+        $expireDate = null
633
+    ) {
634
+        try {
635
+            $share = $this->getShareById($id);
636
+        } catch (ShareNotFound $e) {
637
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
638
+        }
639
+
640
+        $this->lock($share->getNode());
641
+
642
+        if (!$this->canAccessShare($share, false)) {
643
+            throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
644
+        }
645
+
646
+        /*
647 647
 		 * expirationdate, password and publicUpload only make sense for link shares
648 648
 		 */
649
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
650
-			if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
651
-				throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
652
-			}
653
-
654
-			$newPermissions = null;
655
-			if ($publicUpload === 'true') {
656
-				$newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
657
-			} else if ($publicUpload === 'false') {
658
-				$newPermissions = \OCP\Constants::PERMISSION_READ;
659
-			}
660
-
661
-			if ($permissions !== null) {
662
-				$newPermissions = (int)$permissions;
663
-			}
664
-
665
-			if ($newPermissions !== null &&
666
-				!in_array($newPermissions, [
667
-					\OCP\Constants::PERMISSION_READ,
668
-					\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy
669
-					\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct
670
-					\OCP\Constants::PERMISSION_CREATE, // hidden file list
671
-					\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files
672
-				])
673
-			) {
674
-				throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
675
-			}
676
-
677
-			if (
678
-				// legacy
679
-				$newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) ||
680
-				// correct
681
-				$newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)
682
-			) {
683
-				if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
684
-					throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
685
-				}
686
-
687
-				if (!($share->getNode() instanceof \OCP\Files\Folder)) {
688
-					throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
689
-				}
690
-
691
-				// normalize to correct public upload permissions
692
-				$newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
693
-			}
694
-
695
-			if ($newPermissions !== null) {
696
-				$share->setPermissions($newPermissions);
697
-				$permissions = $newPermissions;
698
-			}
699
-
700
-			if ($expireDate === '') {
701
-				$share->setExpirationDate(null);
702
-			} else if ($expireDate !== null) {
703
-				try {
704
-					$expireDate = $this->parseDate($expireDate);
705
-				} catch (\Exception $e) {
706
-					throw new OCSBadRequestException($e->getMessage());
707
-				}
708
-				$share->setExpirationDate($expireDate);
709
-			}
710
-
711
-			if ($password === '') {
712
-				$share->setPassword(null);
713
-			} else if ($password !== null) {
714
-				$share->setPassword($password);
715
-			}
716
-
717
-		} else {
718
-			// For other shares only permissions is valid.
719
-			if ($permissions === null) {
720
-				throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
721
-			} else {
722
-				$permissions = (int)$permissions;
723
-				$share->setPermissions($permissions);
724
-			}
725
-		}
726
-
727
-		if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
728
-			/* Check if this is an incomming share */
729
-			$incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
730
-			$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
731
-
732
-			/** @var \OCP\Share\IShare[] $incomingShares */
733
-			if (!empty($incomingShares)) {
734
-				$maxPermissions = 0;
735
-				foreach ($incomingShares as $incomingShare) {
736
-					$maxPermissions |= $incomingShare->getPermissions();
737
-				}
738
-
739
-				if ($share->getPermissions() & ~$maxPermissions) {
740
-					throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
741
-				}
742
-			}
743
-		}
744
-
745
-
746
-		try {
747
-			$share = $this->shareManager->updateShare($share);
748
-		} catch (\Exception $e) {
749
-			throw new OCSBadRequestException($e->getMessage());
750
-		}
751
-
752
-		return new DataResponse($this->formatShare($share));
753
-	}
754
-
755
-	/**
756
-	 * @param \OCP\Share\IShare $share
757
-	 * @return bool
758
-	 */
759
-	protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) {
760
-		// A file with permissions 0 can't be accessed by us. So Don't show it
761
-		if ($share->getPermissions() === 0) {
762
-			return false;
763
-		}
764
-
765
-		// Owner of the file and the sharer of the file can always get share
766
-		if ($share->getShareOwner() === $this->currentUser ||
767
-			$share->getSharedBy() === $this->currentUser
768
-		) {
769
-			return true;
770
-		}
771
-
772
-		// If the share is shared with you (or a group you are a member of)
773
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
774
-			$share->getSharedWith() === $this->currentUser
775
-		) {
776
-			return true;
777
-		}
778
-
779
-		if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
780
-			$sharedWith = $this->groupManager->get($share->getSharedWith());
781
-			$user = $this->userManager->get($this->currentUser);
782
-			if ($user !== null && $sharedWith->inGroup($user)) {
783
-				return true;
784
-			}
785
-		}
786
-
787
-		return false;
788
-	}
789
-
790
-	/**
791
-	 * Make sure that the passed date is valid ISO 8601
792
-	 * So YYYY-MM-DD
793
-	 * If not throw an exception
794
-	 *
795
-	 * @param string $expireDate
796
-	 *
797
-	 * @throws \Exception
798
-	 * @return \DateTime
799
-	 */
800
-	private function parseDate($expireDate) {
801
-		try {
802
-			$date = new \DateTime($expireDate);
803
-		} catch (\Exception $e) {
804
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
805
-		}
806
-
807
-		if ($date === false) {
808
-			throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
809
-		}
810
-
811
-		$date->setTime(0, 0, 0);
812
-
813
-		return $date;
814
-	}
815
-
816
-	/**
817
-	 * Since we have multiple providers but the OCS Share API v1 does
818
-	 * not support this we need to check all backends.
819
-	 *
820
-	 * @param string $id
821
-	 * @return \OCP\Share\IShare
822
-	 * @throws ShareNotFound
823
-	 */
824
-	private function getShareById($id) {
825
-		$share = null;
826
-
827
-		// First check if it is an internal share.
828
-		try {
829
-			$share = $this->shareManager->getShareById('ocinternal:' . $id);
830
-			return $share;
831
-		} catch (ShareNotFound $e) {
832
-			// Do nothing, just try the other share type
833
-		}
834
-
835
-		try {
836
-			if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
837
-				$share = $this->shareManager->getShareById('ocMailShare:' . $id);
838
-				return $share;
839
-			}
840
-		} catch (ShareNotFound $e) {
841
-			// Do nothing, just try the other share type
842
-		}
843
-
844
-		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
845
-			throw new ShareNotFound();
846
-		}
847
-		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
848
-
849
-		return $share;
850
-	}
851
-
852
-	/**
853
-	 * Lock a Node
854
-	 *
855
-	 * @param \OCP\Files\Node $node
856
-	 */
857
-	private function lock(\OCP\Files\Node $node) {
858
-		$node->lock(ILockingProvider::LOCK_SHARED);
859
-		$this->lockedNode = $node;
860
-	}
861
-
862
-	/**
863
-	 * Cleanup the remaining locks
864
-	 */
865
-	public function cleanup() {
866
-		if ($this->lockedNode !== null) {
867
-			$this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
868
-		}
869
-	}
649
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
650
+            if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
651
+                throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
652
+            }
653
+
654
+            $newPermissions = null;
655
+            if ($publicUpload === 'true') {
656
+                $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
657
+            } else if ($publicUpload === 'false') {
658
+                $newPermissions = \OCP\Constants::PERMISSION_READ;
659
+            }
660
+
661
+            if ($permissions !== null) {
662
+                $newPermissions = (int)$permissions;
663
+            }
664
+
665
+            if ($newPermissions !== null &&
666
+                !in_array($newPermissions, [
667
+                    \OCP\Constants::PERMISSION_READ,
668
+                    \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy
669
+                    \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct
670
+                    \OCP\Constants::PERMISSION_CREATE, // hidden file list
671
+                    \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files
672
+                ])
673
+            ) {
674
+                throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links'));
675
+            }
676
+
677
+            if (
678
+                // legacy
679
+                $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) ||
680
+                // correct
681
+                $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE)
682
+            ) {
683
+                if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
684
+                    throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator'));
685
+                }
686
+
687
+                if (!($share->getNode() instanceof \OCP\Files\Folder)) {
688
+                    throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders'));
689
+                }
690
+
691
+                // normalize to correct public upload permissions
692
+                $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
693
+            }
694
+
695
+            if ($newPermissions !== null) {
696
+                $share->setPermissions($newPermissions);
697
+                $permissions = $newPermissions;
698
+            }
699
+
700
+            if ($expireDate === '') {
701
+                $share->setExpirationDate(null);
702
+            } else if ($expireDate !== null) {
703
+                try {
704
+                    $expireDate = $this->parseDate($expireDate);
705
+                } catch (\Exception $e) {
706
+                    throw new OCSBadRequestException($e->getMessage());
707
+                }
708
+                $share->setExpirationDate($expireDate);
709
+            }
710
+
711
+            if ($password === '') {
712
+                $share->setPassword(null);
713
+            } else if ($password !== null) {
714
+                $share->setPassword($password);
715
+            }
716
+
717
+        } else {
718
+            // For other shares only permissions is valid.
719
+            if ($permissions === null) {
720
+                throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
721
+            } else {
722
+                $permissions = (int)$permissions;
723
+                $share->setPermissions($permissions);
724
+            }
725
+        }
726
+
727
+        if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
728
+            /* Check if this is an incomming share */
729
+            $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
730
+            $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
731
+
732
+            /** @var \OCP\Share\IShare[] $incomingShares */
733
+            if (!empty($incomingShares)) {
734
+                $maxPermissions = 0;
735
+                foreach ($incomingShares as $incomingShare) {
736
+                    $maxPermissions |= $incomingShare->getPermissions();
737
+                }
738
+
739
+                if ($share->getPermissions() & ~$maxPermissions) {
740
+                    throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
741
+                }
742
+            }
743
+        }
744
+
745
+
746
+        try {
747
+            $share = $this->shareManager->updateShare($share);
748
+        } catch (\Exception $e) {
749
+            throw new OCSBadRequestException($e->getMessage());
750
+        }
751
+
752
+        return new DataResponse($this->formatShare($share));
753
+    }
754
+
755
+    /**
756
+     * @param \OCP\Share\IShare $share
757
+     * @return bool
758
+     */
759
+    protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) {
760
+        // A file with permissions 0 can't be accessed by us. So Don't show it
761
+        if ($share->getPermissions() === 0) {
762
+            return false;
763
+        }
764
+
765
+        // Owner of the file and the sharer of the file can always get share
766
+        if ($share->getShareOwner() === $this->currentUser ||
767
+            $share->getSharedBy() === $this->currentUser
768
+        ) {
769
+            return true;
770
+        }
771
+
772
+        // If the share is shared with you (or a group you are a member of)
773
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
774
+            $share->getSharedWith() === $this->currentUser
775
+        ) {
776
+            return true;
777
+        }
778
+
779
+        if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
780
+            $sharedWith = $this->groupManager->get($share->getSharedWith());
781
+            $user = $this->userManager->get($this->currentUser);
782
+            if ($user !== null && $sharedWith->inGroup($user)) {
783
+                return true;
784
+            }
785
+        }
786
+
787
+        return false;
788
+    }
789
+
790
+    /**
791
+     * Make sure that the passed date is valid ISO 8601
792
+     * So YYYY-MM-DD
793
+     * If not throw an exception
794
+     *
795
+     * @param string $expireDate
796
+     *
797
+     * @throws \Exception
798
+     * @return \DateTime
799
+     */
800
+    private function parseDate($expireDate) {
801
+        try {
802
+            $date = new \DateTime($expireDate);
803
+        } catch (\Exception $e) {
804
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
805
+        }
806
+
807
+        if ($date === false) {
808
+            throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
809
+        }
810
+
811
+        $date->setTime(0, 0, 0);
812
+
813
+        return $date;
814
+    }
815
+
816
+    /**
817
+     * Since we have multiple providers but the OCS Share API v1 does
818
+     * not support this we need to check all backends.
819
+     *
820
+     * @param string $id
821
+     * @return \OCP\Share\IShare
822
+     * @throws ShareNotFound
823
+     */
824
+    private function getShareById($id) {
825
+        $share = null;
826
+
827
+        // First check if it is an internal share.
828
+        try {
829
+            $share = $this->shareManager->getShareById('ocinternal:' . $id);
830
+            return $share;
831
+        } catch (ShareNotFound $e) {
832
+            // Do nothing, just try the other share type
833
+        }
834
+
835
+        try {
836
+            if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
837
+                $share = $this->shareManager->getShareById('ocMailShare:' . $id);
838
+                return $share;
839
+            }
840
+        } catch (ShareNotFound $e) {
841
+            // Do nothing, just try the other share type
842
+        }
843
+
844
+        if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
845
+            throw new ShareNotFound();
846
+        }
847
+        $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
848
+
849
+        return $share;
850
+    }
851
+
852
+    /**
853
+     * Lock a Node
854
+     *
855
+     * @param \OCP\Files\Node $node
856
+     */
857
+    private function lock(\OCP\Files\Node $node) {
858
+        $node->lock(ILockingProvider::LOCK_SHARED);
859
+        $this->lockedNode = $node;
860
+    }
861
+
862
+    /**
863
+     * Cleanup the remaining locks
864
+     */
865
+    public function cleanup() {
866
+        if ($this->lockedNode !== null) {
867
+            $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
868
+        }
869
+    }
870 870
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		// FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered
212 212
 		$result = \OC::$server->getContactsManager()->search($query, [$property]);
213 213
 		foreach ($result as $r) {
214
-			foreach($r[$property] as $value) {
214
+			foreach ($r[$property] as $value) {
215 215
 				if ($value === $query) {
216 216
 					return $r['FN'];
217 217
 				}
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 
475 475
 		$shares = array_merge($userShares, $groupShares);
476 476
 
477
-		$shares = array_filter($shares, function (IShare $share) {
477
+		$shares = array_filter($shares, function(IShare $share) {
478 478
 			return $share->getShareOwner() !== $this->currentUser;
479 479
 		});
480 480
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0));
510 510
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0));
511 511
 			$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0));
512
-			if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
512
+			if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
513 513
 				$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0));
514 514
 			}
515 515
 			if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 			}
660 660
 
661 661
 			if ($permissions !== null) {
662
-				$newPermissions = (int)$permissions;
662
+				$newPermissions = (int) $permissions;
663 663
 			}
664 664
 
665 665
 			if ($newPermissions !== null &&
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 			if ($permissions === null) {
720 720
 				throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
721 721
 			} else {
722
-				$permissions = (int)$permissions;
722
+				$permissions = (int) $permissions;
723 723
 				$share->setPermissions($permissions);
724 724
 			}
725 725
 		}
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 
827 827
 		// First check if it is an internal share.
828 828
 		try {
829
-			$share = $this->shareManager->getShareById('ocinternal:' . $id);
829
+			$share = $this->shareManager->getShareById('ocinternal:'.$id);
830 830
 			return $share;
831 831
 		} catch (ShareNotFound $e) {
832 832
 			// Do nothing, just try the other share type
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 
835 835
 		try {
836 836
 			if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
837
-				$share = $this->shareManager->getShareById('ocMailShare:' . $id);
837
+				$share = $this->shareManager->getShareById('ocMailShare:'.$id);
838 838
 				return $share;
839 839
 			}
840 840
 		} catch (ShareNotFound $e) {
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 		if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
845 845
 			throw new ShareNotFound();
846 846
 		}
847
-		$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
847
+		$share = $this->shareManager->getShareById('ocFederatedSharing:'.$id);
848 848
 
849 849
 		return $share;
850 850
 	}
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/PublicPreviewController.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -36,67 +36,67 @@
 block discarded – undo
36 36
 
37 37
 class PublicPreviewController extends Controller {
38 38
 
39
-	/** @var ShareManager */
40
-	private $shareManager;
39
+    /** @var ShareManager */
40
+    private $shareManager;
41 41
 
42
-	/** @var IPreview */
43
-	private $previewManager;
42
+    /** @var IPreview */
43
+    private $previewManager;
44 44
 
45
-	public function __construct($appName,
46
-								IRequest $request,
47
-								ShareManager $shareManger,
48
-								IPreview $previewManager) {
49
-		parent::__construct($appName, $request);
45
+    public function __construct($appName,
46
+                                IRequest $request,
47
+                                ShareManager $shareManger,
48
+                                IPreview $previewManager) {
49
+        parent::__construct($appName, $request);
50 50
 
51
-		$this->shareManager = $shareManger;
52
-		$this->previewManager = $previewManager;
53
-	}
51
+        $this->shareManager = $shareManger;
52
+        $this->previewManager = $previewManager;
53
+    }
54 54
 
55
-	/**
56
-	 * @PublicPage
57
-	 * @NoCSRFRequired
58
-	 *
59
-	 * @param string $file
60
-	 * @param int $x
61
-	 * @param int $y
62
-	 * @param string $t
63
-	 * @param bool $a
64
-	 * @return DataResponse|FileDisplayResponse
65
-	 */
66
-	public function getPreview(
67
-		$file = '',
68
-		$x = 32,
69
-		$y = 32,
70
-		$t = '',
71
-		$a = false
72
-	) {
55
+    /**
56
+     * @PublicPage
57
+     * @NoCSRFRequired
58
+     *
59
+     * @param string $file
60
+     * @param int $x
61
+     * @param int $y
62
+     * @param string $t
63
+     * @param bool $a
64
+     * @return DataResponse|FileDisplayResponse
65
+     */
66
+    public function getPreview(
67
+        $file = '',
68
+        $x = 32,
69
+        $y = 32,
70
+        $t = '',
71
+        $a = false
72
+    ) {
73 73
 
74
-		if ($t === '' || $x === 0 || $y === 0) {
75
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
76
-		}
74
+        if ($t === '' || $x === 0 || $y === 0) {
75
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
76
+        }
77 77
 
78
-		try {
79
-			$share = $this->shareManager->getShareByToken($t);
80
-		} catch (ShareNotFound $e) {
81
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
82
-		}
78
+        try {
79
+            $share = $this->shareManager->getShareByToken($t);
80
+        } catch (ShareNotFound $e) {
81
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
82
+        }
83 83
 
84
-		if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
85
-			return new DataResponse([], Http::STATUS_FORBIDDEN);
86
-		}
84
+        if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
85
+            return new DataResponse([], Http::STATUS_FORBIDDEN);
86
+        }
87 87
 
88
-		try {
89
-			$node = $share->getNode();
90
-			if ($node instanceof Folder) {
91
-				$file = $node->get($file);
92
-			} else {
93
-				$file = $node;
94
-			}
88
+        try {
89
+            $node = $share->getNode();
90
+            if ($node instanceof Folder) {
91
+                $file = $node->get($file);
92
+            } else {
93
+                $file = $node;
94
+            }
95 95
 
96
-			$f = $this->previewManager->getPreview($file, $x, $y, !$a);
97
-			return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
98
-		} catch (NotFoundException $e) {
99
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
100
-		}
101
-	}
96
+            $f = $this->previewManager->getPreview($file, $x, $y, !$a);
97
+            return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
98
+        } catch (NotFoundException $e) {
99
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
100
+        }
101
+    }
102 102
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/RemoteController.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -33,151 +33,151 @@
 block discarded – undo
33 33
 
34 34
 class RemoteController extends OCSController {
35 35
 
36
-	/** @var Manager */
37
-	private $externalManager;
38
-
39
-	/**
40
-	 * @NoAdminRequired
41
-	 *
42
-	 * Remote constructor.
43
-	 *
44
-	 * @param string $appName
45
-	 * @param IRequest $request
46
-	 * @param Manager $externalManager
47
-	 */
48
-	public function __construct($appName,
49
-								IRequest $request,
50
-								Manager $externalManager) {
51
-		parent::__construct($appName, $request);
52
-
53
-		$this->externalManager = $externalManager;
54
-	}
55
-
56
-	/**
57
-	 * @NoAdminRequired
58
-	 *
59
-	 * Get list of pending remote shares
60
-	 *
61
-	 * @return DataResponse
62
-	 */
63
-	public function getOpenShares() {
64
-		return new DataResponse($this->externalManager->getOpenShares());
65
-	}
66
-
67
-	/**
68
-	 * @NoAdminRequired
69
-	 *
70
-	 * Accept a remote share
71
-	 *
72
-	 * @param int $id
73
-	 * @return DataResponse
74
-	 * @throws OCSNotFoundException
75
-	 */
76
-	public function acceptShare($id) {
77
-		if ($this->externalManager->acceptShare($id)) {
78
-			return new DataResponse();
79
-		}
80
-
81
-		// Make sure the user has no notification for something that does not exist anymore.
82
-		$this->externalManager->processNotification($id);
83
-
84
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
85
-	}
86
-
87
-	/**
88
-	 * @NoAdminRequired
89
-	 *
90
-	 * Decline a remote share
91
-	 *
92
-	 * @param int $id
93
-	 * @return DataResponse
94
-	 * @throws OCSNotFoundException
95
-	 */
96
-	public function declineShare($id) {
97
-		if ($this->externalManager->declineShare($id)) {
98
-			return new DataResponse();
99
-		}
100
-
101
-		// Make sure the user has no notification for something that does not exist anymore.
102
-		$this->externalManager->processNotification($id);
103
-
104
-		throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
105
-	}
106
-
107
-	/**
108
-	 * @param array $share Share with info from the share_external table
109
-	 * @return array enriched share info with data from the filecache
110
-	 */
111
-	private static function extendShareInfo($share) {
112
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
113
-		$info = $view->getFileInfo($share['mountpoint']);
114
-
115
-		$share['mimetype'] = $info->getMimetype();
116
-		$share['mtime'] = $info->getMTime();
117
-		$share['permissions'] = $info->getPermissions();
118
-		$share['type'] = $info->getType();
119
-		$share['file_id'] = $info->getId();
120
-
121
-		return $share;
122
-	}
123
-
124
-	/**
125
-	 * @NoAdminRequired
126
-	 *
127
-	 * List accepted remote shares
128
-	 *
129
-	 * @return DataResponse
130
-	 */
131
-	public function getShares() {
132
-		$shares = $this->externalManager->getAcceptedShares();
133
-		$shares = array_map('self::extendShareInfo', $shares);
134
-
135
-		return new DataResponse($shares);
136
-	}
137
-
138
-	/**
139
-	 * @NoAdminRequired
140
-	 *
141
-	 * Get info of a remote share
142
-	 *
143
-	 * @param int $id
144
-	 * @return DataResponse
145
-	 * @throws OCSNotFoundException
146
-	 */
147
-	public function getShare($id) {
148
-		$shareInfo = $this->externalManager->getShare($id);
149
-
150
-		if ($shareInfo === false) {
151
-			throw new OCSNotFoundException('share does not exist');
152
-		} else {
153
-			$shareInfo = self::extendShareInfo($shareInfo);
154
-			return new DataResponse($shareInfo);
155
-		}
156
-	}
157
-
158
-	/**
159
-	 * @NoAdminRequired
160
-	 *
161
-	 * Unshare a remote share
162
-	 *
163
-	 * @param int $id
164
-	 * @return DataResponse
165
-	 * @throws OCSNotFoundException
166
-	 * @throws OCSForbiddenException
167
-	 */
168
-	public function unshare($id) {
169
-		$shareInfo = $this->externalManager->getShare($id);
170
-
171
-		if ($shareInfo === false) {
172
-			throw new OCSNotFoundException('Share does not exist');
173
-		}
174
-
175
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
176
-
177
-		if ($this->externalManager->removeShare($mountPoint) === true) {
178
-			return new DataResponse();
179
-		} else {
180
-			throw new OCSForbiddenException('Could not unshare');
181
-		}
182
-	}
36
+    /** @var Manager */
37
+    private $externalManager;
38
+
39
+    /**
40
+     * @NoAdminRequired
41
+     *
42
+     * Remote constructor.
43
+     *
44
+     * @param string $appName
45
+     * @param IRequest $request
46
+     * @param Manager $externalManager
47
+     */
48
+    public function __construct($appName,
49
+                                IRequest $request,
50
+                                Manager $externalManager) {
51
+        parent::__construct($appName, $request);
52
+
53
+        $this->externalManager = $externalManager;
54
+    }
55
+
56
+    /**
57
+     * @NoAdminRequired
58
+     *
59
+     * Get list of pending remote shares
60
+     *
61
+     * @return DataResponse
62
+     */
63
+    public function getOpenShares() {
64
+        return new DataResponse($this->externalManager->getOpenShares());
65
+    }
66
+
67
+    /**
68
+     * @NoAdminRequired
69
+     *
70
+     * Accept a remote share
71
+     *
72
+     * @param int $id
73
+     * @return DataResponse
74
+     * @throws OCSNotFoundException
75
+     */
76
+    public function acceptShare($id) {
77
+        if ($this->externalManager->acceptShare($id)) {
78
+            return new DataResponse();
79
+        }
80
+
81
+        // Make sure the user has no notification for something that does not exist anymore.
82
+        $this->externalManager->processNotification($id);
83
+
84
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
85
+    }
86
+
87
+    /**
88
+     * @NoAdminRequired
89
+     *
90
+     * Decline a remote share
91
+     *
92
+     * @param int $id
93
+     * @return DataResponse
94
+     * @throws OCSNotFoundException
95
+     */
96
+    public function declineShare($id) {
97
+        if ($this->externalManager->declineShare($id)) {
98
+            return new DataResponse();
99
+        }
100
+
101
+        // Make sure the user has no notification for something that does not exist anymore.
102
+        $this->externalManager->processNotification($id);
103
+
104
+        throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.');
105
+    }
106
+
107
+    /**
108
+     * @param array $share Share with info from the share_external table
109
+     * @return array enriched share info with data from the filecache
110
+     */
111
+    private static function extendShareInfo($share) {
112
+        $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
113
+        $info = $view->getFileInfo($share['mountpoint']);
114
+
115
+        $share['mimetype'] = $info->getMimetype();
116
+        $share['mtime'] = $info->getMTime();
117
+        $share['permissions'] = $info->getPermissions();
118
+        $share['type'] = $info->getType();
119
+        $share['file_id'] = $info->getId();
120
+
121
+        return $share;
122
+    }
123
+
124
+    /**
125
+     * @NoAdminRequired
126
+     *
127
+     * List accepted remote shares
128
+     *
129
+     * @return DataResponse
130
+     */
131
+    public function getShares() {
132
+        $shares = $this->externalManager->getAcceptedShares();
133
+        $shares = array_map('self::extendShareInfo', $shares);
134
+
135
+        return new DataResponse($shares);
136
+    }
137
+
138
+    /**
139
+     * @NoAdminRequired
140
+     *
141
+     * Get info of a remote share
142
+     *
143
+     * @param int $id
144
+     * @return DataResponse
145
+     * @throws OCSNotFoundException
146
+     */
147
+    public function getShare($id) {
148
+        $shareInfo = $this->externalManager->getShare($id);
149
+
150
+        if ($shareInfo === false) {
151
+            throw new OCSNotFoundException('share does not exist');
152
+        } else {
153
+            $shareInfo = self::extendShareInfo($shareInfo);
154
+            return new DataResponse($shareInfo);
155
+        }
156
+    }
157
+
158
+    /**
159
+     * @NoAdminRequired
160
+     *
161
+     * Unshare a remote share
162
+     *
163
+     * @param int $id
164
+     * @return DataResponse
165
+     * @throws OCSNotFoundException
166
+     * @throws OCSForbiddenException
167
+     */
168
+    public function unshare($id) {
169
+        $shareInfo = $this->externalManager->getShare($id);
170
+
171
+        if ($shareInfo === false) {
172
+            throw new OCSNotFoundException('Share does not exist');
173
+        }
174
+
175
+        $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
176
+
177
+        if ($this->externalManager->removeShare($mountPoint) === true) {
178
+            return new DataResponse();
179
+        } else {
180
+            throw new OCSForbiddenException('Could not unshare');
181
+        }
182
+    }
183 183
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return array enriched share info with data from the filecache
110 110
 	 */
111 111
 	private static function extendShareInfo($share) {
112
-		$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
112
+		$view = new \OC\Files\View('/'.\OC_User::getUser().'/files/');
113 113
 		$info = $view->getFileInfo($share['mountpoint']);
114 114
 
115 115
 		$share['mimetype'] = $info->getMimetype();
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			throw new OCSNotFoundException('Share does not exist');
173 173
 		}
174 174
 
175
-		$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
175
+		$mountPoint = '/'.\OC_User::getUser().'/files'.$shareInfo['mountpoint'];
176 176
 
177 177
 		if ($this->externalManager->removeShare($mountPoint) === true) {
178 178
 			return new DataResponse();
Please login to merge, or discard this patch.
apps/files_sharing/lib/ISharedStorage.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,6 +23,6 @@
 block discarded – undo
23 23
 
24 24
 namespace OCA\Files_Sharing;
25 25
 
26
-interface ISharedStorage{
26
+interface ISharedStorage {
27 27
 
28 28
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Exceptions/BrokenPath.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,6 @@
 block discarded – undo
27 27
  * Expected path with a different root
28 28
  * Possible Error Codes:
29 29
  * 10 - Path not relative to data/ and point to the users file directory
30
-
31 30
  */
32 31
 class BrokenPath extends \Exception {
33 32
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/AppInfo/Application.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -40,131 +40,131 @@
 block discarded – undo
40 40
 use OCP\IServerContainer;
41 41
 
42 42
 class Application extends App {
43
-	public function __construct(array $urlParams = array()) {
44
-		parent::__construct('files_sharing', $urlParams);
43
+    public function __construct(array $urlParams = array()) {
44
+        parent::__construct('files_sharing', $urlParams);
45 45
 
46
-		$container = $this->getContainer();
47
-		/** @var IServerContainer $server */
48
-		$server = $container->getServer();
46
+        $container = $this->getContainer();
47
+        /** @var IServerContainer $server */
48
+        $server = $container->getServer();
49 49
 
50
-		/**
51
-		 * Controllers
52
-		 */
53
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
54
-			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
55
-			return new ShareController(
56
-				$c->query('AppName'),
57
-				$c->query('Request'),
58
-				$server->getConfig(),
59
-				$server->getURLGenerator(),
60
-				$server->getUserManager(),
61
-				$server->getLogger(),
62
-				$server->getActivityManager(),
63
-				$server->getShareManager(),
64
-				$server->getSession(),
65
-				$server->getPreviewManager(),
66
-				$server->getRootFolder(),
67
-				$federatedSharingApp->getFederatedShareProvider(),
68
-				$server->getEventDispatcher(),
69
-				$server->getL10N($c->query('AppName')),
70
-				$server->getThemingDefaults()
71
-			);
72
-		});
73
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
74
-			return new ExternalSharesController(
75
-				$c->query('AppName'),
76
-				$c->query('Request'),
77
-				$c->query('ExternalManager'),
78
-				$c->query('HttpClientService')
79
-			);
80
-		});
50
+        /**
51
+         * Controllers
52
+         */
53
+        $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
54
+            $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
55
+            return new ShareController(
56
+                $c->query('AppName'),
57
+                $c->query('Request'),
58
+                $server->getConfig(),
59
+                $server->getURLGenerator(),
60
+                $server->getUserManager(),
61
+                $server->getLogger(),
62
+                $server->getActivityManager(),
63
+                $server->getShareManager(),
64
+                $server->getSession(),
65
+                $server->getPreviewManager(),
66
+                $server->getRootFolder(),
67
+                $federatedSharingApp->getFederatedShareProvider(),
68
+                $server->getEventDispatcher(),
69
+                $server->getL10N($c->query('AppName')),
70
+                $server->getThemingDefaults()
71
+            );
72
+        });
73
+        $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
74
+            return new ExternalSharesController(
75
+                $c->query('AppName'),
76
+                $c->query('Request'),
77
+                $c->query('ExternalManager'),
78
+                $c->query('HttpClientService')
79
+            );
80
+        });
81 81
 
82
-		/**
83
-		 * Core class wrappers
84
-		 */
85
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
86
-			return $server->getHTTPClientService();
87
-		});
88
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
89
-			return $server->getCloudIdManager();
90
-		});
91
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
92
-			$user = $server->getUserSession()->getUser();
93
-			$uid = $user ? $user->getUID() : null;
94
-			$discoveryManager = new DiscoveryManager(
95
-				\OC::$server->getMemCacheFactory(),
96
-				\OC::$server->getHTTPClientService()
97
-			);
98
-			return new \OCA\Files_Sharing\External\Manager(
99
-				$server->getDatabaseConnection(),
100
-				\OC\Files\Filesystem::getMountManager(),
101
-				\OC\Files\Filesystem::getLoader(),
102
-				$server->getHTTPClientService(),
103
-				$server->getNotificationManager(),
104
-				$discoveryManager,
105
-				$uid
106
-			);
107
-		});
108
-		$container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
82
+        /**
83
+         * Core class wrappers
84
+         */
85
+        $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
86
+            return $server->getHTTPClientService();
87
+        });
88
+        $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
89
+            return $server->getCloudIdManager();
90
+        });
91
+        $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
92
+            $user = $server->getUserSession()->getUser();
93
+            $uid = $user ? $user->getUID() : null;
94
+            $discoveryManager = new DiscoveryManager(
95
+                \OC::$server->getMemCacheFactory(),
96
+                \OC::$server->getHTTPClientService()
97
+            );
98
+            return new \OCA\Files_Sharing\External\Manager(
99
+                $server->getDatabaseConnection(),
100
+                \OC\Files\Filesystem::getMountManager(),
101
+                \OC\Files\Filesystem::getLoader(),
102
+                $server->getHTTPClientService(),
103
+                $server->getNotificationManager(),
104
+                $discoveryManager,
105
+                $uid
106
+            );
107
+        });
108
+        $container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
109 109
 
110
-		/**
111
-		 * Middleware
112
-		 */
113
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
114
-			return new SharingCheckMiddleware(
115
-				$c->query('AppName'),
116
-				$server->getConfig(),
117
-				$server->getAppManager(),
118
-				$c['ControllerMethodReflector'],
119
-				$server->getShareManager(),
120
-				$server->getRequest()
121
-			);
122
-		});
110
+        /**
111
+         * Middleware
112
+         */
113
+        $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
114
+            return new SharingCheckMiddleware(
115
+                $c->query('AppName'),
116
+                $server->getConfig(),
117
+                $server->getAppManager(),
118
+                $c['ControllerMethodReflector'],
119
+                $server->getShareManager(),
120
+                $server->getRequest()
121
+            );
122
+        });
123 123
 
124
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
125
-			return new OCSShareAPIMiddleware(
126
-				$server->getShareManager(),
127
-				$server->getL10N($c->query('AppName'))
128
-			);
129
-		});
124
+        $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
125
+            return new OCSShareAPIMiddleware(
126
+                $server->getShareManager(),
127
+                $server->getL10N($c->query('AppName'))
128
+            );
129
+        });
130 130
 
131
-		// Execute middlewares
132
-		$container->registerMiddleWare('SharingCheckMiddleware');
133
-		$container->registerMiddleWare('OCSShareAPIMiddleware');
131
+        // Execute middlewares
132
+        $container->registerMiddleWare('SharingCheckMiddleware');
133
+        $container->registerMiddleWare('OCSShareAPIMiddleware');
134 134
 
135
-		$container->registerService('MountProvider', function (IContainer $c) {
136
-			/** @var \OCP\IServerContainer $server */
137
-			$server = $c->query('ServerContainer');
138
-			return new MountProvider(
139
-				$server->getConfig(),
140
-				$server->getShareManager(),
141
-				$server->getLogger()
142
-			);
143
-		});
135
+        $container->registerService('MountProvider', function (IContainer $c) {
136
+            /** @var \OCP\IServerContainer $server */
137
+            $server = $c->query('ServerContainer');
138
+            return new MountProvider(
139
+                $server->getConfig(),
140
+                $server->getShareManager(),
141
+                $server->getLogger()
142
+            );
143
+        });
144 144
 
145
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
146
-			/** @var \OCP\IServerContainer $server */
147
-			$server = $c->query('ServerContainer');
148
-			return new \OCA\Files_Sharing\External\MountProvider(
149
-				$server->getDatabaseConnection(),
150
-				function() use ($c) {
151
-					return $c->query('ExternalManager');
152
-				},
153
-				$server->getCloudIdManager()
154
-			);
155
-		});
145
+        $container->registerService('ExternalMountProvider', function (IContainer $c) {
146
+            /** @var \OCP\IServerContainer $server */
147
+            $server = $c->query('ServerContainer');
148
+            return new \OCA\Files_Sharing\External\MountProvider(
149
+                $server->getDatabaseConnection(),
150
+                function() use ($c) {
151
+                    return $c->query('ExternalManager');
152
+                },
153
+                $server->getCloudIdManager()
154
+            );
155
+        });
156 156
 
157
-		/*
157
+        /*
158 158
 		 * Register capabilities
159 159
 		 */
160
-		$container->registerCapability('OCA\Files_Sharing\Capabilities');
161
-	}
160
+        $container->registerCapability('OCA\Files_Sharing\Capabilities');
161
+    }
162 162
 
163
-	public function registerMountProviders() {
164
-		/** @var \OCP\IServerContainer $server */
165
-		$server = $this->getContainer()->query('ServerContainer');
166
-		$mountProviderCollection = $server->getMountProviderCollection();
167
-		$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
168
-		$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
169
-	}
163
+    public function registerMountProviders() {
164
+        /** @var \OCP\IServerContainer $server */
165
+        $server = $this->getContainer()->query('ServerContainer');
166
+        $mountProviderCollection = $server->getMountProviderCollection();
167
+        $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
168
+        $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
169
+    }
170 170
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		/**
51 51
 		 * Controllers
52 52
 		 */
53
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
53
+		$container->registerService('ShareController', function(SimpleContainer $c) use ($server) {
54 54
 			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
55 55
 			return new ShareController(
56 56
 				$c->query('AppName'),
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 				$server->getThemingDefaults()
71 71
 			);
72 72
 		});
73
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
73
+		$container->registerService('ExternalSharesController', function(SimpleContainer $c) {
74 74
 			return new ExternalSharesController(
75 75
 				$c->query('AppName'),
76 76
 				$c->query('Request'),
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 		/**
83 83
 		 * Core class wrappers
84 84
 		 */
85
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
85
+		$container->registerService('HttpClientService', function(SimpleContainer $c) use ($server) {
86 86
 			return $server->getHTTPClientService();
87 87
 		});
88
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
88
+		$container->registerService(ICloudIdManager::class, function(SimpleContainer $c) use ($server) {
89 89
 			return $server->getCloudIdManager();
90 90
 		});
91
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
91
+		$container->registerService('ExternalManager', function(SimpleContainer $c) use ($server) {
92 92
 			$user = $server->getUserSession()->getUser();
93 93
 			$uid = $user ? $user->getUID() : null;
94 94
 			$discoveryManager = new DiscoveryManager(
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		/**
111 111
 		 * Middleware
112 112
 		 */
113
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
113
+		$container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server) {
114 114
 			return new SharingCheckMiddleware(
115 115
 				$c->query('AppName'),
116 116
 				$server->getConfig(),
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			);
122 122
 		});
123 123
 
124
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
124
+		$container->registerService('OCSShareAPIMiddleware', function(SimpleContainer $c) use ($server) {
125 125
 			return new OCSShareAPIMiddleware(
126 126
 				$server->getShareManager(),
127 127
 				$server->getL10N($c->query('AppName'))
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		$container->registerMiddleWare('SharingCheckMiddleware');
133 133
 		$container->registerMiddleWare('OCSShareAPIMiddleware');
134 134
 
135
-		$container->registerService('MountProvider', function (IContainer $c) {
135
+		$container->registerService('MountProvider', function(IContainer $c) {
136 136
 			/** @var \OCP\IServerContainer $server */
137 137
 			$server = $c->query('ServerContainer');
138 138
 			return new MountProvider(
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			);
143 143
 		});
144 144
 
145
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
145
+		$container->registerService('ExternalMountProvider', function(IContainer $c) {
146 146
 			/** @var \OCP\IServerContainer $server */
147 147
 			$server = $c->query('ServerContainer');
148 148
 			return new \OCA\Files_Sharing\External\MountProvider(
Please login to merge, or discard this patch.
apps/files_sharing/lib/External/Scanner.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -32,97 +32,97 @@
 block discarded – undo
32 32
 use OCP\Files\StorageNotAvailableException;
33 33
 
34 34
 class Scanner extends \OC\Files\Cache\Scanner {
35
-	/** @var \OCA\Files_Sharing\External\Storage */
36
-	protected $storage;
35
+    /** @var \OCA\Files_Sharing\External\Storage */
36
+    protected $storage;
37 37
 
38
-	/** {@inheritDoc} */
39
-	public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
40
-		if(!$this->storage->remoteIsOwnCloud()) {
41
-			return parent::scan($path, $recursive, $recursive, $lock);
42
-		}
38
+    /** {@inheritDoc} */
39
+    public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
40
+        if(!$this->storage->remoteIsOwnCloud()) {
41
+            return parent::scan($path, $recursive, $recursive, $lock);
42
+        }
43 43
 
44
-		$this->scanAll();
45
-	}
44
+        $this->scanAll();
45
+    }
46 46
 
47
-	/**
48
-	 * Scan a single file and store it in the cache.
49
-	 * If an exception happened while accessing the external storage,
50
-	 * the storage will be checked for availability and removed
51
-	 * if it is not available any more.
52
-	 *
53
-	 * @param string $file file to scan
54
-	 * @param int $reuseExisting
55
-	 * @param int $parentId
56
-	 * @param array | null $cacheData existing data in the cache for the file to be scanned
57
-	 * @param bool $lock set to false to disable getting an additional read lock during scanning
58
-	 * @return array an array of metadata of the scanned file
59
-	 */
60
-	public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
61
-		try {
62
-			return parent::scanFile($file, $reuseExisting);
63
-		} catch (ForbiddenException $e) {
64
-			$this->storage->checkStorageAvailability();
65
-		} catch (NotFoundException $e) {
66
-			// if the storage isn't found, the call to
67
-			// checkStorageAvailable() will verify it and remove it
68
-			// if appropriate
69
-			$this->storage->checkStorageAvailability();
70
-		} catch (StorageInvalidException $e) {
71
-			$this->storage->checkStorageAvailability();
72
-		} catch (StorageNotAvailableException $e) {
73
-			$this->storage->checkStorageAvailability();
74
-		}
75
-	}
47
+    /**
48
+     * Scan a single file and store it in the cache.
49
+     * If an exception happened while accessing the external storage,
50
+     * the storage will be checked for availability and removed
51
+     * if it is not available any more.
52
+     *
53
+     * @param string $file file to scan
54
+     * @param int $reuseExisting
55
+     * @param int $parentId
56
+     * @param array | null $cacheData existing data in the cache for the file to be scanned
57
+     * @param bool $lock set to false to disable getting an additional read lock during scanning
58
+     * @return array an array of metadata of the scanned file
59
+     */
60
+    public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) {
61
+        try {
62
+            return parent::scanFile($file, $reuseExisting);
63
+        } catch (ForbiddenException $e) {
64
+            $this->storage->checkStorageAvailability();
65
+        } catch (NotFoundException $e) {
66
+            // if the storage isn't found, the call to
67
+            // checkStorageAvailable() will verify it and remove it
68
+            // if appropriate
69
+            $this->storage->checkStorageAvailability();
70
+        } catch (StorageInvalidException $e) {
71
+            $this->storage->checkStorageAvailability();
72
+        } catch (StorageNotAvailableException $e) {
73
+            $this->storage->checkStorageAvailability();
74
+        }
75
+    }
76 76
 
77
-	/**
78
-	 * Checks the remote share for changes.
79
-	 * If changes are available, scan them and update
80
-	 * the cache.
81
-	 * @throws NotFoundException
82
-	 * @throws StorageInvalidException
83
-	 * @throws \Exception
84
-	 */
85
-	public function scanAll() {
86
-		try {
87
-			$data = $this->storage->getShareInfo();
88
-		} catch (\Exception $e) {
89
-			$this->storage->checkStorageAvailability();
90
-			throw new \Exception(
91
-				'Error while scanning remote share: "' .
92
-				$this->storage->getRemote() . '" ' .
93
-				$e->getMessage()
94
-			);
95
-		}
96
-		if ($data['status'] === 'success') {
97
-			$this->addResult($data['data'], '');
98
-		} else {
99
-			throw new \Exception(
100
-				'Error while scanning remote share: "' .
101
-				$this->storage->getRemote() . '"'
102
-			);
103
-		}
104
-	}
77
+    /**
78
+     * Checks the remote share for changes.
79
+     * If changes are available, scan them and update
80
+     * the cache.
81
+     * @throws NotFoundException
82
+     * @throws StorageInvalidException
83
+     * @throws \Exception
84
+     */
85
+    public function scanAll() {
86
+        try {
87
+            $data = $this->storage->getShareInfo();
88
+        } catch (\Exception $e) {
89
+            $this->storage->checkStorageAvailability();
90
+            throw new \Exception(
91
+                'Error while scanning remote share: "' .
92
+                $this->storage->getRemote() . '" ' .
93
+                $e->getMessage()
94
+            );
95
+        }
96
+        if ($data['status'] === 'success') {
97
+            $this->addResult($data['data'], '');
98
+        } else {
99
+            throw new \Exception(
100
+                'Error while scanning remote share: "' .
101
+                $this->storage->getRemote() . '"'
102
+            );
103
+        }
104
+    }
105 105
 
106
-	/**
107
-	 * @param array $data
108
-	 * @param string $path
109
-	 */
110
-	private function addResult($data, $path) {
111
-		$id = $this->cache->put($path, $data);
112
-		if (isset($data['children'])) {
113
-			$children = [];
114
-			foreach ($data['children'] as $child) {
115
-				$children[$child['name']] = true;
116
-				$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
117
-			}
106
+    /**
107
+     * @param array $data
108
+     * @param string $path
109
+     */
110
+    private function addResult($data, $path) {
111
+        $id = $this->cache->put($path, $data);
112
+        if (isset($data['children'])) {
113
+            $children = [];
114
+            foreach ($data['children'] as $child) {
115
+                $children[$child['name']] = true;
116
+                $this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
117
+            }
118 118
 
119
-			$existingCache = $this->cache->getFolderContentsById($id);
120
-			foreach ($existingCache as $existingChild) {
121
-				// if an existing child is not in the new data, remove it
122
-				if (!isset($children[$existingChild['name']])) {
123
-					$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
124
-				}
125
-			}
126
-		}
127
-	}
119
+            $existingCache = $this->cache->getFolderContentsById($id);
120
+            foreach ($existingCache as $existingChild) {
121
+                // if an existing child is not in the new data, remove it
122
+                if (!isset($children[$existingChild['name']])) {
123
+                    $this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
124
+                }
125
+            }
126
+        }
127
+    }
128 128
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
 	/** {@inheritDoc} */
39 39
 	public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
40
-		if(!$this->storage->remoteIsOwnCloud()) {
40
+		if (!$this->storage->remoteIsOwnCloud()) {
41 41
 			return parent::scan($path, $recursive, $recursive, $lock);
42 42
 		}
43 43
 
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 		} catch (\Exception $e) {
89 89
 			$this->storage->checkStorageAvailability();
90 90
 			throw new \Exception(
91
-				'Error while scanning remote share: "' .
92
-				$this->storage->getRemote() . '" ' .
91
+				'Error while scanning remote share: "'.
92
+				$this->storage->getRemote().'" '.
93 93
 				$e->getMessage()
94 94
 			);
95 95
 		}
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 			$this->addResult($data['data'], '');
98 98
 		} else {
99 99
 			throw new \Exception(
100
-				'Error while scanning remote share: "' .
101
-				$this->storage->getRemote() . '"'
100
+				'Error while scanning remote share: "'.
101
+				$this->storage->getRemote().'"'
102 102
 			);
103 103
 		}
104 104
 	}
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
 			$children = [];
114 114
 			foreach ($data['children'] as $child) {
115 115
 				$children[$child['name']] = true;
116
-				$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
116
+				$this->addResult($child, ltrim($path.'/'.$child['name'], '/'));
117 117
 			}
118 118
 
119 119
 			$existingCache = $this->cache->getFolderContentsById($id);
120 120
 			foreach ($existingCache as $existingChild) {
121 121
 				// if an existing child is not in the new data, remove it
122 122
 				if (!isset($children[$existingChild['name']])) {
123
-					$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
123
+					$this->cache->remove(ltrim($path.'/'.$existingChild['name'], '/'));
124 124
 				}
125 125
 			}
126 126
 		}
Please login to merge, or discard this patch.