diff --git a/CHANGELOG.md b/CHANGELOG.md index cc865e3..a83109d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ v1.5 --- +- Fix FLEXIAPI-192 Clear and upgrade properly the account dictionary entries if the entries are already existing - Fix FLEXIAPI-191 Add quotes for the pn-prid parameter in FlexisipPusherConnector - 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 diff --git a/flexiapi/app/Account.php b/flexiapi/app/Account.php index 8ef104f..a60a80c 100644 --- a/flexiapi/app/Account.php +++ b/flexiapi/app/Account.php @@ -22,7 +22,6 @@ namespace App; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -153,11 +152,8 @@ class Account extends Authenticatable public function setDictionaryEntry(string $key, string $value): AccountDictionaryEntry { - $entry = $this->dictionaryEntries->where('key', $key)->first(); - - if (!$entry) { - $entry = new AccountDictionaryEntry; - } + $this->dictionaryEntries()->where('key', $key)->delete(); + $entry = new AccountDictionaryEntry; $entry->account_id = $this->id; $entry->key = $key; diff --git a/flexiapi/tests/Feature/ApiAccountDictionaryTest.php b/flexiapi/tests/Feature/ApiAccountDictionaryTest.php index af7efac..cd8b710 100644 --- a/flexiapi/tests/Feature/ApiAccountDictionaryTest.php +++ b/flexiapi/tests/Feature/ApiAccountDictionaryTest.php @@ -75,7 +75,7 @@ class ApiAccountDictionaryTest extends TestCase $this->keyAuthenticated($admin) ->json($this->method, $this->route . '/' . $account->id . '/dictionary/' . $key, [ 'value' => $newValue - ])->assertStatus(200); + ])->assertStatus(201); $this->keyAuthenticated($admin) ->get($this->route . '/' . $account->id . '/dictionary/') diff --git a/flexiapi/tests/Feature/ApiAccountTest.php b/flexiapi/tests/Feature/ApiAccountTest.php index b1fee56..5b2138f 100644 --- a/flexiapi/tests/Feature/ApiAccountTest.php +++ b/flexiapi/tests/Feature/ApiAccountTest.php @@ -400,6 +400,29 @@ class ApiAccountTest extends TestCase // Account update + $this->keyAuthenticated($admin) + ->json('PUT', $this->route . '/' . $accountId, [ + 'username' => 'john3', + 'password' => 'bar', + 'algorithm' => 'SHA-256', + 'dictionary' => [ + $entryNewKey => $entryNewValue + ] + ]) + ->assertJsonMissing([ + 'dictionary' => [ + $entryKey => $entryValue + ] + ]) + ->assertJson([ + 'dictionary' => [ + $entryNewKey => $entryNewValue + ] + ]) + ->assertStatus(200); + + // ...twice + $this->keyAuthenticated($admin) ->json('PUT', $this->route . '/' . $accountId, [ 'username' => 'john3',