fix(NextCloud members and script - part 1)
This commit is contained in:
@@ -61,14 +61,22 @@ class DolibarrService
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public function setMemberStatus(int|string $id, int|string $status): bool
|
||||
/**
|
||||
* Update a member with custom data
|
||||
*
|
||||
* @param int|string $id The Dolibarr member ID (rowid)
|
||||
* @param array $data Array of attributes to update (e.g. ['email' => 'new@email.com', 'array_options' => ['options_custom' => 'val']])
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function updateMember(int|string $id, array $data): bool
|
||||
{
|
||||
$response = $this->client()->put(
|
||||
$this->baseUrl . '/members/' . $id,
|
||||
['status' => $status]
|
||||
$data
|
||||
);
|
||||
|
||||
return $response->successful();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -88,19 +88,44 @@ class ISPConfigMailService extends ISPConfigService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateMailUser(string $email, array $changes): bool
|
||||
{
|
||||
$allUsers = $this->getAllMailUsers();
|
||||
$user = collect($allUsers)->firstWhere('email', $email);
|
||||
// On retrouve l'utilisateur
|
||||
$user = collect($this->getAllMailUsers())
|
||||
->firstWhere('email', $email);
|
||||
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->call('mail_user_update', [
|
||||
'primary_id' => $user['mailuser_id'],
|
||||
'params' => $changes,
|
||||
$mailuserId = (int) $user['mailuser_id'];
|
||||
|
||||
// On récupère l'enregistrement COMPLET (OBLIGATOIRE)
|
||||
$mailUserRecord = $this->call('mail_user_get', [
|
||||
$mailuserId
|
||||
]);
|
||||
|
||||
if (!is_array($mailUserRecord)) {
|
||||
throw new \RuntimeException('mail_user_get did not return array');
|
||||
}
|
||||
|
||||
// On applique les changements
|
||||
foreach ($changes as $key => $value) {
|
||||
$mailUserRecord[$key] = $value;
|
||||
}
|
||||
|
||||
// appel conforme EXACT à l’exemple ISPConfig
|
||||
$result = $this->call('mail_user_update', [
|
||||
0, // client_id (ADMIN)
|
||||
$mailuserId, // primary_id
|
||||
$mailUserRecord // FULL RECORD
|
||||
]);
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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 l’email
|
||||
* @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') ?? [];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user