[BUGFIX] Include file tables in access list 77/17377/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Fri, 28 Dec 2012 14:36:02 +0000 (15:36 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 5 Jan 2013 19:25:38 +0000 (20:25 +0100)
The BackendUtility::getExcludeFields method does not respect the
"ignoreRootLevelRestriction" configuration for these tables.
The result is that editors never see exclude fields as it is not
possible to set them in the access list in a backend group record.

Solution is to ignore the root level configuration if
"ignoreRootLevelRestriction" is also set in TCA.

This change also adds unit tests to check the fixed behavior
as well as the default behavior of this method.

Fixes: #44242
Releases: 6.0, 6.1

Change-Id: I2bb0d989028134388b24fa7ae4f139f2ebf8ee93
Reviewed-on: https://review.typo3.org/17377
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index 8129dd7..f64d154 100644 (file)
@@ -450,7 +450,10 @@ class BackendUtility {
                        // Load table
                        \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table);
                        // All field names configured and not restricted to admins
-                       if (is_array($GLOBALS['TCA'][$table]['columns']) && $GLOBALS['TCA'][$table]['ctrl']['adminOnly'] != 1 && $GLOBALS['TCA'][$table]['ctrl']['rootLevel'] != 1) {
+                       if (is_array($GLOBALS['TCA'][$table]['columns'])
+                                       && empty($GLOBALS['TCA'][$table]['ctrl']['adminOnly'])
+                                       && (empty($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) || !empty($GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction']))
+                       ) {
                                $f_keys = array_keys($GLOBALS['TCA'][$table]['columns']);
                                foreach ($f_keys as $field) {
                                        if ($GLOBALS['TCA'][$table]['columns'][$field]['exclude']) {
@@ -491,7 +494,7 @@ class BackendUtility {
                        }
                }
                // Sort fields by label
-               usort($theExcludeArray, array(t3lib_TCEforms_Flexforms, 'compareArraysByFirstValue'));
+               usort($theExcludeArray, array('TYPO3\\CMS\\Backend\\Form\\FlexFormsHelper', 'compareArraysByFirstValue'));
                return $theExcludeArray;
        }
 
@@ -4094,4 +4097,4 @@ class BackendUtility {
 }
 
 
-?>
+?>
\ No newline at end of file
index cd277be..ef6d755 100644 (file)
@@ -341,6 +341,112 @@ class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', Utility\BackendUtility::getFuncCheck('params', 'test', TRUE));
        }
 
+       /**
+        * Tests concerning getExcludeFields
+        */
+
+       /**
+        * @return array
+        */
+       public function getExcludeFieldsDataProvider() {
+               return array(
+                       'getExcludeFields does not return fields not configured as exclude field' => array(
+                               array(
+                                       'tx_foo' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foo',
+                                               ),
+                                               'columns' => array(
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       ),
+                                                       'baz' => array(
+                                                               'label' => 'bar',
+                                                       ),
+                                               )
+                                       )
+                               ),
+                               array(
+                                       array(
+                                               'foo: bar',
+                                               'tx_foo:bar',
+                                       ),
+                               )
+                       ),
+                       'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
+                               array(
+                                       'tx_foo' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foo',
+                                                       'rootLevel' => TRUE,
+                                                       'security' => array(
+                                                               'ignoreRootLevelRestriction' => TRUE,
+                                                       ),
+                                               ),
+                                               'columns' => array(
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       ),
+                                               )
+                                       )
+                               ),
+                               array(
+                                       array(
+                                               'foo: bar',
+                                               'tx_foo:bar',
+                                       ),
+                               )
+                       ),
+                       'getExcludeFields does not return fields from root level tables' => array(
+                               array(
+                                       'tx_foo' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foo',
+                                                       'rootLevel' => TRUE,
+                                               ),
+                                               'columns' => array(
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       ),
+                                               )
+                                       )
+                               ),
+                               array()
+                       ),
+                       'getExcludeFields does not return fields from admin only level tables' => array(
+                               array(
+                                       'tx_foo' => array(
+                                               'ctrl' => array(
+                                                       'title' => 'foo',
+                                                       'adminOnly' => TRUE,
+                                               ),
+                                               'columns' => array(
+                                                       'bar' => array(
+                                                               'label' => 'bar',
+                                                               'exclude' => 1
+                                                       ),
+                                               )
+                                       )
+                               ),
+                               array()
+                       ),
+               );
+       }
+
+       /**
+        * @param $tca
+        * @param $expected
+        *
+        * @test
+        * @dataProvider getExcludeFieldsDataProvider
+        */
+       public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
+               $GLOBALS['TCA'] = $tca;
+               $this->assertSame($expected, \TYPO3\CMS\Backend\Utility\BackendUtility::getExcludeFields());
+       }
 }
 
 ?>
\ No newline at end of file