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 all 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']);
}

// 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 @@ -108,9 +108,20 @@ public function display($tpl = null)
$this->fieldsets = $this->form ? $this->form->getFieldsets() : null;
$this->formControl = $this->form ? $this->form->getFormControl() : null;

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

$this->components = ConfigHelper::getComponentsWithConfig();
Expand Down