Skip to content

Commit 876eec2

Browse files
committed
fixup! feat: import contacts from files via ocs
1 parent 1a90a69 commit 876eec2

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace OCA\Contacts\AppInfo;
88

9+
use OCA\Contacts\Capabilities;
910
use OCA\Contacts\Dav\PatchPlugin;
1011
use OCA\Contacts\Event\LoadContactsOcaApiEvent;
1112
use OCA\Contacts\Listener\LoadContactsFilesActions;
@@ -30,6 +31,7 @@ public function __construct() {
3031
}
3132

3233
public function register(IRegistrationContext $context): void {
34+
$context->registerCapability(Capabilities::class);
3335
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
3436
$context->registerEventListener(LoadContactsOcaApiEvent::class, LoadContactsOcaApi::class);
3537
}

lib/Capabilities.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Contacts;
11+
12+
use OCA\Contacts\AppInfo\Application;
13+
use OCP\Capabilities\ICapability;
14+
use OCP\IL10N;
15+
use OCP\IURLGenerator;
16+
use OCP\L10N\IFactory as IL10NFactory;
17+
18+
class Capabilities implements ICapability {
19+
private readonly IL10N $l10n;
20+
21+
public function __construct(
22+
private readonly IURLGenerator $url,
23+
IL10NFactory $l10nFactory,
24+
) {
25+
$this->l10n = $l10nFactory->get(Application::APP_ID);
26+
}
27+
28+
public function getCapabilities(): array {
29+
//return [
30+
$caps = [
31+
'contacts' => [
32+
'context-menu' => [
33+
[
34+
'name' => $this->l10n->t('Import contacts'),
35+
'url' => $this->url->getWebroot() . '/ocs/v2.php/apps/contacts/api/v1/import/{fileId}',
36+
'method' => 'POST',
37+
'mimetype_filters' => 'text/vcard',
38+
],
39+
],
40+
],
41+
];
42+
return $caps;
43+
}
44+
}

lib/Controller/ImportController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public function __construct(
4040

4141
/**
4242
* Import the given vCard file (by id) into the given address book of the current user.
43-
* Exactly one of $addressBookKey or $addressBookUri is expected.
43+
* If no address book URI is posted as a payload, an attempt will be made to determine the
44+
* user's default address book.
4445
*
4546
* @param int $fileId The id of a vCard file to import
46-
* @param ?string $addressBookKey The key or id of the address book - {@see \OCP\IAddressBook::getKey}
47-
* @param ?string $addressBookUri The uri of the address book - {@see \OCP\IAddressBook::getUri}
47+
* @param ?string $addressBookUri Optional URI of the address book to import into - {@see \OCP\IAddressBook::getUri}
4848
* @return DataResponse A list of imported contact URIs, amount of skipped contacts and a list of errors.
4949
*
50-
* 200: Contacts were imported (check the response data for stats)
50+
* 200: Contacts were processed (check the response data for stats)
5151
* 400: Not a vCard file or given both $addressBookKey and $addressBookUri
5252
* 401: User is not logged in
5353
* 404: File or address book was not found
5454
*/
5555
#[NoAdminRequired]
56-
#[ApiRoute('POST', '/api/v1/import')]
56+
#[ApiRoute('POST', '/api/v1/import/{fileId}')]
5757
public function import(int $fileId, ?string $addressBookUri = null): DataResponse {
5858
if ($this->userId === null) {
5959
return new DataResponse('Not logged in', Http::STATUS_UNAUTHORIZED);

0 commit comments

Comments
 (0)