fix(NextCloud members and script - part 1)

This commit is contained in:
2026-01-19 15:31:34 +01:00
parent 08d1944491
commit b8de637b23
8 changed files with 287 additions and 29 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Services\Nextcloud;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -46,15 +47,24 @@ class NextcloudService
/**
* Trouve le userId Nextcloud à partir de lemail
* @throws ConnectionException
*/
protected function findUserIdByEmail(string $email): ?string
{
$response = $this->http->get('/cloud/users');
return Cache::remember(
'nextcloud.user_id.' . md5($email),
now()->addDays(7),
function () use ($email) {
return $this->resolveUserIdByEmail($email);
}
);
}
if (!$response->successful()) {
throw new \RuntimeException('Erreur récupération utilisateurs Nextcloud');
}
/**
* @throws ConnectionException
*/
protected function resolveUserIdByEmail(string $email): ?string
{
$response = $this->http->get('/cloud/users');
$users = $response->json('ocs.data.users') ?? [];
@@ -63,7 +73,7 @@ class NextcloudService
if (
$details->successful() &&
($details->json('ocs.data.email') === $email)
$details->json('ocs.data.email') === $email
) {
return $userId;
}
@@ -71,4 +81,26 @@ class NextcloudService
return null;
}
/**
* @throws ConnectionException
*/
public function listUsers(): array
{
return $this->http
->get('/cloud/users')
->json('ocs.data.users') ?? [];
}
/**
* @throws ConnectionException
*/
public function getUserDetails(string $userId): array
{
return $this->http
->get("/cloud/users/{$userId}")
->json('ocs.data') ?? [];
}
}