Skip to content

Commit 9e80cee

Browse files
feat: contacts import ocs
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 4fcbb98 commit 9e80cee

19 files changed

Lines changed: 1285 additions & 8 deletions

3rdparty

Submodule 3rdparty updated 299 files

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@
174174
'OCA\\DAV\\CardDAV\\Converter' => $baseDir . '/../lib/CardDAV/Converter.php',
175175
'OCA\\DAV\\CardDAV\\HasPhotoPlugin' => $baseDir . '/../lib/CardDAV/HasPhotoPlugin.php',
176176
'OCA\\DAV\\CardDAV\\ImageExportPlugin' => $baseDir . '/../lib/CardDAV/ImageExportPlugin.php',
177+
'OCA\\DAV\\CardDAV\\Import\\ImportCountEvent' => $baseDir . '/../lib/CardDAV/Import/ImportCountEvent.php',
178+
'OCA\\DAV\\CardDAV\\Import\\ImportDisposition' => $baseDir . '/../lib/CardDAV/Import/ImportDisposition.php',
179+
'OCA\\DAV\\CardDAV\\Import\\ImportEvent' => $baseDir . '/../lib/CardDAV/Import/ImportEvent.php',
180+
'OCA\\DAV\\CardDAV\\Import\\ImportObjectEvent' => $baseDir . '/../lib/CardDAV/Import/ImportObjectEvent.php',
181+
'OCA\\DAV\\CardDAV\\Import\\ImportService' => $baseDir . '/../lib/CardDAV/Import/ImportService.php',
182+
'OCA\\DAV\\CardDAV\\Import\\TextImporter' => $baseDir . '/../lib/CardDAV/Import/TextImporter.php',
177183
'OCA\\DAV\\CardDAV\\Integration\\ExternalAddressBook' => $baseDir . '/../lib/CardDAV/Integration/ExternalAddressBook.php',
178184
'OCA\\DAV\\CardDAV\\Integration\\IAddressBookProvider' => $baseDir . '/../lib/CardDAV/Integration/IAddressBookProvider.php',
179185
'OCA\\DAV\\CardDAV\\MultiGetExportPlugin' => $baseDir . '/../lib/CardDAV/MultiGetExportPlugin.php',
@@ -269,6 +275,7 @@
269275
'OCA\\DAV\\Controller\\BirthdayCalendarController' => $baseDir . '/../lib/Controller/BirthdayCalendarController.php',
270276
'OCA\\DAV\\Controller\\CalendarExportController' => $baseDir . '/../lib/Controller/CalendarExportController.php',
271277
'OCA\\DAV\\Controller\\CalendarImportController' => $baseDir . '/../lib/Controller/CalendarImportController.php',
278+
'OCA\\DAV\\Controller\\ContactsImportController' => $baseDir . '/../lib/Controller/ContactsImportController.php',
272279
'OCA\\DAV\\Controller\\DirectController' => $baseDir . '/../lib/Controller/DirectController.php',
273280
'OCA\\DAV\\Controller\\ExampleContentController' => $baseDir . '/../lib/Controller/ExampleContentController.php',
274281
'OCA\\DAV\\Controller\\FederatedCalendarController' => $baseDir . '/../lib/Controller/FederatedCalendarController.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ class ComposerStaticInitDAV
189189
'OCA\\DAV\\CardDAV\\Converter' => __DIR__ . '/..' . '/../lib/CardDAV/Converter.php',
190190
'OCA\\DAV\\CardDAV\\HasPhotoPlugin' => __DIR__ . '/..' . '/../lib/CardDAV/HasPhotoPlugin.php',
191191
'OCA\\DAV\\CardDAV\\ImageExportPlugin' => __DIR__ . '/..' . '/../lib/CardDAV/ImageExportPlugin.php',
192+
'OCA\\DAV\\CardDAV\\Import\\ImportCountEvent' => __DIR__ . '/..' . '/../lib/CardDAV/Import/ImportCountEvent.php',
193+
'OCA\\DAV\\CardDAV\\Import\\ImportDisposition' => __DIR__ . '/..' . '/../lib/CardDAV/Import/ImportDisposition.php',
194+
'OCA\\DAV\\CardDAV\\Import\\ImportEvent' => __DIR__ . '/..' . '/../lib/CardDAV/Import/ImportEvent.php',
195+
'OCA\\DAV\\CardDAV\\Import\\ImportObjectEvent' => __DIR__ . '/..' . '/../lib/CardDAV/Import/ImportObjectEvent.php',
196+
'OCA\\DAV\\CardDAV\\Import\\ImportService' => __DIR__ . '/..' . '/../lib/CardDAV/Import/ImportService.php',
197+
'OCA\\DAV\\CardDAV\\Import\\TextImporter' => __DIR__ . '/..' . '/../lib/CardDAV/Import/TextImporter.php',
192198
'OCA\\DAV\\CardDAV\\Integration\\ExternalAddressBook' => __DIR__ . '/..' . '/../lib/CardDAV/Integration/ExternalAddressBook.php',
193199
'OCA\\DAV\\CardDAV\\Integration\\IAddressBookProvider' => __DIR__ . '/..' . '/../lib/CardDAV/Integration/IAddressBookProvider.php',
194200
'OCA\\DAV\\CardDAV\\MultiGetExportPlugin' => __DIR__ . '/..' . '/../lib/CardDAV/MultiGetExportPlugin.php',
@@ -284,6 +290,7 @@ class ComposerStaticInitDAV
284290
'OCA\\DAV\\Controller\\BirthdayCalendarController' => __DIR__ . '/..' . '/../lib/Controller/BirthdayCalendarController.php',
285291
'OCA\\DAV\\Controller\\CalendarExportController' => __DIR__ . '/..' . '/../lib/Controller/CalendarExportController.php',
286292
'OCA\\DAV\\Controller\\CalendarImportController' => __DIR__ . '/..' . '/../lib/Controller/CalendarImportController.php',
293+
'OCA\\DAV\\Controller\\ContactsImportController' => __DIR__ . '/..' . '/../lib/Controller/ContactsImportController.php',
287294
'OCA\\DAV\\Controller\\DirectController' => __DIR__ . '/..' . '/../lib/Controller/DirectController.php',
288295
'OCA\\DAV\\Controller\\ExampleContentController' => __DIR__ . '/..' . '/../lib/Controller/ExampleContentController.php',
289296
'OCA\\DAV\\Controller\\FederatedCalendarController' => __DIR__ . '/..' . '/../lib/Controller/FederatedCalendarController.php',

apps/dav/lib/CardDAV/AddressBookImpl.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
use OCA\DAV\Db\PropertyMapper;
1212
use OCP\Constants;
1313
use OCP\IAddressBookEnabled;
14+
use OCP\IAddressBookWritable;
1415
use OCP\ICreateContactFromString;
1516
use OCP\IURLGenerator;
1617
use Sabre\VObject\Component\VCard;
1718
use Sabre\VObject\Property;
1819
use Sabre\VObject\Reader;
1920
use Sabre\VObject\UUIDUtil;
2021

21-
class AddressBookImpl implements IAddressBookEnabled, ICreateContactFromString {
22+
class AddressBookImpl implements ICreateContactFromString, IAddressBookEnabled, IAddressBookWritable {
2223

2324
/**
2425
* AddressBookImpl constructor.
@@ -57,6 +58,14 @@ public function getUri(): string {
5758
return $this->addressBookInfo['uri'];
5859
}
5960

61+
/**
62+
* @return string the principal URI of the address book owner
63+
* @since 35.0.0
64+
*/
65+
public function getPrincipalUri(): string {
66+
return $this->addressBookInfo['principaluri'];
67+
}
68+
6069
/**
6170
* In comparison to getKey() this function returns a human readable (maybe translated) name
6271
*
@@ -350,6 +359,18 @@ public function isEnabled(): bool {
350359
return true;
351360
}
352361

362+
public function isWritable(): bool {
363+
if (!$this->userId) {
364+
return true;
365+
}
366+
367+
if ($this->isSystemAddressBook()) {
368+
return false;
369+
}
370+
371+
return $this->getPermissions() & Constants::PERMISSION_UPDATE;
372+
}
373+
353374
#[\Override]
354375
public function createFromString(string $name, string $vcfData): void {
355376
$this->backend->createCard($this->getKey(), $name, $vcfData);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV\CardDAV\Import;
10+
11+
final readonly class ImportCountEvent implements ImportEvent {
12+
public function __construct(
13+
public int $vcard,
14+
) {
15+
}
16+
17+
public function total(): int {
18+
return $this->vcard;
19+
}
20+
21+
/**
22+
* @return array{type: 'count', vcard: int}
23+
*/
24+
#[\Override]
25+
public function jsonSerialize(): array {
26+
return [
27+
'type' => 'count',
28+
'vcard' => $this->total(),
29+
];
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV\CardDAV\Import;
10+
11+
enum ImportDisposition: string {
12+
case Created = 'created';
13+
case Updated = 'updated';
14+
case Exists = 'exists';
15+
case Error = 'error';
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV\CardDAV\Import;
10+
11+
use JsonSerializable;
12+
13+
interface ImportEvent extends JsonSerializable {
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\DAV\CardDAV\Import;
10+
11+
final readonly class ImportObjectEvent implements ImportEvent {
12+
/**
13+
* @param list<string> $errors
14+
*/
15+
public function __construct(
16+
public ?string $identifier,
17+
public ImportDisposition $disposition,
18+
public array $errors = [],
19+
) {
20+
}
21+
22+
public function isError(): bool {
23+
return $this->disposition === ImportDisposition::Error;
24+
}
25+
26+
/**
27+
* @return array{type: 'object', identifier: ?string, disposition: string, errors: list<string>}
28+
*/
29+
#[\Override]
30+
public function jsonSerialize(): array {
31+
$result = [
32+
'type' => 'object',
33+
'identifier' => $this->identifier,
34+
'disposition' => $this->disposition->value,
35+
'errors' => $this->errors,
36+
];
37+
38+
return $result;
39+
}
40+
}

0 commit comments

Comments
 (0)