Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>integration_davc</id>
<name>DAV Connector</name>
<summary>Connect Nextcloud to a DAV service</summary>
<description><![CDATA[DAV Connector allows you connect any compatible DAV service to Nextcloud]]></description>
<version>0.1.0-dev</version>
<licence>agpl</licence>
<licence>AGPL-3.0-or-later</licence>
<author mail="krupinski01@gmail.com">Sebastian Krupinski</author>
<namespace>DAVC</namespace>
<types>
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default [
files: ['**/*.js', '**/*.vue', '**/*.ts'],
rules: {
// Relax some rules for now. Can be improved later on (baseline).
'no-console': 'off',
'no-console': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'vue/multi-word-component-names': 'off',
'jsdoc/require-jsdoc': 'off',
Expand Down
7 changes: 2 additions & 5 deletions lib/Controller/AdminConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

class AdminConfigurationController extends Controller {

/**
* @var ConfigurationService
*/
private $ConfigurationService;
private ConfigurationService $ConfigurationService;

public function __construct($appName, IRequest $request, ConfigurationService $ConfigurationService) {
public function __construct(string $appName, IRequest $request, ConfigurationService $ConfigurationService) {

parent::__construct($appName, $request);

Expand Down
11 changes: 7 additions & 4 deletions lib/Controller/UserConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
private CoreService $CoreService,
private HarmonizationService $HarmonizationService,
private ServicesService $ServicesService,
private string $userId,
private ?string $userId,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -74,8 +74,11 @@ public function Connect(array $service): DataResponse {
}
// execute command
try {
$rs = $this->CoreService->connectAccount($this->userId, $service);
return new DataResponse('success');
$entity = $this->CoreService->connectAccount($this->userId, $service);
if ($entity === null) {
return new DataResponse('Failed to connect account', Http::STATUS_BAD_REQUEST);
}
return new DataResponse($entity);
} catch (\Throwable $th) {
return new DataResponse($th->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR);
}
Expand Down Expand Up @@ -198,7 +201,7 @@ public function localCollectionsDeposit(int $sid, array $ContactCorrelations, ar
}
// execute command
try {
$rs = $this->CoreService->localCollectionsDeposit($this->userId, $sid, $ContactCorrelations, $EventCorrelations);
$this->CoreService->localCollectionsDeposit($this->userId, $sid, $ContactCorrelations, $EventCorrelations);
return $this->localCollectionsFetch($sid);
} catch (\Throwable $th) {
return new DataResponse($th->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR);
Expand Down
7 changes: 7 additions & 0 deletions lib/Providers/DAV/Calendar/Cached/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ public function childExists($id): bool {
* @return array<int,EventEntity>
*/
public function getMultipleChildren(array $ids): array {
// remove extension
$ids = array_map(fn ($id) => str_replace('.ics', '', $id), $ids);
// construct filter
$filter = $this->_store->entityListFilter();
$filter->condition('cid', $this->_collection->getId());
Expand Down Expand Up @@ -360,6 +362,9 @@ public function getChild($id): EventEntity|false {
* @return string entity signature
*/
public function createFile($id, $data = null): string {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
// remove extension
$id = str_replace('.ics', '', $id);
// evaluate if data is in UTF8 format and convert if needed
Expand All @@ -381,6 +386,8 @@ public function createFile($id, $data = null): string {
$entity->setSignature(md5($entity->getData()));
// extract additional properties
$this->extractProperties($entity, $vObject);
// URI segment is authoritative for lookups
$entity->setUuid($id);
// deposit entity to data store
$entity = $this->_store->entityCreate($entity);
// return state
Expand Down
3 changes: 3 additions & 0 deletions lib/Providers/DAV/Calendar/Cached/EventEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function get() {
* @inheritDoc
*/
public function put($data) {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
return $this->_collection->modifyFile($this->_entity, $data);
}

Expand Down
13 changes: 12 additions & 1 deletion lib/Providers/DAV/Calendar/Hybrid/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getACL(): array {
'principal' => $this->getOwner(),
'protected' => true
];
}, $this->collection->permissions ?? ['{DAV:}all']);
}, $this->collection->permissions ?: ['{DAV:}all']);
}

/**
Expand Down Expand Up @@ -309,6 +309,8 @@ public function getChildren(): array {
* @return bool
*/
public function childExists($id): bool {
// remove extension
$id = str_replace('.ics', '', $id);
// construct filter
$listFilter = $this->localService->entityListFilter();
$listFilter->condition('cid', $this->collection->localId);
Expand All @@ -326,6 +328,8 @@ public function childExists($id): bool {
* @return array<int,EventEntity>
*/
public function getMultipleChildren(array $ids): array {
// remove extension
$ids = array_map(fn ($id) => str_replace('.ics', '', $id), $ids);
// construct filter
$listFilter = $this->localService->entityListFilter();
$listFilter->condition('cid', $this->collection->localId);
Expand Down Expand Up @@ -375,10 +379,17 @@ public function getChild($id): EventEntity|false {
*/
public function createFile($id, $data = null): string {

if (is_resource($data)) {
$data = stream_get_contents($data);
}
// remove extension
$id = str_replace('.ics', '', $id);

$eo = new Entity();
$eo->localCollectionId = $this->collection->localId;
$eo->remoteCollectionId = $this->collection->remoteId;
$eo->remoteEntityId = $id;
$eo->uuid = $id;
$eo->data = $data;

$remoteService = $this->remoteService();
Expand Down
3 changes: 3 additions & 0 deletions lib/Providers/DAV/Calendar/Hybrid/EventEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function get() {
* @inheritDoc
*/
public function put($data) {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
return $this->collection->modifyFile($this->entity, $data);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Providers/DAV/Contacts/Cached/ContactCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public function childExists($id): bool {
* @return array<int,ContactEntity>
*/
public function getMultipleChildren(array $ids): array {
// remove extension
$ids = array_map(fn ($id) => str_replace('.vcf', '', $id), $ids);
// construct filter
$filter = $this->_store->entityListFilter();
$filter->condition('cid', $this->_collection->getId());
Expand Down Expand Up @@ -296,6 +298,9 @@ public function getChild($id): ContactEntity|false {
* @return string entity signature
*/
public function createFile($id, $data = null): string {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
// remove extension
$id = str_replace('.vcf', '', $id);
// evaluate if data is in UTF8 format and convert if needed
Expand All @@ -315,6 +320,8 @@ public function createFile($id, $data = null): string {
$entity->setSignature(md5($data));
// extract additional properties
$this->extractProperties($entity, $vObject);
// URI segment is authoritative for lookups
$entity->setUuid($id);
// deposit entity to data store
$entity = $this->_store->entityCreate($entity);
// return state
Expand Down
3 changes: 3 additions & 0 deletions lib/Providers/DAV/Contacts/Cached/ContactEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function get() {
* @inheritDoc
*/
public function put($data) {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
return $this->_collection->modifyFile($this->_entity, $data);
}

Expand Down
15 changes: 14 additions & 1 deletion lib/Providers/DAV/Contacts/Hybrid/ContactCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getACL(): array {
'principal' => $this->getOwner(),
'protected' => true
];
}, $this->collection->permissions ?? ['{DAV:}all']);
}, $this->collection->permissions ?: ['{DAV:}all']);
}

/**
Expand Down Expand Up @@ -247,6 +247,8 @@ public function getChildren(): array {
* @return bool
*/
public function childExists($id): bool {
// remove extension
$id = str_replace('.vcf', '', $id);
// construct filter
$listFilter = $this->localService->entityListFilter();
$listFilter->condition('cid', $this->collection->localId);
Expand All @@ -264,6 +266,8 @@ public function childExists($id): bool {
* @return array<int,ContactEntity>
*/
public function getMultipleChildren(array $ids): array {
// remove extension
$ids = array_map(fn ($id) => str_replace('.vcf', '', $id), $ids);
// construct filter
$listFilter = $this->localService->entityListFilter();
$listFilter->condition('cid', $this->collection->localId);
Expand All @@ -287,6 +291,8 @@ public function getMultipleChildren(array $ids): array {
* @return ContactEntity|false
*/
public function getChild($id): ContactEntity|false {
// remove extension
$id = str_replace('.vcf', '', $id);
// construct filter
$listFilter = $this->localService->entityListFilter();
$listFilter->condition('cid', $this->collection->localId);
Expand All @@ -311,10 +317,17 @@ public function getChild($id): ContactEntity|false {
*/
public function createFile($id, $data = null): string {

if (is_resource($data)) {
$data = stream_get_contents($data);
}
// remove extension
$id = str_replace('.vcf', '', $id);

$eo = new Entity();
$eo->localCollectionId = $this->collection->localId;
$eo->remoteCollectionId = $this->collection->remoteId;
$eo->remoteEntityId = $id;
$eo->uuid = $id;
$eo->data = $data;

$remoteService = $this->remoteService();
Expand Down
3 changes: 3 additions & 0 deletions lib/Providers/DAV/Contacts/Hybrid/ContactEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function get() {
* @inheritDoc
*/
public function put($data) {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
return $this->collection->modifyFile($this->entity, $data);
}

Expand Down
24 changes: 12 additions & 12 deletions lib/Service/CoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,40 +111,40 @@ public function locateAccount(array $configuration): ?array {
*
* @return bool
*/
public function connectAccount(string $uid, array $configuration, array $options = []): bool {
public function connectAccount(string $uid, array $configuration, array $options = []): ?ServiceEntity {
$forceAutoDiscovery = in_array('AUTO_DISCOVERY', $options, true);

// validate service configuration
if (!empty($configuration['location_host']) && !\OCA\DAVC\Utile\Validator::host($configuration['location_host'])) {
return false;
return null;
}

if ($configuration['auth'] === Constants::AUTHENTICATION_TYPE_BASIC) {
// validate id
//if (!\OCA\DAVC\Utile\Validator::username($configuration['bauth_id'])) {
// return false;
// return null;
//}
// validate secret
if (empty($configuration['bauth_secret'])) {
return false;
return null;
}
} elseif ($configuration['auth'] === Constants::AUTHENTICATION_TYPE_TOKEN) {
// validate id
if (!\OCA\DAVC\Utile\Validator::username($configuration['oauth_id'])) {
return false;
return null;
}
// validate secret
if (empty($configuration['oauth_access_token'])) {
return false;
return null;
}
} else {
return false;
return null;
}
// if host was not provided, or auto-discovery was explicitly requested, attempt to locate it
if ($forceAutoDiscovery || empty($configuration['location_host'])) {
$configuration = $this->locateAccount($configuration) ?? [];
if (empty($configuration['location_host'])) {
return false;
return null;
}
}

Expand Down Expand Up @@ -180,12 +180,12 @@ public function connectAccount(string $uid, array $configuration, array $options
$info = $remoteStore->discover();
} catch (Throwable $e) {
$this->logger->error('Connection failed:', ['app' => 'davc', 'exception' => $e]);
return false;
return null;
}

// determine if connection was established
if ($info['connected'] === false) {
return false;
return null;
}

if ($info['principalUrl'] !== null) {
Expand All @@ -201,13 +201,13 @@ public function connectAccount(string $uid, array $configuration, array $options
$service->setEnabled(true);
$service->setConnected(true);

$this->ServicesService->deposit($uid, $service);
$service = $this->ServicesService->deposit($uid, $service);

// TODO: Should this be implemented?
// register harmonization task
//$this->TaskService->add(\OCA\DAVC\Tasks\HarmonizationLauncher::class, ['uid' => $uid, 'sid' => $service->getId()]);

return true;
return $service;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/Service/Local/LocalContactsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ public function fromEntityModel(Entity $so, array $additional = []): ContactEnti
// construct correlation signature
$to->setCesn($signature . $so->remoteSignature);
// extract additional values from object
/** @var \Sabre\VObject\VCard $vo */
$vo = Reader::read($so->data);
$to->setUuid($vo->UID->getValue());
if (!empty($so->uuid)) {
$to->setUuid($so->uuid);
} else {
/** @var \Sabre\VObject\VCard $vo */
$vo = Reader::read($so->data);
$to->setUuid($vo->UID->getValue());
}

// override / assign additional values
foreach ($additional as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Local/LocalEventsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function fromEntityModel(Entity $so, array $additional = []): EventEntity
}
}

$to->setUuid($vc->UID->getValue());
$to->setUuid(!empty($so->uuid) ? $so->uuid : $vc->UID->getValue());
$to->setStartson($vc->DTSTART->getDateTime()->getTimestamp());

if ($vc->DTEND) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(IURLGenerator $urlGenerator, IL10N $l) {
* @returns string
*/
public function getID(): string {
return 'integration-jmapc'; //or a generic id if feasible
return 'integration-davc';
}

/**
Expand All @@ -42,7 +42,7 @@ public function getID(): string {
* @return string
*/
public function getName(): string {
return $this->l->t('JMAP Connector');
return $this->l->t('DAV Connector');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getForm(): TemplateResponse {
}

public function getSection(): string {
return 'integration-jmapc';
return 'integration-davc';
}

public function getPriority(): int {
Expand Down
Loading
Loading