aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/l10n/de.js4
-rw-r--r--apps/dav/l10n/de.json4
-rw-r--r--apps/dav/l10n/de_DE.js4
-rw-r--r--apps/dav/l10n/de_DE.json4
-rw-r--r--apps/dav/l10n/fr.js7
-rw-r--r--apps/dav/l10n/fr.json7
-rw-r--r--apps/dav/l10n/tr.js13
-rw-r--r--apps/dav/l10n/tr.json13
-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/Files/FileSearchBackend.php8
-rw-r--r--apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php2
-rw-r--r--apps/dav/lib/Server.php2
-rw-r--r--apps/dav/lib/Service/DefaultContactService.php7
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php121
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php3
-rw-r--r--apps/dav/tests/unit/Service/DefaultContactServiceTest.php21
19 files changed, 254 insertions, 29 deletions
diff --git a/apps/dav/l10n/de.js b/apps/dav/l10n/de.js
index c87fdbe6639..e22163e7731 100644
--- a/apps/dav/l10n/de.js
+++ b/apps/dav/l10n/de.js
@@ -278,9 +278,9 @@ OC.L10N.register(
"Long absence Message" : "Lange Abwesenheits Meldung",
"Save" : "Speichern",
"Disable absence" : "Abwesenheitmeldungen deaktivieren",
- "Failed to load availability" : "Fehler beim Laden der Verfügbarkeit",
+ "Failed to load availability" : "Verfügbarkeit konnte nicht geladen werden",
"Saved availability" : "Verfügbarkeit gespeichert",
- "Failed to save availability" : "Fehler beim Speichern der Verfügbarkeit",
+ "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden",
"Time zone:" : "Zeitzone:",
"to" : "an",
"Delete slot" : "Slot löschen",
diff --git a/apps/dav/l10n/de.json b/apps/dav/l10n/de.json
index 36562db38a9..02a0a5707ab 100644
--- a/apps/dav/l10n/de.json
+++ b/apps/dav/l10n/de.json
@@ -276,9 +276,9 @@
"Long absence Message" : "Lange Abwesenheits Meldung",
"Save" : "Speichern",
"Disable absence" : "Abwesenheitmeldungen deaktivieren",
- "Failed to load availability" : "Fehler beim Laden der Verfügbarkeit",
+ "Failed to load availability" : "Verfügbarkeit konnte nicht geladen werden",
"Saved availability" : "Verfügbarkeit gespeichert",
- "Failed to save availability" : "Fehler beim Speichern der Verfügbarkeit",
+ "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden",
"Time zone:" : "Zeitzone:",
"to" : "an",
"Delete slot" : "Slot löschen",
diff --git a/apps/dav/l10n/de_DE.js b/apps/dav/l10n/de_DE.js
index 9f79fbe5113..f513d35cdc9 100644
--- a/apps/dav/l10n/de_DE.js
+++ b/apps/dav/l10n/de_DE.js
@@ -278,9 +278,9 @@ OC.L10N.register(
"Long absence Message" : "Lange Abwesenheitsnachricht",
"Save" : "Speichern",
"Disable absence" : "Abwesenheit deaktivieren",
- "Failed to load availability" : "Laden der Verfügbarkeit fehlgeschlagen",
+ "Failed to load availability" : "Verfügbarkeit konnte nicht geladen werden",
"Saved availability" : "Verfügbarkeit gespeichert",
- "Failed to save availability" : "Fehler beim Speichern der Verfügbarkeit",
+ "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden",
"Time zone:" : "Zeitzone:",
"to" : "an",
"Delete slot" : "Zeitfenster löschen",
diff --git a/apps/dav/l10n/de_DE.json b/apps/dav/l10n/de_DE.json
index 554260858a6..e27822fbaa6 100644
--- a/apps/dav/l10n/de_DE.json
+++ b/apps/dav/l10n/de_DE.json
@@ -276,9 +276,9 @@
"Long absence Message" : "Lange Abwesenheitsnachricht",
"Save" : "Speichern",
"Disable absence" : "Abwesenheit deaktivieren",
- "Failed to load availability" : "Laden der Verfügbarkeit fehlgeschlagen",
+ "Failed to load availability" : "Verfügbarkeit konnte nicht geladen werden",
"Saved availability" : "Verfügbarkeit gespeichert",
- "Failed to save availability" : "Fehler beim Speichern der Verfügbarkeit",
+ "Failed to save availability" : "Verfügbarkeit konnte nicht gespeichert werden",
"Time zone:" : "Zeitzone:",
"to" : "an",
"Delete slot" : "Zeitfenster löschen",
diff --git a/apps/dav/l10n/fr.js b/apps/dav/l10n/fr.js
index 915f8543589..736d0c450c2 100644
--- a/apps/dav/l10n/fr.js
+++ b/apps/dav/l10n/fr.js
@@ -275,6 +275,13 @@ OC.L10N.register(
"Cancel" : "Annuler",
"Import" : "Importation",
"Error while saving settings" : "Erreur lors de l'enregistrement des paramètres",
+ "Contact reset successfully" : "Contact réinitialisé avec succès",
+ "Error while resetting contact" : "Erreur lors de la remise à zéro du contact",
+ "Contact imported successfully" : "Contact importé avec succès",
+ "Error while importing contact" : "Erreur lors de l'importation du contact",
+ "Import contact" : "Importer un contact",
+ "Import contacts" : "Importer des contacts",
+ "Importing a new .vcf file will delete the existing default contact and replace it with the new one. Do you want to continue?" : "Importer un nouveau fichier .vcf supprimera le contact par défaut existant et le remplacera. Voulez-vous continuer ?",
"There was an error updating your attendance status." : "Une erreur s'est produite lors de la mise à jour de votre statut de présence.",
"Please contact the organizer directly." : "Merci de contacter l'organisateur directement.",
"Are you accepting the invitation?" : "Acceptez-vous l'invitation ?",
diff --git a/apps/dav/l10n/fr.json b/apps/dav/l10n/fr.json
index 7c204187201..8f64a867349 100644
--- a/apps/dav/l10n/fr.json
+++ b/apps/dav/l10n/fr.json
@@ -273,6 +273,13 @@
"Cancel" : "Annuler",
"Import" : "Importation",
"Error while saving settings" : "Erreur lors de l'enregistrement des paramètres",
+ "Contact reset successfully" : "Contact réinitialisé avec succès",
+ "Error while resetting contact" : "Erreur lors de la remise à zéro du contact",
+ "Contact imported successfully" : "Contact importé avec succès",
+ "Error while importing contact" : "Erreur lors de l'importation du contact",
+ "Import contact" : "Importer un contact",
+ "Import contacts" : "Importer des contacts",
+ "Importing a new .vcf file will delete the existing default contact and replace it with the new one. Do you want to continue?" : "Importer un nouveau fichier .vcf supprimera le contact par défaut existant et le remplacera. Voulez-vous continuer ?",
"There was an error updating your attendance status." : "Une erreur s'est produite lors de la mise à jour de votre statut de présence.",
"Please contact the organizer directly." : "Merci de contacter l'organisateur directement.",
"Are you accepting the invitation?" : "Acceptez-vous l'invitation ?",
diff --git a/apps/dav/l10n/tr.js b/apps/dav/l10n/tr.js
index 0795419cb6c..f98655d1efb 100644
--- a/apps/dav/l10n/tr.js
+++ b/apps/dav/l10n/tr.js
@@ -250,6 +250,9 @@ OC.L10N.register(
"Completed on %s" : "%s tarihinde tamamlandı",
"Due on %s by %s" : "%s tarihine kadar %s tarafından",
"Due on %s" : "%s tarihine kadar",
+ "System Address Book" : "Sistem adres defteri",
+ "The system address book contains contact information for all users in your instance." : "Sistem adres defterinde, kopyanızdaki tüm kullanıcıların iletişim bilgileri bulunur.",
+ "Enable System Address Book" : "Sistem adres defteri kullanılsın",
"DAV system address book" : "DAV sistem adres defteri",
"No outstanding DAV system address book sync." : "Bekleyen bir DAV sistemi adres defteri eşitlemesi yok.",
"The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occurred. Please run it manually by calling \"occ dav:sync-system-addressbook\"." : "Kopyanızda 1000 üzerinde kullanıcı olduğundan ya da bir sorun çıktığından DAV sistemi adres defteri eşitlemesi henüz yapılmamış. Lütfen \"occ dav:sync-system-addressbook\" komutunu yürüterek el ile eşitleyin.",
@@ -306,6 +309,16 @@ OC.L10N.register(
"Cancel" : "İptal",
"Import" : "İçe aktar",
"Error while saving settings" : "Ayarlar kaydedilirken sorun çıktı",
+ "Contact reset successfully" : "Kişi sıfırlandı",
+ "Error while resetting contact" : "Kişi sıfırlanırken sorun çıktı",
+ "Contact imported successfully" : "Kişi içe aktarıldı",
+ "Error while importing contact" : "Kişi içe aktarılırken sorun çıktı",
+ "Example Content" : "Örnek içerik",
+ "Set example content to be created on new user first login." : "Yeni kullanıcının ilk oturum açmasında oluşturulacak örnek içeriği ayarlayın.",
+ "Import contact" : "Kişiyi içe aktar",
+ "Reset to default contact" : "Varsayılan kişiye sıfırla",
+ "Import contacts" : "Kişileri içe aktar",
+ "Importing a new .vcf file will delete the existing default contact and replace it with the new one. Do you want to continue?" : "Yeni bir .vcf dosyasını içe aktarmak, var olan varsayılan kişiyi siler ve yenisiyle değiştirir. İlerlemek istiyor musunuz?",
"There was an error updating your attendance status." : "Katılım durumunuz güncellenirken bir sorun çıktı.",
"Please contact the organizer directly." : "Lütfen düzenleyici ile doğrudan görüşün.",
"Are you accepting the invitation?" : "Daveti kabul ediyor musunuz?",
diff --git a/apps/dav/l10n/tr.json b/apps/dav/l10n/tr.json
index d20e1e8dcdf..949b17d2278 100644
--- a/apps/dav/l10n/tr.json
+++ b/apps/dav/l10n/tr.json
@@ -248,6 +248,9 @@
"Completed on %s" : "%s tarihinde tamamlandı",
"Due on %s by %s" : "%s tarihine kadar %s tarafından",
"Due on %s" : "%s tarihine kadar",
+ "System Address Book" : "Sistem adres defteri",
+ "The system address book contains contact information for all users in your instance." : "Sistem adres defterinde, kopyanızdaki tüm kullanıcıların iletişim bilgileri bulunur.",
+ "Enable System Address Book" : "Sistem adres defteri kullanılsın",
"DAV system address book" : "DAV sistem adres defteri",
"No outstanding DAV system address book sync." : "Bekleyen bir DAV sistemi adres defteri eşitlemesi yok.",
"The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occurred. Please run it manually by calling \"occ dav:sync-system-addressbook\"." : "Kopyanızda 1000 üzerinde kullanıcı olduğundan ya da bir sorun çıktığından DAV sistemi adres defteri eşitlemesi henüz yapılmamış. Lütfen \"occ dav:sync-system-addressbook\" komutunu yürüterek el ile eşitleyin.",
@@ -304,6 +307,16 @@
"Cancel" : "İptal",
"Import" : "İçe aktar",
"Error while saving settings" : "Ayarlar kaydedilirken sorun çıktı",
+ "Contact reset successfully" : "Kişi sıfırlandı",
+ "Error while resetting contact" : "Kişi sıfırlanırken sorun çıktı",
+ "Contact imported successfully" : "Kişi içe aktarıldı",
+ "Error while importing contact" : "Kişi içe aktarılırken sorun çıktı",
+ "Example Content" : "Örnek içerik",
+ "Set example content to be created on new user first login." : "Yeni kullanıcının ilk oturum açmasında oluşturulacak örnek içeriği ayarlayın.",
+ "Import contact" : "Kişiyi içe aktar",
+ "Reset to default contact" : "Varsayılan kişiye sıfırla",
+ "Import contacts" : "Kişileri içe aktar",
+ "Importing a new .vcf file will delete the existing default contact and replace it with the new one. Do you want to continue?" : "Yeni bir .vcf dosyasını içe aktarmak, var olan varsayılan kişiyi siler ve yenisiyle değiştirir. İlerlemek istiyor musunuz?",
"There was an error updating your attendance status." : "Katılım durumunuz güncellenirken bir sorun çıktı.",
"Please contact the organizer directly." : "Lütfen düzenleyici ile doğrudan görüşün.",
"Are you accepting the invitation?" : "Daveti kabul ediyor musunuz?",
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/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index 1b785962112..ace367e4490 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -422,10 +422,16 @@ class FileSearchBackend implements ISearchBackend {
$field = $this->mapPropertyNameToColumn($property);
}
+ try {
+ $castedValue = $this->castValue($property, $value ?? '');
+ } catch (\Error $e) {
+ throw new \InvalidArgumentException('Invalid property value for ' . $property->name, previous: $e);
+ }
+
return new SearchComparison(
$trimmedType,
$field,
- $this->castValue($property, $value ?? ''),
+ $castedValue,
$extra ?? ''
);
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/lib/Service/DefaultContactService.php b/apps/dav/lib/Service/DefaultContactService.php
index 193f3b285c6..ad7a1179195 100644
--- a/apps/dav/lib/Service/DefaultContactService.php
+++ b/apps/dav/lib/Service/DefaultContactService.php
@@ -9,9 +9,11 @@ declare(strict_types=1);
namespace OCA\DAV\Service;
+use OCA\DAV\AppInfo\Application;
use OCA\DAV\CardDAV\CardDavBackend;
use OCP\App\IAppManager;
use OCP\Files\AppData\IAppDataFactory;
+use OCP\IAppConfig;
use Psr\Log\LoggerInterface;
use Symfony\Component\Uid\Uuid;
@@ -20,11 +22,16 @@ class DefaultContactService {
private CardDavBackend $cardDav,
private IAppManager $appManager,
private IAppDataFactory $appDataFactory,
+ private IAppConfig $config,
private LoggerInterface $logger,
) {
}
public function createDefaultContact(int $addressBookId): void {
+ $enableDefaultContact = $this->config->getValueString(Application::APP_ID, 'enableDefaultContact', 'no');
+ if ($enableDefaultContact !== 'yes') {
+ return;
+ }
$appData = $this->appDataFactory->get('dav');
try {
$folder = $appData->getFolder('defaultContact');
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);
diff --git a/apps/dav/tests/unit/Service/DefaultContactServiceTest.php b/apps/dav/tests/unit/Service/DefaultContactServiceTest.php
index 9540e77ce6c..68bbc02ed08 100644
--- a/apps/dav/tests/unit/Service/DefaultContactServiceTest.php
+++ b/apps/dav/tests/unit/Service/DefaultContactServiceTest.php
@@ -17,6 +17,7 @@ use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\Uid\Uuid;
@@ -28,6 +29,7 @@ class DefaultContactServiceTest extends TestCase {
private MockObject|IAppManager $appManager;
private MockObject|IAppDataFactory $appDataFactory;
private MockObject|LoggerInterface $logger;
+ private MockObject|IAppConfig $config;
protected function setUp(): void {
parent::setUp();
@@ -36,19 +38,21 @@ class DefaultContactServiceTest extends TestCase {
$this->appManager = $this->createMock(IAppManager::class);
$this->appDataFactory = $this->createMock(IAppDataFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->config = $this->createMock(IAppConfig::class);
$this->service = new DefaultContactService(
$this->cardDav,
$this->appManager,
$this->appDataFactory,
- $this->logger
+ $this->config,
+ $this->logger,
);
}
public function testCreateDefaultContactWithInvalidCard(): void {
// Invalid vCard missing required FN property
$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nEND:VCARD";
-
+ $this->config->method('getValueString')->willReturn('yes');
$appData = $this->createMock(IAppData::class);
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
@@ -72,6 +76,7 @@ class DefaultContactServiceTest extends TestCase {
$originalRev = '20200101T000000Z';
$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nUID:$originalUid\nREV:$originalRev\nEND:VCARD";
+ $this->config->method('getValueString')->willReturn('yes');
$appData = $this->createMock(IAppData::class);
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
@@ -103,6 +108,7 @@ class DefaultContactServiceTest extends TestCase {
public function testDefaultContactFileDoesNotExist(): void {
$appData = $this->createMock(IAppData::class);
+ $this->config->method('getValueString')->willReturn('yes');
$appData->method('getFolder')->willThrowException(new NotFoundException());
$this->appDataFactory->method('get')->willReturn($appData);
@@ -115,6 +121,7 @@ class DefaultContactServiceTest extends TestCase {
public function testUidAndRevAreAddedIfMissing(): void {
$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nEND:VCARD";
+ $this->config->method('getValueString')->willReturn('yes');
$appData = $this->createMock(IAppData::class);
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
@@ -145,4 +152,14 @@ class DefaultContactServiceTest extends TestCase {
$this->assertNotNull($vcard->UID);
$this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
}
+
+ public function testDefaultContactIsNotCreatedIfEnabled(): void {
+ $this->config->method('getValueString')->willReturn('no');
+ $this->logger->expects($this->never())
+ ->method('error');
+ $this->cardDav->expects($this->never())
+ ->method('createCard');
+
+ $this->service->createDefaultContact(123);
+ }
}