aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php31
-rw-r--r--apps/dav/lib/CalDAV/Calendar.php9
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesPlugin.php21
-rw-r--r--apps/dav/lib/Connector/Sabre/ServerFactory.php2
-rw-r--r--apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php2
-rw-r--r--apps/dav/lib/Server.php2
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php121
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php3
8 files changed, 173 insertions, 18 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 81e999cc356..2ef57ca77bb 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -1429,37 +1429,40 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/**
* Moves a calendar object from calendar to calendar.
*
- * @param int $sourceCalendarId
+ * @param string $sourcePrincipalUri
+ * @param int $sourceObjectId
+ * @param string $targetPrincipalUri
* @param int $targetCalendarId
- * @param int $objectId
- * @param string $oldPrincipalUri
- * @param string $newPrincipalUri
+ * @param string $tragetObjectUri
* @param int $calendarType
* @return bool
* @throws Exception
*/
- public function moveCalendarObject(int $sourceCalendarId, int $targetCalendarId, int $objectId, string $oldPrincipalUri, string $newPrincipalUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
+ public function moveCalendarObject(string $sourcePrincipalUri, int $sourceObjectId, string $targetPrincipalUri, int $targetCalendarId, string $tragetObjectUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
$this->cachedObjects = [];
- return $this->atomic(function () use ($sourceCalendarId, $targetCalendarId, $objectId, $oldPrincipalUri, $newPrincipalUri, $calendarType) {
- $object = $this->getCalendarObjectById($oldPrincipalUri, $objectId);
+ return $this->atomic(function () use ($sourcePrincipalUri, $sourceObjectId, $targetPrincipalUri, $targetCalendarId, $tragetObjectUri, $calendarType) {
+ $object = $this->getCalendarObjectById($sourcePrincipalUri, $sourceObjectId);
if (empty($object)) {
return false;
}
+ $sourceCalendarId = $object['calendarid'];
+ $sourceObjectUri = $object['uri'];
+
$query = $this->db->getQueryBuilder();
$query->update('calendarobjects')
->set('calendarid', $query->createNamedParameter($targetCalendarId, IQueryBuilder::PARAM_INT))
- ->where($query->expr()->eq('id', $query->createNamedParameter($objectId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
- ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
+ ->set('uri', $query->createNamedParameter($tragetObjectUri, IQueryBuilder::PARAM_STR))
+ ->where($query->expr()->eq('id', $query->createNamedParameter($sourceObjectId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->executeStatement();
- $this->purgeProperties($sourceCalendarId, $objectId);
- $this->updateProperties($targetCalendarId, $object['uri'], $object['calendardata'], $calendarType);
+ $this->purgeProperties($sourceCalendarId, $sourceObjectId);
+ $this->updateProperties($targetCalendarId, $tragetObjectUri, $object['calendardata'], $calendarType);
- $this->addChanges($sourceCalendarId, [$object['uri']], 3, $calendarType);
- $this->addChanges($targetCalendarId, [$object['uri']], 1, $calendarType);
+ $this->addChanges($sourceCalendarId, [$sourceObjectUri], 3, $calendarType);
+ $this->addChanges($targetCalendarId, [$tragetObjectUri], 1, $calendarType);
- $object = $this->getCalendarObjectById($newPrincipalUri, $objectId);
+ $object = $this->getCalendarObjectById($targetPrincipalUri, $sourceObjectId);
// Calendar Object wasn't found - possibly because it was deleted in the meantime by a different client
if (empty($object)) {
return false;
diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php
index 6fd7d147131..789fe4b55c0 100644
--- a/apps/dav/lib/CalDAV/Calendar.php
+++ b/apps/dav/lib/CalDAV/Calendar.php
@@ -391,9 +391,14 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
if (!($sourceNode instanceof CalendarObject)) {
return false;
}
-
try {
- return $this->caldavBackend->moveCalendarObject($sourceNode->getCalendarId(), (int)$this->calendarInfo['id'], $sourceNode->getId(), $sourceNode->getOwner(), $this->getOwner());
+ return $this->caldavBackend->moveCalendarObject(
+ $sourceNode->getOwner(),
+ $sourceNode->getId(),
+ $this->getOwner(),
+ $this->getResourceId(),
+ $targetName,
+ );
} catch (Exception $e) {
$this->logger->error('Could not move calendar object: ' . $e->getMessage(), ['exception' => $e]);
return false;
diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php
index 34f48384e12..b886534f9de 100644
--- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php
@@ -11,6 +11,7 @@ use OC\AppFramework\Http\Request;
use OC\FilesMetadata\Model\FilesMetadata;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\Files_Sharing\External\Mount as SharingExternalMount;
+use OCP\Accounts\IAccountManager;
use OCP\Constants;
use OCP\Files\ForbiddenException;
use OCP\Files\IFilenameValidator;
@@ -91,6 +92,7 @@ class FilesPlugin extends ServerPlugin {
private IPreview $previewManager,
private IUserSession $userSession,
private IFilenameValidator $validator,
+ private IAccountManager $accountManager,
private bool $isPublic = false,
private bool $downloadAttachment = true,
) {
@@ -361,9 +363,26 @@ class FilesPlugin extends ServerPlugin {
$owner = $node->getOwner();
if (!$owner) {
return null;
- } else {
+ }
+
+ // Get current user to see if we're in a public share or not
+ $user = $this->userSession->getUser();
+
+ // If the user is logged in, we can return the display name
+ if ($user !== null) {
return $owner->getDisplayName();
}
+
+ // Check if the user published their display name
+ $ownerAccount = $this->accountManager->getAccount($owner);
+ $ownerNameProperty = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
+
+ // Since we are not logged in, we need to have at least the published scope
+ if ($ownerNameProperty->getScope() === IAccountManager::SCOPE_PUBLISHED) {
+ return $owner->getDisplayName();
+ }
+
+ return null;
});
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php
index f035ff8d625..55cbb416457 100644
--- a/apps/dav/lib/Connector/Sabre/ServerFactory.php
+++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php
@@ -14,6 +14,7 @@ use OCA\DAV\DAV\CustomPropertiesBackend;
use OCA\DAV\DAV\ViewOnlyPlugin;
use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCA\Theming\ThemingDefaults;
+use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
@@ -128,6 +129,7 @@ class ServerFactory {
$this->previewManager,
$this->userSession,
\OCP\Server::get(IFilenameValidator::class),
+ \OCP\Server::get(IAccountManager::class),
false,
!$this->config->getSystemValue('debug', false)
)
diff --git a/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php b/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php
index ead2645779b..601103f7a24 100644
--- a/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php
+++ b/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php
@@ -77,7 +77,7 @@ class RemoveOrphanEventsAndContacts implements IRepairStep {
$qb->delete($childTable)
->where($qb->expr()->in('id', $qb->createParameter('ids')));
- $orphanItemsBatch = array_chunk($orphanItems, 200);
+ $orphanItemsBatch = array_chunk($orphanItems, 1000);
foreach ($orphanItemsBatch as $items) {
$qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
$qb->executeStatement();
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 9ea18c029c8..f1595bab391 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -64,6 +64,7 @@ use OCA\DAV\SystemTag\SystemTagPlugin;
use OCA\DAV\Upload\ChunkingPlugin;
use OCA\DAV\Upload\ChunkingV2Plugin;
use OCA\Theming\ThemingDefaults;
+use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -287,6 +288,7 @@ class Server {
\OCP\Server::get(IPreview::class),
\OCP\Server::get(IUserSession::class),
\OCP\Server::get(IFilenameValidator::class),
+ \OCP\Server::get(IAccountManager::class),
false,
$config->getSystemValueBool('debug', false) === false,
)
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index db07165ebf0..1352229b1f5 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -7,12 +7,15 @@
*/
namespace OCA\DAV\Tests\unit\Connector\Sabre;
+use OC\Accounts\Account;
+use OC\Accounts\AccountProperty;
use OC\User\User;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\DAV\Connector\Sabre\File;
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCA\DAV\Connector\Sabre\Node;
+use OCP\Accounts\IAccountManager;
use OCP\Files\FileInfo;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidPathException;
@@ -43,6 +46,7 @@ class FilesPluginTest extends TestCase {
private IPreview&MockObject $previewManager;
private IUserSession&MockObject $userSession;
private IFilenameValidator&MockObject $filenameValidator;
+ private IAccountManager&MockObject $accountManager;
private FilesPlugin $plugin;
protected function setUp(): void {
@@ -57,6 +61,7 @@ class FilesPluginTest extends TestCase {
$this->previewManager = $this->createMock(IPreview::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->filenameValidator = $this->createMock(IFilenameValidator::class);
+ $this->accountManager = $this->createMock(IAccountManager::class);
$this->plugin = new FilesPlugin(
$this->tree,
@@ -65,6 +70,7 @@ class FilesPluginTest extends TestCase {
$this->previewManager,
$this->userSession,
$this->filenameValidator,
+ $this->accountManager,
);
$response = $this->getMockBuilder(ResponseInterface::class)
@@ -154,6 +160,13 @@ class FilesPluginTest extends TestCase {
->method('getDisplayName')
->willReturn('M. Foo');
+ $owner = $this->getMockBuilder(Account::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($owner);
+
$node->expects($this->once())
->method('getDirectDownload')
->willReturn(['url' => 'http://example.com/']);
@@ -161,6 +174,18 @@ class FilesPluginTest extends TestCase {
->method('getOwner')
->willReturn($user);
+ $displayNameProp = $this->getMockBuilder(AccountProperty::class)
+ ->disableOriginalConstructor()->getMock();
+ $owner
+ ->expects($this->once())
+ ->method('getProperty')
+ ->with(IAccountManager::PROPERTY_DISPLAYNAME)
+ ->willReturn($displayNameProp);
+ $displayNameProp
+ ->expects($this->once())
+ ->method('getScope')
+ ->willReturn(IAccountManager::SCOPE_PUBLISHED);
+
$this->plugin->handleGetProperties(
$propFind,
$node
@@ -179,6 +204,101 @@ class FilesPluginTest extends TestCase {
$this->assertEquals([], $propFind->get404Properties());
}
+ public function testGetDisplayNamePropertyWhenNotPublished(): void {
+ /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+
+ $propFind = new PropFind(
+ '/dummyPath',
+ [
+ FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn(null);
+
+ $user = $this->getMockBuilder(User::class)
+ ->disableOriginalConstructor()->getMock();
+
+ $user
+ ->expects($this->never())
+ ->method('getDisplayName');
+
+ $owner = $this->getMockBuilder(Account::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->accountManager->expects($this->once())
+ ->method('getAccount')
+ ->with($user)
+ ->willReturn($owner);
+
+ $node->expects($this->once())
+ ->method('getOwner')
+ ->willReturn($user);
+
+ $displayNameProp = $this->getMockBuilder(AccountProperty::class)
+ ->disableOriginalConstructor()->getMock();
+ $owner
+ ->expects($this->once())
+ ->method('getProperty')
+ ->with(IAccountManager::PROPERTY_DISPLAYNAME)
+ ->willReturn($displayNameProp);
+ $displayNameProp
+ ->expects($this->once())
+ ->method('getScope')
+ ->willReturn(IAccountManager::SCOPE_PRIVATE);
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals(null, $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
+ }
+
+ public function testGetDisplayNamePropertyWhenNotPublishedButLoggedIn(): void {
+ /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+
+ $propFind = new PropFind(
+ '/dummyPath',
+ [
+ FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $user = $this->getMockBuilder(User::class)
+ ->disableOriginalConstructor()->getMock();
+
+ $node->expects($this->once())
+ ->method('getOwner')
+ ->willReturn($user);
+
+ $loggedInUser = $this->getMockBuilder(User::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+
+ $user
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('M. Foo');
+
+ $this->accountManager->expects($this->never())
+ ->method('getAccount');
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('M. Foo', $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
+ }
+
public function testGetPropertiesStorageNotAvailable(): void {
/** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
@@ -215,6 +335,7 @@ class FilesPluginTest extends TestCase {
$this->previewManager,
$this->userSession,
$this->filenameValidator,
+ $this->accountManager,
true,
);
$this->plugin->initialize($this->server);
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
index 8b169dcd46f..6a9372ca3fd 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
@@ -11,6 +11,7 @@ use OC\Files\View;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCA\DAV\Connector\Sabre\FilesReportPlugin as FilesReportPluginImplementation;
+use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\Files\File;
use OCP\Files\FileInfo;
@@ -389,6 +390,7 @@ class FilesReportPluginTest extends \Test\TestCase {
->getMock();
$validator = $this->createMock(IFilenameValidator::class);
+ $accountManager = $this->createMock(IAccountManager::class);
$this->server->addPlugin(
new FilesPlugin(
@@ -398,6 +400,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->previewManager,
$this->createMock(IUserSession::class),
$validator,
+ $accountManager,
)
);
$this->plugin->initialize($this->server);