Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace OCA\FederatedFileSharing\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use OCP\Migration\ISchemaMigration;

/** Updates remote_id to be string if required */
class Version20190410160725 implements ISchemaMigration {
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];

if ($schema->hasTable("${prefix}federated_reshares")) {
$table = $schema->getTable("{$prefix}federated_reshares");
$remoteIdColumn = $table->getColumn('remote_id');
if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Type::STRING) {
$remoteIdColumn->setType(Type::getType(Type::STRING));
$remoteIdColumn->setOptions(['length' => 255]);
}
}

if ($schema->hasTable("${prefix}share_external")) {
$table = $schema->getTable("{$prefix}share_external");
$remoteIdColumn = $table->getColumn('remote_id');
if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Type::STRING) {
$remoteIdColumn->setType(Type::getType(Type::STRING));
$remoteIdColumn->setOptions(['length' => 255]);
}
}
}
}
2 changes: 1 addition & 1 deletion apps/federatedfilesharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<description>Provide federated file sharing across ownCloud servers</description>
<licence>AGPL</licence>
<author>Bjoern Schiessle, Roeland Jago Douma</author>
<version>0.4.0</version>
<version>0.5.0</version>
<namespace>FederatedFileSharing</namespace>
<use-migrations>true</use-migrations>
<category>other</category>
Expand Down
4 changes: 2 additions & 2 deletions apps/federatedfilesharing/lib/FedShareManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function __construct(FederatedShareProvider $federatedShareProvider,
* @param Address $ownerAddress
* @param Address $sharedByAddress
* @param string $shareWith
* @param int $remoteId
* @param string $remoteId
* @param string $name
* @param string $token
*
Expand Down Expand Up @@ -181,7 +181,7 @@ public function createShare(Address $ownerAddress,

/**
* @param IShare $share
* @param int $remoteId
* @param string $remoteId
* @param string $shareWith
* @param int|null $permissions - null for OCM 1.0-proposal1
*
Expand Down
8 changes: 4 additions & 4 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected function getShareFromExternalShareTable(IShare $share) {
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
$result = $query->execute()->fetchAll();

if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) {
if (isset($result[0]) && $result[0]['remote_id'] !== "") {
return $result[0];
}

Expand Down Expand Up @@ -427,7 +427,7 @@ public function storeRemoteId($shareId, $remoteId) {
* get share ID on remote server for federated re-shares
*
* @param IShare $share
* @return int
* @return string
* @throws ShareNotFound
*/
public function getRemoteId(IShare $share) {
Expand All @@ -440,7 +440,7 @@ public function getRemoteId(IShare $share) {
throw new ShareNotFound();
}

return (int)$data['remote_id'];
return $data['remote_id'];
}

/**
Expand Down Expand Up @@ -975,7 +975,7 @@ public function updateForRecipient(IShare $share, $recipient) {
}

/**
* @param int $remoteId
* @param string $remoteId
* @param string $shareToken
* @return mixed
*/
Expand Down
16 changes: 8 additions & 8 deletions apps/federatedfilesharing/lib/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(
* @param Address $sharedByAddress
* @param string $token
* @param string $name
* @param int $remote_id
* @param string $remote_id
*
* @return bool
*
Expand Down Expand Up @@ -148,7 +148,7 @@ public function requestReShare($token, $id, $shareId, $remote, $shareWith, $perm
if (\is_array($response) && isset($response['sharedSecret'], $response['providerId'])) {
return [
$response['sharedSecret'],
(int) $response['providerId']
$response['providerId']
];
}
return true;
Expand All @@ -172,7 +172,7 @@ public function requestReShare($token, $id, $shareId, $remote, $shareWith, $perm
if ($httpRequestSuccessful && $this->isOcsStatusOk($status) && $validToken && $validRemoteId) {
return [
$status['ocs']['data']['token'],
(int)$status['ocs']['data']['remoteId']
$status['ocs']['data']['remoteId']
];
}

Expand Down Expand Up @@ -207,7 +207,7 @@ public function sendRevokeShare($remote, $id, $token) {
* send notification to remote server if the permissions was changed
*
* @param string $remote
* @param int $remoteId
* @param string $remoteId
* @param string $token
* @param int $permissions
* @return bool
Expand All @@ -220,7 +220,7 @@ public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
* forward accept reShare to remote server
*
* @param string $remote
* @param int $remoteId
* @param string $remoteId
* @param string $token
*/
public function sendAcceptShare($remote, $remoteId, $token) {
Expand All @@ -231,7 +231,7 @@ public function sendAcceptShare($remote, $remoteId, $token) {
* forward decline reShare to remote server
*
* @param string $remote
* @param int $remoteId
* @param string $remoteId
* @param string $token
*/
public function sendDeclineShare($remote, $remoteId, $token) {
Expand All @@ -242,7 +242,7 @@ public function sendDeclineShare($remote, $remoteId, $token) {
* inform remote server whether server-to-server share was accepted/declined
*
* @param string $remote
* @param int $remoteId Share id on the remote host
* @param string $remoteId Share id on the remote host
* @param string $token
* @param string $action possible actions:
* accept, decline, unshare, revoke, permissions
Expand Down Expand Up @@ -371,7 +371,7 @@ protected function sendOcmRemoteShare(Address $shareWithAddress, Address $ownerA
$fields = [
'shareWith' => $shareWithAddress->getCloudId(),
'name' => $name,
'providerId' => $remote_id,
'providerId' => (string) $remote_id,
'owner' => $ownerAddress->getCloudId(),
'ownerDisplayName' => $ownerAddress->getDisplayName(),
'sender' => $sharedByAddress->getCloudId(),
Expand Down
37 changes: 37 additions & 0 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
*/
namespace OCA\FederatedFileSharing\Tests;

use Doctrine\DBAL\Driver\Statement;
use OCA\FederatedFileSharing\Address;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -945,4 +948,38 @@ public function dataTestGetAccepted() {
[false, 'yes', 'yes', true, true],
];
}

public function testGetRemoteId() {
$exprBuilder = $this->createMock(IExpressionBuilder::class);
$statementMock = $this->createMock(Statement::class);
$statementMock->method('fetch')->willReturn(['remote_id' => 'a0b0c0']);

$qbMock = $this->createMock(IQueryBuilder::class);
$qbMock->method('select')->willReturnSelf();
$qbMock->method('from')->willReturnSelf();
$qbMock->method('where')->willReturnSelf();
$qbMock->method('expr')->willReturn($exprBuilder);
$qbMock->method('execute')->willReturn($statementMock);
$connectionMock = $this->createMock(IDBConnection::class);
$connectionMock->method('getQueryBuilder')->willReturn($qbMock);

$shareMock = $this->createMock(IShare::class);
$this->provider = new FederatedShareProvider(
$connectionMock,
$this->eventDispatcher,
$this->addressHandler,
$this->notifications,
$this->tokenHandler,
$this->l,
$this->logger,
$this->rootFolder,
$this->config,
$this->userManager
);

$this->assertEquals(
'a0b0c0',
$this->provider->getRemoteId($shareMock)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace OCA\FederatedFileSharing\Tests\appinfo\Migrations;

// FIXME: autoloader fails to load migration
require_once \dirname(\dirname(\dirname(__DIR__))) . "/appinfo/Migrations/Version20190410160725.php";

use Doctrine\DBAL\Schema\Table;
use OCA\FederatedFileSharing\Migrations\Version20190410160725;
use Test\TestCase;
use Doctrine\DBAL\Schema\Schema;

class Version20190410160725Test extends TestCase {
public function testExecute() {
$tablePrefix = 'pr_';
$migration = new Version20190410160725();
$table = $this->createMock(Table::class);
$schema = $this->createMock(Schema::class);
$schema->method('hasTable')->withConsecutive(
['pr_federated_reshares'],
['pr_share_external']
)->willReturn(true);
$schema->method('getTable')->withConsecutive(
['pr_federated_reshares'],
['pr_share_external']
)->willReturn($table);

$this->assertNull($migration->changeSchema($schema, ['tablePrefix' => $tablePrefix]));
}
}
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function __construct(\OCP\IDBConnection $connection,
* @param string $owner
* @param boolean $accepted
* @param string $user
* @param int $remoteId
* @param string $remoteId
* @return Mount|null
*/
public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Share/Events/ShareEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function getRemote() {
}

/**
* @return int
* @return string
* @since 10.0.2
*/
public function getRemoteId() {
return (int)$this->share['remote_id'];
return $this->share['remote_id'];
}

/**
Expand Down