Fix FLEXIAPI-185 Return null if the account dictionary is empty in the API

This commit is contained in:
Timothée Jaussoin 2024-06-13 15:23:25 +02:00
parent 61a0339442
commit 9f908c3f7d
3 changed files with 22 additions and 1 deletions

View file

@ -2,6 +2,7 @@
v1.5 v1.5
---- ----
- 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/<id> endpoint if they are available - Fix FLEXIAPI-184 Append phone_change_code and email_change_code to the admin /accounts/<id> endpoint if they are available
- Fix FLEXIAPI-183 Complete the account hooks on the dictionnary actions - Fix FLEXIAPI-183 Complete the account hooks on the dictionnary actions
- Fix FLEXIAPI-181 Replace APP_ADMINS_MANAGE_MULTI_DOMAINS with APP_SUPER_ADMINS_SIP_DOMAINS - Fix FLEXIAPI-181 Replace APP_ADMINS_MANAGE_MULTI_DOMAINS with APP_SUPER_ADMINS_SIP_DOMAINS

View file

@ -22,6 +22,7 @@ namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Collection;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -140,8 +141,10 @@ class Account extends Authenticatable
return $this->hasMany(AccountDictionaryEntry::class); return $this->hasMany(AccountDictionaryEntry::class);
} }
public function getDictionaryAttribute() public function getDictionaryAttribute(): ?Collection
{ {
if ($this->dictionaryEntries->isEmpty()) return null;
return $this->dictionaryEntries->keyBy('key')->map(function ($entry) { return $this->dictionaryEntries->keyBy('key')->map(function ($entry) {
return $entry->value; return $entry->value;
}); });

View file

@ -423,6 +423,23 @@ class ApiAccountTest extends TestCase
$entryNewKey => $entryNewValue $entryNewKey => $entryNewValue
] ]
]); ]);
// Clear
$this->keyAuthenticated($admin)
->json('PUT', $this->route . '/' . $accountId, [
'username' => 'john3',
'password' => 'bar',
'algorithm' => 'SHA-256',
'dictionary' => []
])
->assertJson(['dictionary' => null])
->assertStatus(200);
$this->keyAuthenticated($admin)
->json('GET', $this->route . '/' . $accountId)
->assertSee(['"dictionary":null'], false)
->assertStatus(200);
} }
public function testActivated() public function testActivated()