Skip to content

Commit 18b0d02

Browse files
committed
Redistribute authorities
1 parent cc4525f commit 18b0d02

8 files changed

Lines changed: 285 additions & 177 deletions

File tree

apps/federatedfilesharing/lib/AddressHandler.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,21 @@ public function compareAddresses($user1, $server1, $user2, $server2) {
151151
* @return string
152152
*/
153153
public function removeProtocolFromUrl($url) {
154-
if (\strpos($url, 'https://') === 0) {
155-
return \substr($url, \strlen('https://'));
156-
} elseif (\strpos($url, 'http://') === 0) {
157-
return \substr($url, \strlen('http://'));
158-
}
154+
// replace all characters before :// and :// itself
155+
return \preg_replace('|^(.*?://)|', '', $url);
156+
}
159157

160-
return $url;
158+
/**
159+
* Get a remote name without a protocol, potential file names
160+
* and a trailing slash
161+
*
162+
* @param string $remote
163+
*
164+
* @return string
165+
*/
166+
public function normalizeRemote($remote) {
167+
$fixedRemote = $this->fixRemoteURL($remote);
168+
return $this->removeProtocolFromUrl($fixedRemote);
161169
}
162170

163171
/**

apps/federatedfilesharing/lib/AppInfo/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ function ($c) use ($server) {
8181
function ($c) use ($server) {
8282
return new FedShareManager(
8383
$this->getFederatedShareProvider(),
84-
$server->getDatabaseConnection(),
84+
$c->query('Notifications'),
8585
$server->getUserManager(),
8686
$server->getActivityManager(),
8787
$server->getNotificationManager(),
88+
$c->query('AddressHandler'),
8889
$server->getEventDispatcher()
8990
);
9091
}
@@ -97,10 +98,8 @@ function ($c) use ($server) {
9798
$c->query('AppName'),
9899
$c->query('Request'),
99100
$this->getFederatedShareProvider(),
100-
$server->getDatabaseConnection(),
101101
$server->getAppManager(),
102102
$server->getUserManager(),
103-
$c->query('Notifications'),
104103
$c->query('AddressHandler'),
105104
$c->query('FederatedShareManager')
106105
);

apps/federatedfilesharing/lib/Controller/RequestHandlerController.php

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232
use OCA\FederatedFileSharing\Exception\InvalidShareException;
3333
use OCA\FederatedFileSharing\FederatedShareProvider;
3434
use OCA\FederatedFileSharing\FedShareManager;
35-
use OCA\FederatedFileSharing\Notifications;
3635
use OCP\App\IAppManager;
3736
use OCP\AppFramework\Http;
3837
use OCP\AppFramework\OCSController;
3938
use OCP\Constants;
40-
use OCP\IDBConnection;
4139
use OCP\IRequest;
4240
use OCP\IUserManager;
4341
use OCP\Share;
@@ -55,17 +53,12 @@ class RequestHandlerController extends OCSController {
5553
/** @var FederatedShareProvider */
5654
private $federatedShareProvider;
5755

58-
/** @var IDBConnection */
59-
private $connection;
60-
6156
/** @var IAppManager */
6257
private $appManager;
58+
6359
/** @var IUserManager */
6460
private $userManager;
6561

66-
/** @var Notifications */
67-
private $notifications;
68-
6962
/** @var AddressHandler */
7063
private $addressHandler;
7164

@@ -78,30 +71,24 @@ class RequestHandlerController extends OCSController {
7871
* @param string $appName
7972
* @param IRequest $request
8073
* @param FederatedShareProvider $federatedShareProvider
81-
* @param IDBConnection $connection
8274
* @param IAppManager $appManager
8375
* @param IUserManager $userManager
84-
* @param Notifications $notifications
8576
* @param AddressHandler $addressHandler
8677
* @param FedShareManager $fedShareManager
8778
*/
8879
public function __construct($appName,
8980
IRequest $request,
9081
FederatedShareProvider $federatedShareProvider,
91-
IDBConnection $connection,
9282
IAppManager $appManager,
9383
IUserManager $userManager,
94-
Notifications $notifications,
9584
AddressHandler $addressHandler,
9685
FedShareManager $fedShareManager
9786
) {
9887
parent::__construct($appName, $request);
9988

10089
$this->federatedShareProvider = $federatedShareProvider;
101-
$this->connection = $connection;
10290
$this->appManager = $appManager;
10391
$this->userManager = $userManager;
104-
$this->notifications = $notifications;
10592
$this->addressHandler = $addressHandler;
10693
$this->fedShareManager = $fedShareManager;
10794
}
@@ -228,7 +215,6 @@ public function reShare($id) {
228215
if (!$reSharingAllowed) {
229216
return new Result(null, Http::STATUS_BAD_REQUEST);
230217
}
231-
$share->setPermissions($share->getPermissions() & $permission);
232218
$result = $this->fedShareManager->reShare(
233219
$share,
234220
$remoteId,
@@ -264,20 +250,8 @@ public function reShare($id) {
264250
public function acceptShare($id) {
265251
try {
266252
$this->assertOutgoingSharingEnabled();
267-
268253
$share = $this->getValidShare($id);
269254
$this->fedShareManager->acceptShare($share);
270-
if ($share->getShareOwner() !== $share->getSharedBy()) {
271-
list(, $remote) = $this->addressHandler->splitUserRemote(
272-
$share->getSharedBy()
273-
);
274-
$remoteId = $this->federatedShareProvider->getRemoteId($share);
275-
$this->notifications->sendAcceptShare(
276-
$remote,
277-
$remoteId,
278-
$share->getToken()
279-
);
280-
}
281255
} catch (NotSupportedException $e) {
282256
return new Result(
283257
null,
@@ -303,13 +277,7 @@ public function acceptShare($id) {
303277
public function declineShare($id) {
304278
try {
305279
$this->assertOutgoingSharingEnabled();
306-
307280
$share = $this->getValidShare($id);
308-
if ($share->getShareOwner() !== $share->getSharedBy()) {
309-
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
310-
$remoteId = $this->federatedShareProvider->getRemoteId($share);
311-
$this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken());
312-
}
313281
$this->fedShareManager->declineShare($share);
314282
} catch (NotSupportedException $e) {
315283
return new Result(
@@ -338,22 +306,8 @@ public function unshare($id) {
338306
try {
339307
$this->assertOutgoingSharingEnabled();
340308
$token = $this->request->getParam('token', null);
341-
$query = $this->connection->getQueryBuilder();
342-
$query->select('*')->from('share_external')
343-
->where(
344-
$query->expr()->eq(
345-
'remote_id', $query->createNamedParameter($id)
346-
)
347-
)
348-
->andWhere(
349-
$query->expr()->eq(
350-
'share_token',
351-
$query->createNamedParameter($token)
352-
)
353-
);
354-
$shareRow = $query->execute()->fetch();
355-
if ($token && $id && $shareRow !== false) {
356-
$this->fedShareManager->unshare($shareRow);
309+
if ($token && $id) {
310+
$this->fedShareManager->unshare($id, $token);
357311
}
358312
} catch (NotSupportedException $e) {
359313
return new Result(

0 commit comments

Comments
 (0)