Skip to content

Commit

Permalink
Redistribute authorities
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo authored and gitmate-bot committed Dec 5, 2018
1 parent e19f65d commit f6c6633
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 177 deletions.
20 changes: 14 additions & 6 deletions apps/federatedfilesharing/lib/AddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,21 @@ public function compareAddresses($user1, $server1, $user2, $server2) {
* @return string
*/
public function removeProtocolFromUrl($url) {
if (\strpos($url, 'https://') === 0) {
return \substr($url, \strlen('https://'));
} elseif (\strpos($url, 'http://') === 0) {
return \substr($url, \strlen('http://'));
}
// replace all characters before :// and :// itself
return \preg_replace('|^(.*?://)|', '', $url);
}

return $url;
/**
* Get a remote name without a protocol, potential file names
* and a trailing slash
*
* @param string $remote
*
* @return string
*/
public function normalizeRemote($remote) {
$fixedRemote = $this->fixRemoteURL($remote);
return $this->removeProtocolFromUrl($fixedRemote);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ function ($c) use ($server) {
function ($c) use ($server) {
return new FedShareManager(
$this->getFederatedShareProvider(),
$server->getDatabaseConnection(),
$c->query('Notifications'),
$server->getUserManager(),
$server->getActivityManager(),
$server->getNotificationManager(),
$c->query('AddressHandler'),
$server->getEventDispatcher()
);
}
Expand All @@ -97,10 +98,8 @@ function ($c) use ($server) {
$c->query('AppName'),
$c->query('Request'),
$this->getFederatedShareProvider(),
$server->getDatabaseConnection(),
$server->getAppManager(),
$server->getUserManager(),
$c->query('Notifications'),
$c->query('AddressHandler'),
$c->query('FederatedShareManager')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@
use OCA\FederatedFileSharing\Exception\InvalidShareException;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\FedShareManager;
use OCA\FederatedFileSharing\Notifications;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCSController;
use OCP\Constants;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Share;
Expand All @@ -55,17 +53,12 @@ class RequestHandlerController extends OCSController {
/** @var FederatedShareProvider */
private $federatedShareProvider;

/** @var IDBConnection */
private $connection;

/** @var IAppManager */
private $appManager;

/** @var IUserManager */
private $userManager;

/** @var Notifications */
private $notifications;

/** @var AddressHandler */
private $addressHandler;

Expand All @@ -78,30 +71,24 @@ class RequestHandlerController extends OCSController {
* @param string $appName
* @param IRequest $request
* @param FederatedShareProvider $federatedShareProvider
* @param IDBConnection $connection
* @param IAppManager $appManager
* @param IUserManager $userManager
* @param Notifications $notifications
* @param AddressHandler $addressHandler
* @param FedShareManager $fedShareManager
*/
public function __construct($appName,
IRequest $request,
FederatedShareProvider $federatedShareProvider,
IDBConnection $connection,
IAppManager $appManager,
IUserManager $userManager,
Notifications $notifications,
AddressHandler $addressHandler,
FedShareManager $fedShareManager
) {
parent::__construct($appName, $request);

$this->federatedShareProvider = $federatedShareProvider;
$this->connection = $connection;
$this->appManager = $appManager;
$this->userManager = $userManager;
$this->notifications = $notifications;
$this->addressHandler = $addressHandler;
$this->fedShareManager = $fedShareManager;
}
Expand Down Expand Up @@ -228,7 +215,6 @@ public function reShare($id) {
if (!$reSharingAllowed) {
return new Result(null, Http::STATUS_BAD_REQUEST);
}
$share->setPermissions($share->getPermissions() & $permission);
$result = $this->fedShareManager->reShare(
$share,
$remoteId,
Expand Down Expand Up @@ -264,20 +250,8 @@ public function reShare($id) {
public function acceptShare($id) {
try {
$this->assertOutgoingSharingEnabled();

$share = $this->getValidShare($id);
$this->fedShareManager->acceptShare($share);
if ($share->getShareOwner() !== $share->getSharedBy()) {
list(, $remote) = $this->addressHandler->splitUserRemote(
$share->getSharedBy()
);
$remoteId = $this->federatedShareProvider->getRemoteId($share);
$this->notifications->sendAcceptShare(
$remote,
$remoteId,
$share->getToken()
);
}
} catch (NotSupportedException $e) {
return new Result(
null,
Expand All @@ -303,13 +277,7 @@ public function acceptShare($id) {
public function declineShare($id) {
try {
$this->assertOutgoingSharingEnabled();

$share = $this->getValidShare($id);
if ($share->getShareOwner() !== $share->getSharedBy()) {
list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
$remoteId = $this->federatedShareProvider->getRemoteId($share);
$this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken());
}
$this->fedShareManager->declineShare($share);
} catch (NotSupportedException $e) {
return new Result(
Expand Down Expand Up @@ -338,22 +306,8 @@ public function unshare($id) {
try {
$this->assertOutgoingSharingEnabled();
$token = $this->request->getParam('token', null);
$query = $this->connection->getQueryBuilder();
$query->select('*')->from('share_external')
->where(
$query->expr()->eq(
'remote_id', $query->createNamedParameter($id)
)
)
->andWhere(
$query->expr()->eq(
'share_token',
$query->createNamedParameter($token)
)
);
$shareRow = $query->execute()->fetch();
if ($token && $id && $shareRow !== false) {
$this->fedShareManager->unshare($shareRow);
if ($token && $id) {
$this->fedShareManager->unshare($id, $token);
}
} catch (NotSupportedException $e) {
return new Result(
Expand Down
Loading

0 comments on commit f6c6633

Please sign in to comment.