Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117915372
D4659.1775405961.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D4659.1775405961.diff
View Options
diff --git a/src/app/Backends/DAV.php b/src/app/Backends/DAV.php
--- a/src/app/Backends/DAV.php
+++ b/src/app/Backends/DAV.php
@@ -314,6 +314,45 @@
return $response !== false;
}
+ /**
+ * Initialize DAV folders (collections)
+ *
+ * @param \App\User $user User object
+ * @param array<array> $folders Folders list (path, displayname, type, components)
+ *
+ * @return bool True on success, False on error
+ */
+ public static function initDefaultFolders(\App\User $user, array $folders)
+ {
+ // FIXME: It looks like we'll need a way to authenticate the user, or cyrus admin
+ $dav = new self($email, $password);
+
+ foreach ($folders as $props) {
+ $folder = new DAV\Folder();
+ $folder->href = "addressbooks/user/{$user->email}/{$props['path']}";
+ $folder->name = $props['displayname'] ?? '';
+ $folder->types = ['collection', $props['type']];
+ $folder->components = $props['components'] ?? [];
+
+ // folder already exists? check the properties and update if needed
+ if ($existing = $dav->folderInfo($folder->href)) {
+ if ($existing->name != $folder->name || $existing->components != $folder->components) {
+ if (!$dav->folderUpdate($folder)) {
+ \Log::error("Failed to update DAV folder {$folder->href}");
+ return false;
+ }
+ }
+ }
+
+ if (!$dav->folderCreate($folder)) {
+ \Log::error("Failed to create DAV folder {$folder->href}");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Search DAV objects in a folder.
*
diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php
--- a/src/app/Jobs/User/CreateJob.php
+++ b/src/app/Jobs/User/CreateJob.php
@@ -106,6 +106,13 @@
$user->status |= \App\User::STATUS_IMAP_READY;
}
+ $folders = \config('services.dav.default_folders');
+ if (count($folders)) {
+ if (!\App\Backends\DAV::initDefaultFolders($user, $folders)) {
+ throw new \Exception("Failed to initialize DAV folders for user {$this->userId}.");
+ }
+ }
+
// Make user active in non-mandate mode only
if (
!($wallet = $user->wallet())
diff --git a/src/config/services.php b/src/config/services.php
--- a/src/config/services.php
+++ b/src/config/services.php
@@ -1,5 +1,32 @@
<?php
+$dav_folders = [];
+if (env('DAV_WITH_DEFAULT_FOLDERS', false)) {
+ $dav_folders = [
+ [
+ // FIXME: Should we use something else than 'Default'? This is
+ // what Cyrus creates, and I didn't find a setting to change it,
+ // we can only disable creation of the folder.
+ 'path' => 'Default',
+ 'displayname' => 'Calendar',
+ 'components' => ['VEVENT'],
+ 'type' => 'calendar',
+ ],
+ [
+ 'path' => 'Tasks',
+ 'displayname' => 'Tasks',
+ 'components' => ['VTODO'],
+ 'type' => 'calendar',
+ ],
+ [
+ // FIXME: Same here, should we use 'Contacts'?
+ 'path' => 'Default',
+ 'displayname' => 'Contacts',
+ 'type' => 'addressbook',
+ ],
+ ];
+}
+
return [
/*
@@ -58,6 +85,7 @@
'dav' => [
'uri' => env('DAV_URI', 'https://proxy/'),
+ 'default_folders' => $dav_folders,
],
'activesync' => [
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 4:19 PM (13 h, 23 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18833887
Default Alt Text
D4659.1775405961.diff (3 KB)
Attached To
Mode
D4659: Init default DAV folders
Attached
Detach File
Event Timeline