75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Dav;
|
|
|
|
use Sabre\DAVACL\PrincipalBackend\AbstractBackend;
|
|
use App\Models\User;
|
|
|
|
/**
|
|
* Minimal principal backend — pulls principals straight from `users`.
|
|
*/
|
|
class PrincipalBackend extends AbstractBackend
|
|
{
|
|
/* ---------- mandatory look-ups ---------- */
|
|
|
|
public function getPrincipalByPath($path)
|
|
{
|
|
// "principals/<ulid>"
|
|
if (! str_starts_with($path, 'principals/')) {
|
|
return null;
|
|
}
|
|
|
|
$id = substr($path, strlen('principals/'));
|
|
$user = User::find($id);
|
|
|
|
return $user ? $this->format($user) : null;
|
|
}
|
|
|
|
public function getPrincipalsByPrefix($prefixPath)
|
|
{
|
|
// Sabre passes "principals" as the prefix for /principals/*
|
|
return User::all()->map(fn ($u) => $this->format($u))->all();
|
|
}
|
|
|
|
/* ---------- the five extra interface methods ---------- */
|
|
|
|
public function updatePrincipal($path, $mutations)
|
|
{
|
|
// not writable for now
|
|
return false;
|
|
}
|
|
|
|
public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof', $limit = 100)
|
|
{
|
|
// not implemented yet
|
|
return [];
|
|
}
|
|
|
|
public function getGroupMemberSet($principal)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getGroupMembership($principal)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function setGroupMemberSet($principal, array $members)
|
|
{
|
|
return false; // read-only
|
|
}
|
|
|
|
/* ---------- helper ---------- */
|
|
|
|
private function format(User $u)
|
|
{
|
|
return [
|
|
'id' => $u->id,
|
|
'uri' => $u->uri, // "principals/<ULID>"
|
|
'{DAV:}displayname' => $u->displayname ?? $u->name,
|
|
'{http://sabredav.org/ns}email-address' => $u->email,
|
|
];
|
|
}
|
|
}
|