Improved the permissions adding behaviour so that no permissions tab will be added if no permissions are set in a view. gh-629

This commit is contained in:
Llewellyn van der Merwe 2020-12-24 18:28:07 +02:00
parent 3bd2158b83
commit cc201b8ec0
Signed by untrusted user: Llewellyn
GPG Key ID: EFC0C720A240551C
6 changed files with 91 additions and 25 deletions

View File

@ -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**

View File

@ -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**

View File

@ -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
*

View File

@ -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';

View File

@ -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"

View File

@ -82,25 +82,6 @@ $componentParams = $this->params; // will be removed just use $this->params inst
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php if ($this->canDo->get('core.admin')) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'help_documentTab', 'permissions', JText::_('COM_COMPONENTBUILDER_HELP_DOCUMENT_PERMISSION', true)); ?>
<div class="row-fluid form-horizontal-desktop">
<div class="span12">
<fieldset class="adminform">
<div class="adminformlist">
<?php foreach ($this->form->getFieldset('accesscontrol') as $field): ?>
<div>
<?php echo $field->label; echo $field->input;?>
</div>
<div class="clearfix"></div>
<?php endforeach; ?>
</div>
</fieldset>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
<div>