Fixes for translations corrupting client savings

This commit is contained in:
David Bomba 2022-04-01 15:13:46 +11:00
parent 5a4614da1f
commit eec5e47302
2 changed files with 41 additions and 6 deletions

View File

@ -64,13 +64,13 @@ trait ClientGroupSettingsSaver
} }
//this pass will handle any null values that are in the translations //this pass will handle any null values that are in the translations
foreach ($settings->translations as $key => $value) { // foreach ($settings->translations as $key => $value) {
if (is_null($settings->translations[$key])) { // if (is_null($settings->translations[$key])) {
$settings->translations[$key] = ''; // $settings->translations[$key] = '';
} // }
} // }
$entity_settings->translations = $settings->translations; // $entity_settings->translations = $settings->translations;
$entity->settings = $entity_settings; $entity->settings = $entity_settings;
$entity->save(); $entity->save();
@ -94,6 +94,9 @@ trait ClientGroupSettingsSaver
ksort($casts); ksort($casts);
if(property_exists($settings, 'translations'))
unset($settings->translations);
foreach ($settings as $key => $value) { foreach ($settings as $key => $value) {
if (! isset($settings->{$key}) || empty($settings->{$key}) || (! is_object($settings->{$key}) && strlen($settings->{$key}) == 0)) { if (! isset($settings->{$key}) || empty($settings->{$key}) || (! is_object($settings->{$key}) && strlen($settings->{$key}) == 0)) {
unset($settings->{$key}); unset($settings->{$key});

View File

@ -42,6 +42,38 @@ class ClientApiTest extends TestCase
Model::reguard(); Model::reguard();
} }
public function testIllegalPropertiesInClientSettings()
{
$settings = [
'currency_id' => "1",
'translations' => [
'email' => 'legal@eagle.com'
],
];
$data = [
'name' => $this->faker->firstName,
'settings' => $settings,
];
$response = false;
try{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$response->assertStatus(200);
$arr = $response->json();
$this->assertFalse(array_key_exists('translations', $arr['data']['settings']));
}
public function testClientLanguageCodeIllegal() public function testClientLanguageCodeIllegal()
{ {