Skip to content

Commit

Permalink
Merge branch 'pu/cw/tweakFieldFeatureSwitch' into 'main'
Browse files Browse the repository at this point in the history
tweak(Tinebase): allow field feature config to be for different app

See merge request tine20/tine20!6644
  • Loading branch information
corneliusweiss committed Feb 26, 2025
2 parents 4ab5b08 + dc6fc92 commit 036d6ba
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 53 deletions.
28 changes: 7 additions & 21 deletions tests/tine20/Tinebase/Frontend/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,28 +696,14 @@ public function testGetAllRegistryData()
$symbols = Zend_Locale::getTranslationList('symbols', $locale);
self::assertEquals($symbols['decimal'], $registryData['Tinebase']['decimalSeparator']);

if (Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
$configuredSalesModels = array_keys($registryData['Sales']['models']);
self::assertTrue(in_array('Invoice', $configuredSalesModels), 'Invoices is missing from configured models: '
. print_r($configuredSalesModels, true));
$copyOmitFields = array(
'billed_in',
'invoice_id',
'status',
'cleared_at',
'relations',
);
} else {
$copyOmitFields = array(
'billed_in',
'status',
'cleared_at',
'relations',
);
}

self::assertTrue(isset($registryData['Timetracker']['models']['Timeaccount']['copyOmitFields']), 'Timeaccount copyOmitFields empty/missing');
self::assertEquals($copyOmitFields, $registryData['Timetracker']['models']['Timeaccount']['copyOmitFields']);
self::assertEquals([
'billed_in',
'invoice_id',
'status',
'cleared_at',
'relations',
], $registryData['Timetracker']['models']['Timeaccount']['copyOmitFields']);
self::assertTrue(is_array(($registryData['Timetracker']['relatableModels'][0])), 'relatableModels needs to be an numbered array');

$this->_assertImportExportDefinitions($registryData);
Expand Down
16 changes: 0 additions & 16 deletions tests/tine20/Tinebase/ModelConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ public function testModelCreationTraditional()
$this->assertNull($cObj);
}

/**
* tests if the modelconfiguration is created for foreign record keys that are disabled by a feature switch
*/
public function testModelConfigWithDisabledForeignRecords()
{
// TODO disable feature first
if (Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
$this->markTestSkipped('only testable when disabled');
}

$timesheet = new Timetracker_Model_Timesheet(array(), true);
$mcFields = $timesheet->getConfiguration()->getFields();
$this->assertEquals('string', $mcFields['invoice_id']['type']);
$this->assertEquals(null, $mcFields['invoice_id']['label']);
}

/**
* testModelConfigWithDisabledRelationApp
*/
Expand Down
6 changes: 5 additions & 1 deletion tine20/Addressbook/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,11 @@ class Addressbook_Model_Contact extends Tinebase_Record_NewAbstract
self::UI_CONFIG => [
'filterOptions' => [
'jsConfig' => ['filtertype' => 'tinebase.site']
]
],
self::UI_CONFIG_FEATURE => [
self::APP_NAME => Tinebase_Config::APP_NAME,
self::UI_CONFIG_FEATURE => Tinebase_Config::FEATURE_SITE
],
]
],

Expand Down
4 changes: 4 additions & 0 deletions tine20/Calendar/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ class Calendar_Model_Event extends Tinebase_Record_Abstract
'searchComboConfig' => [
'useEditPlugin' => false,
],
self::UI_CONFIG_FEATURE => [
self::APP_NAME => Tinebase_Config::APP_NAME,
self::UI_CONFIG_FEATURE => Tinebase_Config::FEATURE_SITE
],
],
],
'organizer' => [
Expand Down
9 changes: 6 additions & 3 deletions tine20/Timetracker/Model/Timeaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ class Timetracker_Model_Timeaccount extends Sales_Model_Accountable_Abstract
'appName' => 'Sales',
'modelName' => 'Invoice',
'idProperty' => 'id',
// TODO we should replace this with a generic approach to fetch configured models of an app
// -> APP_Frontend_Json::$_configuredModels should be moved from json to app controller
'feature' => 'invoicesModule', // Sales_Config::FEATURE_INVOICES_MODULE
),
self::UI_CONFIG => [
self::UI_CONFIG_FEATURE => [
self::APP_NAME => 'Sales',
self::UI_CONFIG_FEATURE => 'invoicesModule'
],
],
'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
'copyOmit' => true,
),
Expand Down
9 changes: 6 additions & 3 deletions tine20/Timetracker/Model/Timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,13 @@ class Timetracker_Model_Timesheet extends Tinebase_Record_Abstract implements Sa
'appName' => 'Sales',
'modelName' => 'Invoice',
'idProperty' => 'id',
// TODO we should replace this with a generic approach to fetch configured models of an app
// -> APP_Frontend_Json::$_configuredModels should be moved from json to app controller
'feature' => 'invoicesModule', // Sales_Config::FEATURE_INVOICES_MODULE
),
self::UI_CONFIG => [
self::UI_CONFIG_FEATURE => [
self::APP_NAME => 'Sales',
self::UI_CONFIG_FEATURE => 'invoicesModule'
],
],
'copyOmit' => true,
),
'is_cleared' => array(
Expand Down
8 changes: 0 additions & 8 deletions tine20/Tinebase/ModelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2232,14 +2232,6 @@ protected function _isAvailable($_fieldConfig)
$result = self::$_availableApplications[$fieldConfig['appName']];
}

if ($result && isset($fieldConfig['feature'])) {
$config = Tinebase_Config_Abstract::factory($fieldConfig['appName']);
$result = $config->featureEnabled($fieldConfig['feature']);

if (! $result && Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__
. '::' . __LINE__ . ' Feature ' . $fieldConfig['feature'] . ' disables field');
}

return $result;
}

Expand Down
4 changes: 4 additions & 0 deletions tine20/Tinebase/ModelConfiguration/Const.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ class Tinebase_ModelConfiguration_Const {
public const UNIQUE_CONSTRAINTS = 'uniqueConstraints';
public const UNSIGNED = 'unsigned';
public const UI_CONFIG = 'uiconfig';
/**
* define which feature is required to enable field or filter
*/
public const UI_CONFIG_FEATURE = 'feature';
public const UI_CONFIG_LAYOUT_SMALL = 'small';
public const UI_CONFIG_LAYOUT_MEDIUM = 'medium';
public const UI_CONFIG_LAYOUT_BIG = 'big';
Expand Down
5 changes: 4 additions & 1 deletion tine20/Tinebase/js/ApplicationStarter.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ Ext.apply(Tine.Tinebase.ApplicationStarter,{
Tine.log.error('Application ' + owningAppName + ' not found!');
return null;
}

const feature = _.get(fieldconfig, 'uiconfig.feature')
if (feature && !Tine.Tinebase.featureEnabled(feature.feature, feature.appName)) {
return null;
}
// check right on foreign app
if (fieldconfig && (fieldconfig.type == 'record' || fieldconfig.type == 'records')) {
var opt = fieldconfig.config;
Expand Down
5 changes: 5 additions & 0 deletions tine20/Tinebase/js/widgets/form/FieldManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ Tine.widgets.form.FieldManager = function() {
return null;
}

const feature = _.get(fieldDefinition, 'uiconfig.feature')
if (feature && !Tine.Tinebase.featureEnabled(feature.feature, feature.appName)) {
return null;
}

return this.getByFieldDefinition(fieldDefinition, category, config);
},

Expand Down
9 changes: 9 additions & 0 deletions tine20/Tinebase/js/widgets/grid/ColumnManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ Tine.widgets.grid.ColumnManager = function() {
if (! app) return null;

if (fieldDefinition) {
if (_.get(fieldDefinition, 'disabled') || _.get(fieldDefinition, 'uiconfig.disabled')) {
return null;
}

const feature = _.get(fieldDefinition, 'uiconfig.feature')
if (feature && !Tine.Tinebase.featureEnabled(feature.feature, feature.appName)) {
return null;
}

if (['text', 'fulltext'].indexOf(fieldDefinition.type) >= 0) {
config.hidden = true;
}
Expand Down

0 comments on commit 036d6ba

Please sign in to comment.