From 09ce0743841ea00d86367e2002aa7b8cbd5b8a7e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 16 May 2026 12:10:11 +0100 Subject: [PATCH] Fix Client Admin API docs/guards and correct Guest API test fixture typos (#3561) * Initial plan * fix client admin api docs and validation edge cases Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/4dcf2f2c-77f2-4343-83ef-ecd1e9d63d82 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * refactor currency assignment in client admin update Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/4dcf2f2c-77f2-4343-83ef-ecd1e9d63d82 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> --- src/modules/Client/Api/Admin.php | 19 +++++++++++-------- tests-legacy/modules/Client/Api/GuestTest.php | 18 +++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/modules/Client/Api/Admin.php b/src/modules/Client/Api/Admin.php index 75a2b2c8d..f8fe80e9b 100644 --- a/src/modules/Client/Api/Admin.php +++ b/src/modules/Client/Api/Admin.php @@ -47,11 +47,11 @@ class Admin extends \Api_Abstract } /** - * Get a list of clients. + * Get client ID/name pairs. * * @param array $data Filtering options * - * @return array List of clients in a paginated manner + * @return array List of client ID/name pairs */ public function get_pairs($data) { @@ -156,7 +156,9 @@ class Admin extends \Api_Abstract throw new InformationException('This email address is already registered.'); } - $validator->isPasswordStrong($data['password']); + if (isset($data['password']) && $data['password'] !== '') { + $validator->isPasswordStrong($data['password']); + } $this->di['events_manager']->fire(['event' => 'onBeforeAdminClientCreate', 'params' => $data]); $id = $service->adminCreateClient($data); @@ -248,16 +250,17 @@ class Admin extends \Api_Abstract unset($data['birthday']); } - if (($data['currency'] ?? null) && $service->canChangeCurrency($client, $data['currency'] ?? null)) { - $client->currency = $data['currency'] ?? $client->currency; + $currency = $data['currency'] ?? null; + if ($currency && $service->canChangeCurrency($client, $currency)) { + $client->currency = $currency; } $this->di['events_manager']->fire(['event' => 'onBeforeAdminClientUpdate', 'params' => $data]); // Special handling for the phone country codes - $phoneCC = $data['phone_cc'] ?? $client->phone_cc; - if (!empty($phoneCC)) { - $client->phone_cc = Tools::validatePhoneCC($phoneCC); + $phoneCountryCode = $data['phone_cc'] ?? $client->phone_cc; + if (!empty($phoneCountryCode)) { + $client->phone_cc = Tools::validatePhoneCC($phoneCountryCode); } // Special handling for the phone number itself diff --git a/tests-legacy/modules/Client/Api/GuestTest.php b/tests-legacy/modules/Client/Api/GuestTest.php index 30ac9cab2..cbcc000e9 100644 --- a/tests-legacy/modules/Client/Api/GuestTest.php +++ b/tests-legacy/modules/Client/Api/GuestTest.php @@ -18,8 +18,8 @@ final class GuestTest extends \BBTestCase $data = [ 'email' => 'test@email.com', 'first_name' => 'John', - 'password' => 'testpaswword', - 'password_confirm' => 'testpaswword', + 'password' => 'testpassword', + 'password_confirm' => 'testpassword', ]; $serviceMock = $this->createMock(\Box\Mod\Client\Service::class); @@ -69,8 +69,8 @@ final class GuestTest extends \BBTestCase $data = [ 'email' => 'test@email.com', 'first_name' => 'John', - 'password' => 'testpaswword', - 'password_confirm' => 'testpaswword', + 'password' => 'testpassword', + 'password_confirm' => 'testpassword', ]; $serviceMock = $this->createMock(\Box\Mod\Client\Service::class); @@ -115,8 +115,8 @@ final class GuestTest extends \BBTestCase $data = [ 'email' => 'test@email.com', 'first_name' => 'John', - 'password' => 'testpaswword', - 'password_confirm' => 'testpaswword', + 'password' => 'testpassword', + 'password_confirm' => 'testpassword', ]; $client = new Guest(); @@ -138,8 +138,8 @@ final class GuestTest extends \BBTestCase $data = [ 'email' => 'test@email.com', 'first_name' => 'John', - 'password' => 'testpaswword', - 'password_confirm' => 'wrongpaswword', + 'password' => 'testpassword', + 'password_confirm' => 'wrongpassword', ]; $client = new Guest(); @@ -211,7 +211,7 @@ final class GuestTest extends \BBTestCase public function testResetPasswordNewFlow(): void { - $data['email'] = 'John@exmaple.com'; + $data['email'] = 'John@example.com'; $eventMock = $this->createMock('\Box_EventManager'); $eventMock->expects($this->atLeastOnce())->method('fire');