Skip to content

Commit

Permalink
fixup! feat(dav): Add and filter locally scoped properties for federa…
Browse files Browse the repository at this point in the history
…ted address book sync
  • Loading branch information
miaulalala authored and ChristophWurst committed May 8, 2023
1 parent 4da74d0 commit 252b3f4
Showing 1 changed file with 31 additions and 63 deletions.
94 changes: 31 additions & 63 deletions apps/dav/lib/CardDAV/SystemAddressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,7 @@ public function getChildren(): array {
* @return Card[]
*/
public function getMultipleChildren($paths): array {
if ($this->trustedServers === null || $this->request === null) {
return parent::getMultipleChildren($paths);
}

/** @psalm-suppress NoInterfaceProperties */
if ($this->request->server['PHP_AUTH_USER'] !== 'system') {
return parent::getMultipleChildren($paths);
}

/** @psalm-suppress NoInterfaceProperties */
$sharedSecret = $this->request->server['PHP_AUTH_PW'];
if ($sharedSecret === null) {
return parent::getMultipleChildren($paths);
}

$servers = $this->trustedServers->getServers();
$trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) {
return $trustedServer['shared_secret'] === $sharedSecret;
});
// Authentication is fine, but it's not for a federated share
if (empty($trusted)) {
if (!$this->isFederation()) {
return parent::getMultipleChildren($paths);
}

Expand Down Expand Up @@ -130,27 +110,7 @@ public function getMultipleChildren($paths): array {
* @throws Forbidden
*/
public function getChild($name): Card {
if ($this->trustedServers === null || $this->request === null) {
return parent::getChild($name);
}

/** @psalm-suppress NoInterfaceProperties */
if ($this->request->server['PHP_AUTH_USER'] !== 'system') {
return parent::getChild($name);
}

/** @psalm-suppress NoInterfaceProperties */
$sharedSecret = $this->request->server['PHP_AUTH_PW'];
if ($sharedSecret === null) {
return parent::getChild($name);
}

$servers = $this->trustedServers->getServers();
$trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) {
return $trustedServer['shared_secret'] === $sharedSecret;
});
// Authentication is fine, but it's not for a federated share
if (empty($trusted)) {
if (!$this->isFederation()) {
return parent::getChild($name);
}

Expand Down Expand Up @@ -197,27 +157,7 @@ public function getChanges($syncToken, $syncLevel, $limit = null): ?array {
return null;
}

if ($this->trustedServers === null || $this->request === null) {
return parent::getChanges($syncToken, $syncLevel, $limit);
}

/** @psalm-suppress NoInterfaceProperties */
if ($this->request->server['PHP_AUTH_USER'] !== 'system') {
return parent::getChanges($syncToken, $syncLevel, $limit);
}

/** @psalm-suppress NoInterfaceProperties */
$sharedSecret = $this->request->server['PHP_AUTH_PW'];
if ($sharedSecret === null) {
return parent::getChanges($syncToken, $syncLevel, $limit);
}

$servers = $this->trustedServers->getServers();
$trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) {
return $trustedServer['shared_secret'] === $sharedSecret;
});
// Authentication is fine, but it's not for a federated share
if (empty($trusted)) {
if (!$this->isFederation()) {
return parent::getChanges($syncToken, $syncLevel, $limit);
}

Expand Down Expand Up @@ -254,4 +194,32 @@ public function getChanges($syncToken, $syncLevel, $limit = null): ?array {
$changed['deleted'] = $deleted;
return $changed;
}

private function isFederation(): bool {
if ($this->trustedServers === null || $this->request === null) {
return false;
}

/** @psalm-suppress NoInterfaceProperties */
if ($this->request->server['PHP_AUTH_USER'] !== 'system') {
return false;
}

/** @psalm-suppress NoInterfaceProperties */
$sharedSecret = $this->request->server['PHP_AUTH_PW'];
if ($sharedSecret === null) {
return false;
}

$servers = $this->trustedServers->getServers();
$trusted = array_filter($servers, function ($trustedServer) use ($sharedSecret) {
return $trustedServer['shared_secret'] === $sharedSecret;
});
// Authentication is fine, but it's not for a federated share
if (empty($trusted)) {
return false;
}

return true;
}
}

0 comments on commit 252b3f4

Please sign in to comment.