diff options
-rw-r--r-- | apps/files_sharing/lib/deleteorphanedsharesjob.php | 11 | ||||
-rw-r--r-- | core/command/encryption/status.php | 56 | ||||
-rw-r--r-- | core/js/share.js | 2 | ||||
-rw-r--r-- | core/js/tests/specs/shareSpec.js | 25 | ||||
-rw-r--r-- | core/register_command.php | 1 | ||||
-rw-r--r-- | lib/private/share/share.php | 16 | ||||
-rw-r--r-- | lib/private/tags.php | 1 | ||||
-rw-r--r-- | tests/lib/share/share.php | 33 |
8 files changed, 134 insertions, 11 deletions
diff --git a/apps/files_sharing/lib/deleteorphanedsharesjob.php b/apps/files_sharing/lib/deleteorphanedsharesjob.php index f39078b778f..0654c82dd94 100644 --- a/apps/files_sharing/lib/deleteorphanedsharesjob.php +++ b/apps/files_sharing/lib/deleteorphanedsharesjob.php @@ -22,8 +22,6 @@ namespace OCA\Files_sharing\Lib; -use Doctrine\DBAL\Platforms\SqlitePlatform; -use OCP\IDBConnection; use OC\BackgroundJob\TimedJob; /** @@ -39,6 +37,13 @@ class DeleteOrphanedSharesJob extends TimedJob { protected $defaultIntervalMin = 15; /** + * sets the correct interval for this timed job + */ + public function __construct(){ + $this->interval = $this->defaultIntervalMin * 60; + } + + /** * Makes the background job do its work * * @param array $argument unused argument @@ -53,7 +58,7 @@ class DeleteOrphanedSharesJob extends TimedJob { 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; $deletedEntries = $connection->executeUpdate($sql); - $logger->info("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); } } diff --git a/core/command/encryption/status.php b/core/command/encryption/status.php new file mode 100644 index 00000000000..1a52500cf29 --- /dev/null +++ b/core/command/encryption/status.php @@ -0,0 +1,56 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Core\Command\Encryption; + +use OC\Core\Command\Base; +use OCP\Encryption\IManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Status extends Base { + /** @var IManager */ + protected $encryptionManager; + + /** + * @param IManager $encryptionManager + */ + public function __construct(IManager $encryptionManager) { + parent::__construct(); + $this->encryptionManager = $encryptionManager; + } + + protected function configure() { + parent::configure(); + + $this + ->setName('encryption:status') + ->setDescription('Lists the current status of encryption') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $this->writeArrayInOutputFormat($input, $output, [ + 'enabled' => $this->encryptionManager->isEnabled(), + 'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(), + ]); + } +} diff --git a/core/js/share.js b/core/js/share.js index 45873ca870e..6723b829ca5 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -356,7 +356,7 @@ OC.Share={ var data = OC.Share.loadItem(itemType, itemSource); var dropDownEl; var html = '<div id="dropdown" class="drop shareDropDown" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">'; - if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) { + if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined && data.reshare.uid_owner !== OC.currentUser) { html += '<span class="reshare">'; if (oc_config.enable_avatars === true) { html += '<div class="avatar"></div> '; diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index a16358b55c5..3e9a0b247d7 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -29,6 +29,7 @@ describe('OC.Share tests', function() { var oldEnableAvatars; var avatarStub; var placeholderStub; + var oldCurrentUser; beforeEach(function() { $('#testArea').append($('<div id="shareContainer"></div>')); @@ -62,8 +63,12 @@ describe('OC.Share tests', function() { oc_config.enable_avatars = false; avatarStub = sinon.stub($.fn, 'avatar'); placeholderStub = sinon.stub($.fn, 'imageplaceholder'); + + oldCurrentUser = OC.currentUser; + OC.currentUser = 'user0'; }); afterEach(function() { + OC.currentUser = oldCurrentUser; /* jshint camelcase:false */ oc_appconfig.core = oldAppConfig; loadItemStub.restore(); @@ -864,6 +869,26 @@ describe('OC.Share tests', function() { ); expect($('#dropdown #shareWithList').length).toEqual(0); }); + it('allows owner to share their own share when they are also the recipient', function() { + OC.currentUser = 'user1'; + loadItemStub.returns({ + reshare: { + permissions: OC.PERMISSION_READ, + uid_owner: 'user1' + }, + shares: [] + }); + OC.Share.showDropDown( + 'file', + 123, + $container, + true, + OC.PERMISSION_ALL, + 'shared_file_name.txt' + ); + // sharing still allowed + expect($('#dropdown #shareWithList').length).toEqual(1); + }); }); }); }); diff --git a/core/register_command.php b/core/register_command.php index b9c722860c1..5e16abca0c0 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -54,6 +54,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig())); $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); } else { $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig())); } diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 38f763bfe87..027c518f9f1 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -333,15 +333,15 @@ class Share extends Constants { $shares = array(); $fileDependent = false; + $where = 'WHERE'; + $fileDependentWhere = ''; if ($itemType === 'file' || $itemType === 'folder') { $fileDependent = true; $column = 'file_source'; - $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` '; - $where .= 'INNER JOIN `*PREFIX*storages` ON `numeric_id` = `*PREFIX*filecache`.`storage` '; - $where .= ' WHERE'; + $fileDependentWhere = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` '; + $fileDependentWhere .= 'INNER JOIN `*PREFIX*storages` ON `numeric_id` = `*PREFIX*filecache`.`storage` '; } else { $column = 'item_source'; - $where = 'WHERE'; } $select = self::createSelectStatement(self::FORMAT_NONE, $fileDependent); @@ -364,7 +364,7 @@ class Share extends Constants { $arguments[] = $owner; } - $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` '. $where); + $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` '. $fileDependentWhere . $where); $result = \OC_DB::executeAudited($query, $arguments); @@ -380,7 +380,7 @@ class Share extends Constants { $groups = \OC_Group::getUserGroups($user); if (!empty($groups)) { - $where = 'WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'; + $where = $fileDependentWhere . ' WHERE `' . $column . '` = ? AND `item_type` = ? AND `share_with` in (?)'; $arguments = array($itemSource, $itemType, $groups); $types = array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY); @@ -394,7 +394,7 @@ class Share extends Constants { // class isn't static anymore... $conn = \OC_DB::getConnection(); $result = $conn->executeQuery( - 'SELECT * FROM `*PREFIX*share` ' . $where, + 'SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where, $arguments, $types ); @@ -2100,7 +2100,9 @@ class Share extends Constants { \OC_Log::write('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR); throw new \Exception($message_t); } + } + if ($checkReshare && $checkReshare['uid_owner'] !== \OC_User::getUser()) { // Check if share permissions is granted if (self::isResharingAllowed() && (int)$checkReshare['permissions'] & \OCP\Constants::PERMISSION_SHARE) { if (~(int)$checkReshare['permissions'] & $permissions) { diff --git a/lib/private/tags.php b/lib/private/tags.php index 6edd7b2f980..09cb7618c02 100644 --- a/lib/private/tags.php +++ b/lib/private/tags.php @@ -257,6 +257,7 @@ class Tags implements \OCP\ITags { */ public function getIdsForTag($tag) { $result = null; + $tagId = false; if(is_numeric($tag)) { $tagId = $tag; } elseif(is_string($tag)) { diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index abdddfb5584..5909102f797 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -501,6 +501,38 @@ class Test_Share extends \Test\TestCase { } + public function testSharingAFolderThatIsSharedWithAGroupOfTheOwner() { + OC_User::setUserId($this->user1); + $view = new \OC\Files\View('/' . $this->user1 . '/'); + $view->mkdir('files/test'); + $view->mkdir('files/test/sub1'); + $view->mkdir('files/test/sub1/sub2'); + + $fileInfo = $view->getFileInfo('files/test/sub1'); + $fileId = $fileInfo->getId(); + + $this->assertTrue( + OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_GROUP, $this->group1, \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_CREATE), + 'Failed asserting that user 1 successfully shared "test/sub1" with group 1.' + ); + + $result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); + $this->assertNotEmpty($result); + $this->assertEquals(\OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_CREATE, $result['permissions']); + + $fileInfo = $view->getFileInfo('files/test/sub1/sub2'); + $fileId = $fileInfo->getId(); + + $this->assertTrue( + OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user4, \OCP\Constants::PERMISSION_READ), + 'Failed asserting that user 1 successfully shared "test/sub1/sub2" with user 4.' + ); + + $result = OCP\Share::getItemShared('folder', $fileId, Test_Share_Backend::FORMAT_SOURCE); + $this->assertNotEmpty($result); + $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']); + } + protected function shareUserOneTestFileWithGroupOne() { OC_User::setUserId($this->user1); $this->assertTrue( @@ -766,6 +798,7 @@ class Test_Share extends \Test\TestCase { /** * @param boolean|string $token + * @return array */ protected function getShareByValidToken($token) { $row = OCP\Share::getShareByToken($token); |