diff --git a/CHANGELOG.md b/CHANGELOG.md index 2446fc3..c104ac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Flexisip Account Manager Changelog v1.5 ----- +--- +- Fix FLEXIAPI-186 Ensure that empty objects are serialized in JSON as objects and not empty arrays - Fix FLEXIAPI-185 Return null if the account dictionary is empty in the API - Fix FLEXIAPI-184 Append phone_change_code and email_change_code to the admin /accounts/ endpoint if they are available - Fix FLEXIAPI-183 Complete the account hooks on the dictionnary actions diff --git a/flexiapi/app/Account.php b/flexiapi/app/Account.php index 6188c29..8ef104f 100644 --- a/flexiapi/app/Account.php +++ b/flexiapi/app/Account.php @@ -30,6 +30,7 @@ use Carbon\Carbon; use Awobaz\Compoships\Compoships; use App\Http\Controllers\Account\AuthenticateController as WebAuthenticateController; +use stdClass; class Account extends Authenticatable { @@ -141,9 +142,9 @@ class Account extends Authenticatable return $this->hasMany(AccountDictionaryEntry::class); } - public function getDictionaryAttribute(): ?Collection + public function getDictionaryAttribute() { - if ($this->dictionaryEntries->isEmpty()) return null; + if ($this->dictionaryEntries->isEmpty()) return new stdClass; return $this->dictionaryEntries->keyBy('key')->map(function ($entry) { return $entry->value; diff --git a/flexiapi/app/Libraries/FlexisipConnector.php b/flexiapi/app/Libraries/FlexisipConnector.php index ec447be..6142ce2 100644 --- a/flexiapi/app/Libraries/FlexisipConnector.php +++ b/flexiapi/app/Libraries/FlexisipConnector.php @@ -22,6 +22,7 @@ namespace App\Libraries; use App\Device; use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Log; +use stdClass; class FlexisipConnector { @@ -41,6 +42,8 @@ class FlexisipConnector Log::error('Redis server issue: ' . $th->getMessage()); } + if ($devices->isEmpty()) return new stdClass; + return $devices->keyBy('uuid'); } diff --git a/flexiapi/tests/Feature/ApiAccountTest.php b/flexiapi/tests/Feature/ApiAccountTest.php index 02ee9ca..b1fee56 100644 --- a/flexiapi/tests/Feature/ApiAccountTest.php +++ b/flexiapi/tests/Feature/ApiAccountTest.php @@ -73,6 +73,17 @@ class ApiAccountTest extends TestCase ]); } + public function testEmptyDevices() + { + $account = Account::factory()->create(); + $account->generateApiKey(); + + $this->keyAuthenticated($account) + ->get($this->route . '/me/devices') + ->assertStatus(200) + ->assertSee('{}'); + } + public function testUsernameNotPhone() { $password = Password::factory()->admin()->create(); @@ -438,7 +449,7 @@ class ApiAccountTest extends TestCase $this->keyAuthenticated($admin) ->json('GET', $this->route . '/' . $accountId) - ->assertSee(['"dictionary":null'], false) + ->assertSee(['"dictionary":{}'], false) ->assertStatus(200); }