1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

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
foreach ($settings->translations as $key => $value) {
if (is_null($settings->translations[$key])) {
$settings->translations[$key] = '';
}
}
// foreach ($settings->translations as $key => $value) {
// if (is_null($settings->translations[$key])) {
// $settings->translations[$key] = '';
// }
// }
$entity_settings->translations = $settings->translations;
// $entity_settings->translations = $settings->translations;
$entity->settings = $entity_settings;
$entity->save();
@ -94,6 +94,9 @@ trait ClientGroupSettingsSaver
ksort($casts);
if(property_exists($settings, 'translations'))
unset($settings->translations);
foreach ($settings as $key => $value) {
if (! isset($settings->{$key}) || empty($settings->{$key}) || (! is_object($settings->{$key}) && strlen($settings->{$key}) == 0)) {
unset($settings->{$key});

View File

@ -42,6 +42,38 @@ class ClientApiTest extends TestCase
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()
{