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
Expand Up @@ -67,7 +67,7 @@ class RequestHandlerControllerTest extends TestCase {

/** @var \OCA\FederatedFileSharing\AddressHandler|\PHPUnit_Framework_MockObject_MockObject */
private $addressHandler;

/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;

Expand Down Expand Up @@ -107,7 +107,7 @@ protected function setUp() {
$this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock();

$this->cloudIdManager = new CloudIdManager();

$this->registerHttpHelper($httpHelperMock);

$this->s2s = new RequestHandlerController(
Expand Down Expand Up @@ -384,6 +384,7 @@ public function testGetShare($found, $correctId, $correctToken) {
'parent' => null,
'accepted' => '0',
'expiration' => null,
'password' => null,
'mail_send' => '0'
];

Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Turning the feature off removes shared files and folders on the server for all s
<licence>AGPL</licence>
<author>Michael Gapczynski, Bjoern Schiessle</author>
<default_enable/>
<version>1.2.0</version>
<version>1.4.0</version>
<types>
<filesystem/>
</types>
Expand Down
5 changes: 5 additions & 0 deletions apps/files_sharing/appinfo/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
if (version_compare($installedVersion, '1.1.1', '<')) {
$m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig());
}

if (version_compare($installedVersion, '1.4.0', '<')) {
$m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig());
$m->addPasswordColumn();
}
26 changes: 24 additions & 2 deletions apps/files_sharing/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
namespace OCA\Files_Sharing;

use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;
use \OCP\IConfig;

Expand All @@ -34,8 +35,12 @@ class Capabilities implements ICapability {
/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
/** @var IAppManager */
private $appManager;

public function __construct(IConfig $config, IAppManager $appManager) {
$this->config = $config;
$this->appManager = $appManager;
}

/**
Expand Down Expand Up @@ -76,16 +81,33 @@ public function getCapabilities() {
$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';

$res['user']['send_mail'] = false;
$res['user']['expire_date']['enabled'] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is $res['user']['expire_date'] set anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one is for group shares and one for user shares.


// deprecated in favour of 'group', but we need to keep it for now
// in order to stay compatible with older clients
$res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';

$res['group'] = [];
$res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
$res['group']['expire_date']['enabled'] = true;
}

//Federated sharing
$res['federation'] = [
'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes',
'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes'
'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
'expire_date' => ['enabled' => true]
];

if ($this->appManager->isEnabledForUser('sharebymail')) {
$res['mailshare'] = [
'enabled' => true,
'upload_files_drop' => ['enabled' => true],
'password' => ['enabled' => true],
'expire_date' => ['enabled' => true]
];
}

return [
'files_sharing' => $res,
];
Expand Down
43 changes: 31 additions & 12 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
$result['file_parent'] = $node->getParent()->getId();
$result['file_target'] = $share->getTarget();

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}

if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $this->userManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
Expand All @@ -179,17 +184,13 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
$result['token'] = $share->getToken();
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}

} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
$result['token'] = $share->getToken();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
$result['share_with'] = $share->getSharedWith();
$result['password'] = $share->getPassword();
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
$result['token'] = $share->getToken();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
Expand Down Expand Up @@ -668,13 +669,14 @@ public function updateShare(
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
}

if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
}

/*
* expirationdate, password and publicUpload only make sense for link shares
*/
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
}

$newPermissions = null;
if ($publicUpload === 'true') {
Expand Down Expand Up @@ -740,13 +742,30 @@ public function updateShare(
}

} else {
// For other shares only permissions is valid.
if ($permissions === null) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
} else {
if ($permissions !== null) {
$permissions = (int)$permissions;
$share->setPermissions($permissions);
}

if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
if ($password === '') {
$share->setPassword(null);
} else if ($password !== null) {
$share->setPassword($password);
}
}

if ($expireDate === '') {
$share->setExpirationDate(null);
} else if ($expireDate !== null) {
try {
$expireDate = $this->parseDate($expireDate);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage());
}
$share->setExpirationDate($expireDate);
}

}

if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
Expand Down
18 changes: 18 additions & 0 deletions apps/files_sharing/lib/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ public function removeSendMailOption() {
$this->config->deleteAppValue('core', 'shareapi_allow_public_notification');
}

public function addPasswordColumn() {
$query = $this->connection->getQueryBuilder();
$query
->update('share')
->set('password', 'share_with')
->where($query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
->andWhere($query->expr()->isNotNull('share_with'));
$query->execute();

$clearQuery = $this->connection->getQueryBuilder();
$clearQuery
->update('share')->set('share_with', $clearQuery->createNamedParameter(null))
->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));

$clearQuery->execute();

}

/**
* find the owner of a re-shared file/folder
*
Expand Down
30 changes: 0 additions & 30 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,36 +936,6 @@ function testUpdateShare() {
$this->shareManager->deleteShare($share2);
}

/**
* @medium
* @depends testCreateShareUserFile
*/
public function testUpdateShareInvalidPermissions() {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);

$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
} catch (OCSBadRequestException $e) {

}
$ocs->cleanup();

//Permissions should not have changed!
$share1 = $this->shareManager->getShareById('ocinternal:' . $share1->getId());
$this->assertEquals(19, $share1->getPermissions());

$this->shareManager->deleteShare($share1);
}

/**
* @medium
*/
Expand Down
11 changes: 7 additions & 4 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Tests\TestCase;
use OCP\App\IAppManager;

/**
* Class CapabilitiesTest
Expand All @@ -46,17 +47,19 @@ private function getFilesSharingPart(array $data) {
}

/**
* Create a mock config object and insert the values in $map tot the getAppValue
* Create a mock config object and insert the values in $map to the getAppValue
* function. Then obtain the capabilities and extract the first few
* levels in the array
*
* @param (string[])[] $map Map of arguments to return types for the getAppValue function in the mock
* @return string[]
*/
private function getResults(array $map) {
$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
$stub->method('getAppValue')->will($this->returnValueMap($map));
$cap = new Capabilities($stub);
$config = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
$config->method('getAppValue')->will($this->returnValueMap($map));
$appManager = $this->getMockBuilder(IAppManager::class)->getMock();
$appManager->expects($this->any())->method('isEnabledForUser')->with('sharebymail')->willReturn(true);
$cap = new Capabilities($config, $appManager);
$result = $this->getFilesSharingPart($cap->getCapabilities());
return $result;
}
Expand Down
Loading