diff --git a/app/Utils/Traits/ClientGroupSettingsSaver.php b/app/Utils/Traits/ClientGroupSettingsSaver.php index c4cce0e598..2172469f19 100644 --- a/app/Utils/Traits/ClientGroupSettingsSaver.php +++ b/app/Utils/Traits/ClientGroupSettingsSaver.php @@ -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}); diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 5c6553df11..de2b642f96 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -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() {