From cc201b8ec0b99ddda1f49d8b57c44e3b2088903e Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 24 Dec 2020 18:28:07 +0200 Subject: [PATCH] Improved the permissions adding behaviour so that no permissions tab will be added if no permissions are set in a view. gh-629 --- README.md | 2 +- admin/README.txt | 2 +- admin/helpers/compiler/c_Fields.php | 88 ++++++++++++++++++- admin/helpers/compiler/e_Interpretation.php | 4 +- .../en-GB/en-GB.com_componentbuilder.ini | 1 - admin/views/help_document/tmpl/edit.php | 19 ---- 6 files changed, 91 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3b7700d46..8336ce489 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ TODO + *Version*: 2.12.3 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **290895** ++ *Line count*: **290875** + *Field count*: **1601** + *File count*: **1923** + *Folder count*: **316** diff --git a/admin/README.txt b/admin/README.txt index 3b7700d46..8336ce489 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -147,7 +147,7 @@ TODO + *Version*: 2.12.3 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **290895** ++ *Line count*: **290875** + *Field count*: **1601** + *File count*: **1923** + *Folder count*: **316** diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 541ec1f71..e178895fa 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -46,6 +46,13 @@ class Fields extends Structure */ public $layoutBuilder = array(); + /** + * permissions builder + * + * @var array + */ + public $hasPermissions = array(); + /** * used to fix the zero order * @@ -865,7 +872,8 @@ class Fields extends Structure } // fix the permissions field "title" issue gh-629 // check if the the title is not already set - if (!isset($this->fieldsNames[$nameSingleCode]['title'])) + if (!isset($this->fieldsNames[$nameSingleCode]['title']) + && $this->hasPermissionsSet($view, $nameSingleCode)) { // set the field/tab name $field_name = "title"; @@ -1299,7 +1307,8 @@ class Fields extends Structure } // fix the permissions field "title" issue gh-629 // check if the the title is not already set - if (!isset($this->fieldsNames[$nameSingleCode]['title'])) + if (!isset($this->fieldsNames[$nameSingleCode]['title']) + && $this->hasPermissionsSet($view, $nameSingleCode)) { // set the field/tab name $field_name = "title"; @@ -1455,6 +1464,81 @@ class Fields extends Structure return $this->xmlPrettyPrint($XML, 'fieldset'); } + /** + * Check to see if a view has permissions + * + * @param array $view View details + * @param string $nameSingleCode View Single Code Name + * + * @return boolean true if it has permisssions + * + */ + protected function hasPermissionsSet(&$view, &$nameSingleCode) + { + // first check if we have checked this already + if (!isset($this->hasPermissions[$nameSingleCode])) + { + // default is false + $this->hasPermissions[$nameSingleCode] = false; + // when a view has history, it has permissions + // since it tracks the version access + if (isset($view['history']) && $view['history'] == 1) + { + // set the permission for later + $this->hasPermissions[$nameSingleCode] = true; + // break out here + return true; + } + // check if the view has permissions + if (isset($view['settings']) + && ComponentbuilderHelper::checkArray( + $view['settings']->permissions + )) + { + foreach ($view['settings']->permissions as $per) + { + // check if the permission targets the view + // 1 = view + // 3 = both view & component + if (isset($per['implementation']) + && ( + $per['implementation'] == 1 + || $per['implementation'] == 3 + )) + { + // set the permission for later + $this->hasPermissions[$nameSingleCode] = true; + // break out here + return true; + } + } + } + // check if the fields has permissions + if (isset($view['settings']) + && ComponentbuilderHelper::checkArray( + $view['settings']->fields + )) + { + foreach ($view['settings']->fields as $field) + { + // if a field has any permissions + // the a view has permissions + if (isset($field['permission']) + && ComponentbuilderHelper::checkArray( + $field['permission'] + )) + { + // set the permission for later + $this->hasPermissions[$nameSingleCode] = true; + // break out here + return true; + } + } + } + } + return $this->hasPermissions[$nameSingleCode]; + } + /** * set Field Names * diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 35a98d8ab..1170315dd 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -13393,7 +13393,9 @@ class Interpretation extends Fields } // make sure we dont load it to a view with the name component (as this will cause conflict with Joomla conventions) - if ($nameSingleCode != 'component') + if ($nameSingleCode != 'component' + && isset($this->hasPermissions[$nameSingleCode]) + && $this->hasPermissions[$nameSingleCode]) { // set permissions tab lang $tabLangName = $langView . '_PERMISSION'; diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index d825f5db3..e820b4dda 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -5678,7 +5678,6 @@ COM_COMPONENTBUILDER_HELP_DOCUMENT_MODIFIED_DATE_LABEL="Modified Date" COM_COMPONENTBUILDER_HELP_DOCUMENT_NEW="A New Help Document" COM_COMPONENTBUILDER_HELP_DOCUMENT_NOT_REQUIRED="Not Required" COM_COMPONENTBUILDER_HELP_DOCUMENT_ORDERING_LABEL="Ordering" -COM_COMPONENTBUILDER_HELP_DOCUMENT_PERMISSION="Permissions" COM_COMPONENTBUILDER_HELP_DOCUMENT_PUBLISHING="Publishing" COM_COMPONENTBUILDER_HELP_DOCUMENT_SAVE_WARNING="Alias already existed so a number was added at the end. You can re-edit the Help Document to customise the alias." COM_COMPONENTBUILDER_HELP_DOCUMENT_SELECT_AN_OPTION="Select an option" diff --git a/admin/views/help_document/tmpl/edit.php b/admin/views/help_document/tmpl/edit.php index abb668680..d5638e5c8 100644 --- a/admin/views/help_document/tmpl/edit.php +++ b/admin/views/help_document/tmpl/edit.php @@ -82,25 +82,6 @@ $componentParams = $this->params; // will be removed just use $this->params inst - canDo->get('core.admin')) : ?> - -
-
-
-
- form->getFieldset('accesscontrol') as $field): ?> -
- label; echo $field->input;?> -
-
- -
-
-
-
- - -