From a6ca60a2fdc76759720e9dee1848da2c29f649d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCle?= Date: Tue, 12 Nov 2024 13:16:25 +0100 Subject: [PATCH] fix(Tinebase/ModelConfiguration): remove field from jsonExpander if app is not available --- .../HumanResources/ModelConfigurationTest.php | 6 +++--- tests/tine20/Tinebase/ModelConfigurationTest.php | 16 ++++++++++++++-- tine20/Tinebase/ModelConfiguration.php | 5 ++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/tine20/HumanResources/ModelConfigurationTest.php b/tests/tine20/HumanResources/ModelConfigurationTest.php index ac1d3d46311..cec8bc8a40b 100644 --- a/tests/tine20/HumanResources/ModelConfigurationTest.php +++ b/tests/tine20/HumanResources/ModelConfigurationTest.php @@ -4,7 +4,7 @@ * * @package Tinebase * @license http://www.gnu.org/licenses/agpl.html - * @copyright Copyright (c) 2013 - 2018 Metaways Infosystems GmbH (http://www.metaways.de) + * @copyright Copyright (c) 2013 - 2024 Metaways Infosystems GmbH (http://www.metaways.de) * @copyright Copyright (c) 2014 Serpro (http://www.serpro.gov.br) * @author Flávio Gomes da Silva Lisboa */ @@ -15,9 +15,9 @@ require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php'; /** - * Test class for Tinebase_ModelConfiguration, using the test class from hr + * Test class for HumanResources_ModelConfigurationTest */ -class HumanResources_ModelConfigurationTest extends \PHPUnit\Framework\TestCase +class HumanResources_ModelConfigurationTest extends TestCase { /** * tests if the modelconfiguration gets created using the static call diff --git a/tests/tine20/Tinebase/ModelConfigurationTest.php b/tests/tine20/Tinebase/ModelConfigurationTest.php index c2da4320217..a47e705a3b4 100644 --- a/tests/tine20/Tinebase/ModelConfigurationTest.php +++ b/tests/tine20/Tinebase/ModelConfigurationTest.php @@ -6,13 +6,15 @@ * * @package Tinebase * @license http://www.gnu.org/licenses/agpl.html - * @copyright Copyright (c) 2013-2021 Metaways Infosystems GmbH (http://www.metaways.de) + * @copyright Copyright (c) 2013-2024 Metaways Infosystems GmbH (http://www.metaways.de) * @author Alexander Stintzing */ class Tinebase_ModelConfigurationTest extends TestCase { protected function tearDown(): void -{ + { + Tinebase_Application::getInstance()->setApplicationStatus('Sales', Tinebase_Application::ENABLED); + parent::tearDown(); // reset mc config to prevent problems with following tests @@ -140,4 +142,14 @@ public function testConfigViaDefault() self::assertTrue(isset($fields['sales_tax']['default']), print_r($fields['sales_tax'], true)); self::assertEquals(19.0, $fields['sales_tax']['default'], print_r($fields['sales_tax'], true)); } + + public function testModelExpanderWithoutRecordApp() + { + // disable Sales + Tinebase_Application::getInstance()->setApplicationStatus('Sales', Tinebase_Application::DISABLED); + $inventoryMC = Inventory_Model_InventoryItem::getConfiguration(); + if ($inventoryMC->jsonExpander) { + self::assertArrayNotHasKey('invoice', $inventoryMC->jsonExpander['properties'], print_r($inventoryMC->jsonExpander, true)); + } + } } diff --git a/tine20/Tinebase/ModelConfiguration.php b/tine20/Tinebase/ModelConfiguration.php index 8c9c63d8a89..8923bab4331 100644 --- a/tine20/Tinebase/ModelConfiguration.php +++ b/tine20/Tinebase/ModelConfiguration.php @@ -1161,7 +1161,7 @@ class_exists($this->_appName . '_Model_' . $this->_modelName . 'Grants')) { self::VALIDATORS => [Zend_Filter_Input::ALLOW_EMPTY => true],*/ ]; } - // you can null everything below here to prevent it from being writte to + // you can null everything below here to prevent it from being written to if (!array_key_exists(self::JSON_EXPANDER, $modelClassConfiguration) && !is_array($this->_jsonExpander)) { $this->_jsonExpander = []; } @@ -1363,6 +1363,9 @@ class_exists($this->_appName . '_Model_' . $this->_modelName . 'Grants')) { $fieldDef[self::TYPE] = 'string'; $fieldDef['label'] = NULL; unset($this->_filterModel[$fieldKey]); + if (isset($this->_jsonExpander['properties'][$fieldKey])) { + unset($this->_jsonExpander['properties'][$fieldKey]); + } continue; } // the property name