Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Control access to component preferences individually #41496

Open
wants to merge 36 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a9f9fe
Update ExceptionHandler.php
MarkRS-UK Jun 27, 2022
298dae1
Merge pull request #1 from MarkRS-UK/MarkRS-UK-patch-1
MarkRS-UK Jun 27, 2022
0e86915
Merge branch '4.2-dev' into master
HLeithner Jun 27, 2022
7e1e53d
Merge branch '4.2-dev' into master
laoneo Jun 27, 2022
a2a04e5
Merge branch '4.2-dev' into master
richard67 Jun 28, 2022
5f35fd7
Merge branch 'joomla:4.2-dev' into master
MarkRS-UK Jul 18, 2022
3de0665
Merge branch 'joomla:4.3-dev' into master
MarkRS-UK Jun 14, 2023
2db4c95
Merge branch 'joomla:4.3-dev' into master
MarkRS-UK Aug 28, 2023
0b07115
Update HtmlView.php
MarkRS-UK Aug 28, 2023
15d1f74
Update HtmlView.php
MarkRS-UK Aug 28, 2023
3728966
Merge branch '4.3-dev' into preferences
MarkRS-UK Aug 28, 2023
188e6e4
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
f75609e
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
e41f642
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
ef6dead
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
757dbdc
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
ddef3a8
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 28, 2023
2c03800
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Aug 29, 2023
2bd57d4
Merge branch '4.3-dev' into preferences
MarkRS-UK Aug 29, 2023
7285ec2
Update ComponentModel.php
MarkRS-UK Aug 29, 2023
a0fd5ec
Update ComponentModel.php
MarkRS-UK Aug 29, 2023
3b378ad
Merge remote-tracking branch 'upstream/5.0-dev' into preferences
richard67 Aug 31, 2023
b97d43d
Merge branch '5.0-dev' into preferences
richard67 Sep 1, 2023
2fe9b18
Update administrator/components/com_config/src/View/Component/HtmlVie…
MarkRS-UK Sep 4, 2023
160f98b
Merge branch '5.0-dev' into preferences
QuyTon Sep 5, 2023
e9a2a63
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 6, 2023
972f437
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 6, 2023
0a2ac30
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 7, 2023
aa88a61
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 7, 2023
aec2e0f
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 7, 2023
76511b4
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 10, 2023
746b6e4
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 11, 2023
d7f0613
Merge branch '5.0-dev' into preferences
MarkRS-UK Sep 11, 2023
debb756
Merge branch '5.2-dev' into preferences
MarkRS-UK Apr 27, 2024
f4001e0
Merge branch '5.3-dev' into preferences
richard67 Sep 15, 2024
e9adbe5
Fix PHPCS
richard67 Sep 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion administrator/components/com_config/src/Model/ComponentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ public function save($data)
$context = $this->option . '.' . $this->name;
PluginHelper::importPlugin('extension');

// Check super user group.
// Check super user group and individual preference tab access
if (isset($data['params']) && !$this->getCurrentUser()->authorise('core.admin')) {
$form = $this->getForm([], false);

foreach ($form->getFieldsets() as $fieldset) {
$hasAccess = $this->getCurrentUser()->authorise("core.options.$fieldset");
foreach ($form->getFieldset($fieldset->name) as $field) {
if (
$field->type === 'UserGroupList' && isset($data['params'][$field->fieldname])
Expand All @@ -173,6 +174,9 @@ public function save($data)
) {
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
}
if (!$hasAccess && isset($data['params'][$field->fieldname])) {
unset($data['params'][$field->fieldname]);
}
}
}
}
Expand Down Expand Up @@ -212,6 +216,13 @@ public function save($data)

unset($data['id']);

// If the user only has access to a subset of preferences,
// merge these with the full preference set
$previous = (array)\json_decode($table->params);
if (\count($data['params'], COUNT_RECURSIVE) != \count($previous, COUNT_RECURSIVE)) {
$data['params'] = \array_merge($previous, $data['params']);
richard67 marked this conversation as resolved.
Show resolved Hide resolved
}

// Bind the data.
if (!$table->bind($data)) {
throw new \RuntimeException($table->getError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ public function display($tpl = null)
$this->fieldsets = $form ? $form->getFieldsets() : null;
$this->formControl = $form ? $form->getFormControl() : null;

// Don't show permissions fieldset if not authorised.
if (!$user->authorise('core.admin', $component->option) && isset($this->fieldsets['permissions'])) {
unset($this->fieldsets['permissions']);
// Remove unauthorised preference tabs.
foreach ($this->fieldsets as $key => $value) {
if ($key == 'permissions') {
MarkRS-UK marked this conversation as resolved.
Show resolved Hide resolved
if (
(!$user->authorise('core.admin', $component->option) || !$user->authorise('core.options.permission', $component->option))
&& isset($this->fieldsets['permissions'])
) {
unset($this->fieldsets['permissions']);
}
} else {
if (!$user->authorise("core.options.$key", $component->option) && isset($this->fieldsets[$key])) {
unset($this->fieldsets[$key]);
}
}
}

$this->form = &$form;
Expand Down
4 changes: 3 additions & 1 deletion build/media_source/system/js/fields/calendar.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@

if (window.innerHeight < containerTmp.getBoundingClientRect().bottom + 20) {
containerTmp.style.marginTop = - (containerTmp.getBoundingClientRect().height + this.inputField.getBoundingClientRect().height) + "px";
}
} else {
containerTmp.style.marginTop = 'initial';
}

this.processCalendar();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class JoomlaFieldMedia extends HTMLElement {
let type;
this.buttonClearEl.style.display = '';
this.previewElement.innerHTML = '';
const ext = getExtension(value);
const ext = getExtension(value).toLowerCase();

if (supportedExtensions.images.includes(ext)) type = 'images';
if (supportedExtensions.audios.includes(ext)) type = 'audios';
Expand Down
7 changes: 5 additions & 2 deletions build/media_source/system/js/fields/modal-fields.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@
iframeDocument = this.contentDocument;

// Validate the child form and update parent form.
if (iframeDocument.getElementById(idFieldId) && iframeDocument.getElementById(idFieldId).value != '0')
{
if (
iframeDocument.getElementById(idFieldId)
&& iframeDocument.getElementById(idFieldId).value != '0'
&& [].slice.call(iframeDocument.querySelectorAll('joomla-alert[type="danger"]')).length == 0
) {
window.processModalParent(fieldPrefix, iframeDocument.getElementById(idFieldId).value, iframeDocument.getElementById(titleFieldId).value);

// If Save & Close (save task), submit the edit close action (so we don't have checked out items).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
flex-direction: column;
justify-content: center;
padding: .8rem;
line-height: normal;
color: var(--white);
background: var(--alert-accent-color, var(--template-bg-dark));
align-content: center;
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
-- Templates
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
(0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, 1, '', '', '', 0, 0),
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, 1, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', '', 0, 0);
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, 1, '', '{"brand":"1","logoFile":"","siteTitle":"","siteDescription":"","useFontScheme":"0","colorName":"colors_standard","fluidContainer":"0","stickyHeader":0,"backTop":0}', '', 0, 0);

-- Files Extensions
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
-- Templates
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
(0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, 1, '', '', '', 0, 0),
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, 1, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', '', 0, 0);
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, 1, '', '{"brand":"1","logoFile":"","siteTitle":"","siteDescription":"","useFontScheme":"0","colorName":"colors_standard","fluidContainer":"0","stickyHeader":0,"backTop":0}', '', 0, 0);

-- Files Extensions
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
Expand Down
4 changes: 4 additions & 0 deletions libraries/src/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ public function addStyleSheet($url, $options = [], $attribs = [])
*/
public function addStyleDeclaration($content, $type = 'text/css')
{
if ($content === null) {
return $this;
}

$type = strtolower($type);

if (empty($this->_style[$type])) {
Expand Down
30 changes: 20 additions & 10 deletions libraries/src/Form/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,20 @@ public function renderField($options = [])
? ((string) $this->form->getXml()->config->inlinehelp['button'] == 'show' ?: false)
: false;

if ($this->showon) {
// Check if the field has showon in nested option
$hasOptionShowOn = false;

if (!empty((array) $this->element->xpath('option'))) {
foreach ($this->element->xpath('option') as $option) {
if ((string) $option['showon']) {
$hasOptionShowOn = true;

break;
}
}
}

if ($this->showon || $hasOptionShowOn) {
$options['rel'] = ' data-showon=\'' .
json_encode(FormHelper::parseShowOnConditions($this->showon, $this->formControl, $this->group)) . '\'';
$options['showonEnabled'] = true;
Expand Down Expand Up @@ -1279,17 +1292,12 @@ public function postProcess($value, $group = null, Registry $input = null)
*/
protected function getLayoutData()
{
// Label preprocess
$label = !empty($this->element['label']) ? (string) $this->element['label'] : null;
$label = $label && $this->translateLabel ? Text::_($label) : $label;

// Description preprocess
$label = !empty($this->element['label']) ? (string) $this->element['label'] : null;
$label = $label && $this->translateLabel ? Text::_($label) : $label;
$description = !empty($this->description) ? $this->description : null;
$description = !empty($description) && $this->translateDescription ? Text::_($description) : $description;

$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);

return [
$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);
$options = [
'autocomplete' => $this->autocomplete,
'autofocus' => $this->autofocus,
'class' => $this->class,
Expand Down Expand Up @@ -1319,6 +1327,8 @@ protected function getLayoutData()
'dataAttributes' => $this->dataAttributes,
'parentclass' => $this->parentclass,
];

return $options;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function setSender($from, $name = '')
*/
public function setSubject($subject)
{
$this->Subject = MailHelper::cleanLine($subject);
$this->Subject = MailHelper::cleanSubject($subject);

return $this;
}
Expand Down
22 changes: 17 additions & 5 deletions plugins/content/loadmodule/src/Extension/LoadModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ final class LoadModule extends CMSPlugin
*/
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
// Don't run this plugin when the content is being indexed
if ($context === 'com_finder.indexer') {
return;
}

// Only execute if $article is an object and has a text property
if (!is_object($article) || !property_exists($article, 'text') || is_null($article->text)) {
return;
Expand All @@ -69,6 +64,23 @@ public function onContentPrepare($context, &$article, &$params, $page = 0)
// Expression to search for(id)
$regexmodid = '/{loadmoduleid\s([1-9][0-9]*)}/i';

// Remove macros and don't run this plugin when the content is being indexed
if ($context === 'com_finder.indexer') {
if (str_contains($article->text, 'loadposition')) {
$article->text = preg_replace($regex, '', $article->text);
}

if (str_contains($article->text, 'loadmoduleid')) {
$article->text = preg_replace($regexmodid, '', $article->text);
}

if (str_contains($article->text, 'loadmodule')) {
$article->text = preg_replace($regexmod, '', $article->text);
}

return;
}

if (str_contains($article->text, '{loadposition ')) {
// Find all instances of plugin and put in $matches for loadposition
// $matches[0] is full pattern match, $matches[1] is the position
Expand Down