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
5 changes: 1 addition & 4 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,7 @@ public function testUpdateShare() {

$this->assertNotNull($share1->getAttributes());
$share1 = $this->shareManager->createShare($share1);
$this->assertNull($share1->getAttributes());
$this->assertEquals(19, $share1->getPermissions());
// attributes get cleared when empty
$this->assertNull($share1->getAttributes());

$share2 = $this->shareManager->newShare();
$share2->setNode($node1)
Expand Down Expand Up @@ -1126,7 +1123,7 @@ public function testDeleteShare() {
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share1);
$share2 = $this->shareManager->createShare($share2);

$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($share1->getId());
Expand Down
54 changes: 22 additions & 32 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
use OC\Share20\Exception\BackendError;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -90,19 +90,19 @@ class DefaultShareProvider implements IShareProvider {
/** @var IURLGenerator */
private $urlGenerator;

/** @var IConfig */
private $config;
private ITimeFactory $timeFactory;

public function __construct(
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder,
IMailer $mailer,
Defaults $defaults,
IFactory $l10nFactory,
IURLGenerator $urlGenerator,
IConfig $config) {
IDBConnection $connection,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder,
IMailer $mailer,
Defaults $defaults,
IFactory $l10nFactory,
IURLGenerator $urlGenerator,
ITimeFactory $timeFactory,
) {
$this->dbConn = $connection;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
Expand All @@ -111,7 +111,7 @@ public function __construct(
$this->defaults = $defaults;
$this->l10nFactory = $l10nFactory;
$this->urlGenerator = $urlGenerator;
$this->config = $config;
$this->timeFactory = $timeFactory;
}

/**
Expand Down Expand Up @@ -216,32 +216,22 @@ public function create(\OCP\Share\IShare $share) {
}

// Set the time this share was created
$qb->setValue('stime', $qb->createNamedParameter(time()));
$shareTime = $this->timeFactory->now();
$qb->setValue('stime', $qb->createNamedParameter($shareTime->getTimestamp()));

// insert the data and fetch the id of the share
$this->dbConn->beginTransaction();
$qb->execute();
$id = $this->dbConn->lastInsertId('*PREFIX*share');

// Now fetch the inserted share and create a complete share object
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
$qb->executeStatement();

$cursor = $qb->execute();
$data = $cursor->fetch();
$this->dbConn->commit();
$cursor->closeCursor();
// Update mandatory data
$id = $qb->getLastInsertId();
$share->setId((string)$id);
$share->setProviderId($this->identifier());

if ($data === false) {
throw new ShareNotFound('Newly created share could not be found');
}
$share->setShareTime(\DateTime::createFromImmutable($shareTime));

$mailSendValue = $share->getMailSend();
$data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue;
$share->setMailSend(($mailSendValue === null) ? true : $mailSendValue);

$share = $this->createShare($data);
return $share;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
use OCA\Talk\Share\RoomShareProvider;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function defaultShareProvider() {
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getL10NFactory(),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->getConfig()
$this->serverContainer->query(ITimeFactory::class),
);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,6 @@ public function testMoveMountPointIntoSharedFolder() {
->setSharedBy($this->user)
->setShareType(IShare::TYPE_USER)
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setId(42)
->setProviderId('foo')
->setNode($shareDir);
$shareManager->createShare($share);

Expand Down
33 changes: 17 additions & 16 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

use OC\Share20\DefaultShareProvider;
use OC\Share20\ShareAttributes;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IGroupManager;
Expand Down Expand Up @@ -79,8 +79,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */
protected $urlGenerator;

/** @var IConfig|MockObject */
protected $config;
/** @var ITimeFactory|MockObject */
protected $timeFactory;

protected function setUp(): void {
$this->dbConn = \OC::$server->getDatabaseConnection();
Expand All @@ -92,9 +92,10 @@ protected function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);

$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable("2023-05-04 00:00 Europe/Berlin"));

//Empty share table
$this->dbConn->getQueryBuilder()->delete('share')->execute();
Expand All @@ -108,7 +109,7 @@ protected function setUp(): void {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
);
}

Expand Down Expand Up @@ -469,7 +470,7 @@ public function testDeleteSingleShare() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -564,7 +565,7 @@ public function testDeleteGroupShareWithUserGroupShares() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
])
->setMethods(['getShareById'])
->getMock();
Expand Down Expand Up @@ -724,11 +725,11 @@ public function testCreateUserShare() {
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());

// nothing from setSharedWithDisplayName/setSharedWithAvatar is saved in DB
// Data is kept after creation
$this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
$this->assertSame(null, $share2->getSharedWithDisplayName());
$this->assertSame(null, $share2->getSharedWithAvatar());
$this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());

$this->assertSame(
[
Expand Down Expand Up @@ -794,11 +795,11 @@ public function testCreateGroupShare() {
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());

// nothing from setSharedWithDisplayName/setSharedWithAvatar is saved in DB
// Data is kept after creation
$this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
$this->assertSame(null, $share2->getSharedWithDisplayName());
$this->assertSame(null, $share2->getSharedWithAvatar());
$this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
$this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());

$this->assertSame(
[
Expand Down Expand Up @@ -2524,7 +2525,7 @@ public function testGetSharesInFolder() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
);

$password = md5(time());
Expand Down Expand Up @@ -2622,7 +2623,7 @@ public function testGetAccessListNoCurrentAccessRequired() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down Expand Up @@ -2718,7 +2719,7 @@ public function testGetAccessListCurrentAccessRequired() {
$this->defaults,
$this->l10nFactory,
$this->urlGenerator,
$this->config
$this->timeFactory
);

$u1 = $userManager->createUser('testShare1', 'test');
Expand Down