generated from Nodarx/template
Initial service DAV module
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ServiceDav\Backends;
|
||||
|
||||
use KTXC\SessionIdentity;
|
||||
use KTXC\SessionTenant;
|
||||
use KTXM\ServiceDav\DavProperties;
|
||||
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
|
||||
|
||||
/**
|
||||
* DAVACL principal backend.
|
||||
*/
|
||||
class PrincipalBackend implements BackendInterface
|
||||
{
|
||||
public const PRINCIPAL_PREFIX = 'principals';
|
||||
|
||||
public function __construct(
|
||||
private readonly SessionIdentity $identity,
|
||||
private readonly SessionTenant $tenant,
|
||||
) {}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// BackendInterface
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function getPrincipalsByPrefix($prefixPath): array
|
||||
{
|
||||
if ($prefixPath !== self::PRINCIPAL_PREFIX || $this->identity->identity() === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [$this->buildPrincipal()];
|
||||
}
|
||||
|
||||
public function getPrincipalByPath($path): ?array
|
||||
{
|
||||
if ($this->identity->identity() === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$expected = self::PRINCIPAL_PREFIX . '/' . $this->identity->identifier();
|
||||
if ($path !== $expected) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->buildPrincipal();
|
||||
}
|
||||
|
||||
public function getGroupMemberSet($principal): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getGroupMembership($principal): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function setGroupMemberSet($principal, $members): void
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
public function updatePrincipal($path, $propPatch): int
|
||||
{
|
||||
return 403;
|
||||
}
|
||||
|
||||
public function searchPrincipals($prefixPath, $searchProperties, $test = 'allof'): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function findByUri($uri, $principalPrefix): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private function buildPrincipal(): array
|
||||
{
|
||||
$userId = $this->identity->identifier();
|
||||
$label = $this->identity->label() ?? $userId;
|
||||
$email = $this->identity->mailAddress() ?? '';
|
||||
|
||||
return [
|
||||
DavProperties::URI => self::PRINCIPAL_PREFIX . '/' . $userId,
|
||||
DavProperties::DISPLAYNAME => $label,
|
||||
DavProperties::SABRE_EMAIL => $email,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user