mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for translations corrupting client savings
This commit is contained in:
parent
5a4614da1f
commit
eec5e47302
@ -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});
|
||||
|
@ -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()
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user