Bug: In the Helper's addSubmenu() method, custom admin views have the wrong permission names #910

Closed
opened 2022-05-08 17:27:48 +00:00 by Obscerno · 10 comments
Obscerno commented 2022-05-08 17:27:48 +00:00 (Migrated from github.com)

Specifically, it uses the view name instead of the in-code name to generate the permissions. An example from one of my projects:

if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents'))
{
    JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_HAPPENINGS'), 'index.php?option=com_efevents&view=happenings', $submenu === 'happenings');
}

The line

$user->authorise('generate_northern_happenings.submenu', 'com_efevents')

should be:

$user->authorise('happenings.submenu', 'com_efevents')

I added custom REPLACE code to make that change in my project and it fixed it for me!

Specifically, it uses the view name instead of the in-code name to generate the permissions. An example from one of my projects: if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents')) { JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_HAPPENINGS'), 'index.php?option=com_efevents&view=happenings', $submenu === 'happenings'); } The line `$user->authorise('generate_northern_happenings.submenu', 'com_efevents')` should be: `$user->authorise('happenings.submenu', 'com_efevents')` I added custom REPLACE code to make that change in my project and it fixed it for me!
Obscerno commented 2022-05-08 18:04:41 +00:00 (Migrated from github.com)

Just adding: to reproduce, you can't be logged in as a superuser. You have to be a lower-level user who has permission to access the backend and access the custom admin view.

If you're a superuser, authorise() will return true even if the permission doesn't exist.

Just adding: to reproduce, you can't be logged in as a superuser. You have to be a lower-level user who has permission to access the backend and access the custom admin view. If you're a superuser, authorise() will return true even if the permission doesn't exist.

There is already an issue open on this, we will keep the conversation on this issue 885

There is already an issue open on this, we will keep the conversation on this [issue 885](https://github.com/vdm-io/Joomla-Component-Builder/issues/885)

Okay seems like its not related... sorry. before I can say more. Your pointing out that the name is incorrect, yet this name can not be incorrect as it directly used the edit view name. So we will need to look closer at what your trying to do here.

Okay seems like its not related... sorry. before I can say more. Your pointing out that the name is incorrect, yet this name can not be incorrect as it directly used the edit view name. So we will need to look closer at what your trying to do here.
Obscerno commented 2022-05-09 15:20:28 +00:00 (Migrated from github.com)

Okay here are some more details. Here's my custom admin view settings:

Screenshot from 2022-05-09 11-03-25

And here is what a non-admin sees when using the component (they have all of the permissions):

Screenshot from 2022-05-09 11-12-15

You can see that the field "Generate Northern Happenings" is available in the menu up top, but it's not available in the sidebar menu below. I want it to appear in that submenu. I found out that in the helper JBC creates this function:

/**
 * Configure the Linkbar.
 */
public static function addSubmenu($submenu)
{
	// load user for access menus
	$user = JFactory::getUser();
	// load the submenus to sidebar

	if ($user->authorise('event.access', 'com_efevents') && $user->authorise('event.submenu', 'com_efevents'))
	{
		JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_EVENTS'), 'index.php?option=com_efevents&view=events', $submenu === 'events');
		JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_EVENT_EVENTS_CATEGORIES'), 'index.php?option=com_categories&view=categories&extension=com_efevents.event', $submenu === 'categories.event');
	}
	if ($user->authorise('location.access', 'com_efevents') && $user->authorise('location.submenu', 'com_efevents'))
	{
		JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_LOCATIONS'), 'index.php?option=com_efevents&view=locations', $submenu === 'locations');
	}
	if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents'))
	{
		JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_HAPPENINGS'), 'index.php?option=com_efevents&view=happenings', $submenu === 'happenings');
	}
}

That last bit has the code: $user->authorise('generate_northern_happenings.submenu', 'com_efevents'). And generate_northern_happenings.submenu is where the problem is. It should say happenings.submenu.

Okay here are some more details. Here's my custom admin view settings: ![Screenshot from 2022-05-09 11-03-25](https://user-images.githubusercontent.com/33399601/167439520-94f32967-5f65-47eb-843a-eb5015f589d5.png) And here is what a non-admin sees when using the component (they have all of the permissions): ![Screenshot from 2022-05-09 11-12-15](https://user-images.githubusercontent.com/33399601/167440942-e0d668de-d060-4c5e-8916-94304254d3b5.png) You can see that the field "Generate Northern Happenings" is available in the menu up top, but it's not available in the sidebar menu below. I want it to appear in that submenu. I found out that in the helper JBC creates this function: /** * Configure the Linkbar. */ public static function addSubmenu($submenu) { // load user for access menus $user = JFactory::getUser(); // load the submenus to sidebar if ($user->authorise('event.access', 'com_efevents') && $user->authorise('event.submenu', 'com_efevents')) { JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_EVENTS'), 'index.php?option=com_efevents&view=events', $submenu === 'events'); JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_EVENT_EVENTS_CATEGORIES'), 'index.php?option=com_categories&view=categories&extension=com_efevents.event', $submenu === 'categories.event'); } if ($user->authorise('location.access', 'com_efevents') && $user->authorise('location.submenu', 'com_efevents')) { JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_LOCATIONS'), 'index.php?option=com_efevents&view=locations', $submenu === 'locations'); } if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents')) { JHtmlSidebar::addEntry(JText::_('COM_EFEVENTS_SUBMENU_HAPPENINGS'), 'index.php?option=com_efevents&view=happenings', $submenu === 'happenings'); } } That last bit has the code: `$user->authorise('generate_northern_happenings.submenu', 'com_efevents')`. And `generate_northern_happenings.submenu` is where the problem is. It should say `happenings.submenu`.

Okay you may be aware of our predicament with "my" yearly years of creativity... lol. So we have a compiler that can only best be described as a beastly kind of a perfectionist, anyhow... to matters at hand, we have a methods called setSubMenus, addCustomSubMenu, and setCustomAdminSubMenu in the e_Interpretation class that really is the main actor in building the submenu. Since we can't view the e_Interpretation class "the predicament" on github... (only here) You could also have a look at it on your local system...

Now let us consider the matter, and you will see our actions are in fact correct... and that Joomla at its best day is a moving mass of self serving ambition of well meaning elephant like behavior that has but one result... deforestation! By that I mean, they break down things without admittance to the dependencies other may have of the now not so strong older trees... lol

Okay so the menu, side-bar work as expected, as this is how Joomla use to work... and so JCB controllers this side bar, and that is why it still works... o boy I am already frustrated at just the thought of this ingenious change...

Where as the permissions and access layer of the internal menu of Joomla seems to have changed to no longer work the way it use to before. These two areas are actually unrelated... but okay in truth they should behave the same and this is how it use to work. To test, pull an old Joomla 3.9.x version up of Joomla and you will see what I mean.

Back to modern day elephant circus and its adventures... JCB does not control the main menu behavior, this is all Joomla based on the menus added to the XML of your component, for example this xml.

As you can see it makes use of the plural views name, and so all Joomla has to work with is this view= value to get permissions and all set, which should be okay, yet I see your component has the view name, and not the code name as permissions....

So looking at the the methods I mentioned above, this does not make sense as in all places we are working with the code name... which is making me wonder if you have some other view with the same name? admin view or custom menu? as this will explain the weird behavior... as at this point I can still not see any explanation for this wrong code if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents')) as going over those methods... for years now I do not see the bug...

Here we get the $nameSingle value...
image

Here we build the permissions:
image
or here (depending on how you setup your permissions in the view)
image

Which in both cases use the correct $nameSingle value... so this makes me think it is a setup error, of another nature.

So first lets make sure you have the following option set:
image

When adding the custom admin view to your component, do you have access selected?

Okay you may be aware of our predicament with "my" yearly years of creativity... lol. So we have a compiler that can only best be described as a beastly kind of a perfectionist, anyhow... to matters at hand, we have a methods called `setSubMenus`, `addCustomSubMenu`, and `setCustomAdminSubMenu` in the `e_Interpretation` class that really is the main actor in building the submenu. Since we can't view the `e_Interpretation` class "the predicament" on github... ([only here](https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/admin/helpers/compiler/e_Interpretation.php)) You could also have a look at it on your local system... Now let us consider the matter, and you will see our actions are in fact correct... and that Joomla at its best day is a moving mass of self serving ambition of well meaning elephant like behavior that has but one result... deforestation! By that I mean, they break down things without admittance to the dependencies other may have of the now not so strong older trees... lol Okay so the menu, `side-bar` work as expected, as this is **how Joomla use to work**... and so JCB controllers this **_side bar_**, and that is why it still works... o boy I am already frustrated at just the thought of this ingenious change... Where as the permissions and access layer of the internal menu of Joomla seems to have changed to no longer work the way it use to before. These two areas are actually unrelated... but okay in truth they should behave the same and this is how it use to work. To test, pull an old Joomla 3.9.x version up of Joomla and you will see what I mean. Back to modern day elephant circus and its adventures... JCB does not control the main menu behavior, this is all Joomla based on the menus added to the XML of your component, for [example this xml](https://github.com/Llewellynvdm/Joomla-Sermon-Distributor/blob/master/sermondistributor.xml#L75). As you can see it makes use of the plural views name, and so all Joomla has to work with is this `view=` value to get permissions and all set, which should be okay, yet I see your component has the `view name`, and not the `code name` as permissions.... So looking at the the methods I mentioned above, this does not make sense as in all places we are working with the code name... which is making me wonder if you have some other view with the same name? admin view or custom menu? as this will explain the weird behavior... as at this point I can still not see any explanation for this wrong code `if ($user->authorise('generate_northern_happenings.submenu', 'com_efevents'))` as going over those methods... for years now I do not see the bug... Here we get the `$nameSingle` value... ![image](https://user-images.githubusercontent.com/5607939/167571566-0bc1501b-ea36-4edf-a7f9-f981e09c051b.png) Here we build the permissions: ![image](https://user-images.githubusercontent.com/5607939/167571766-ed0752a0-c1f5-4980-b194-c0bb90f235cb.png) or here (depending on how you setup your permissions in the view) ![image](https://user-images.githubusercontent.com/5607939/167571988-a1a9540f-8a31-4002-89d2-1744907e57d1.png) Which in both cases use the correct `$nameSingle` value... so this makes me think it is a setup error, of another nature. So first lets make sure you have the following option set: ![image](https://user-images.githubusercontent.com/5607939/167572951-791a946a-6a1a-474d-b8d6-4d58b0ba23dc.png) When adding the custom admin view to your component, do you have access selected?
Obscerno commented 2022-05-10 17:56:10 +00:00 (Migrated from github.com)

I did not have access enabled! But I just enabled it and it didn't change anything in my project. I still can't see the submenu when logged in as a non-administrator (I checked to make sure the user had all the permissions).

That said, I messed around with JCB's compiler code and I think I narrowed it down to this line: https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/admin/helpers/compiler/e_Interpretation.php#L23927

It is only run when, in the component, a custom admin view is added and "Order Before" is not set:

Screenshot from 2022-05-10 13-51-43

I did not have access enabled! But I just enabled it and it didn't change anything in my project. I still can't see the submenu when logged in as a non-administrator (I checked to make sure the user had all the permissions). That said, I messed around with JCB's compiler code and I think I narrowed it down to this line: https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/admin/helpers/compiler/e_Interpretation.php#L23927 It is only run when, in the component, a custom admin view is added and "Order Before" is not set: ![Screenshot from 2022-05-10 13-51-43](https://user-images.githubusercontent.com/33399601/167691716-dfba7348-30b0-422c-ada7-0fe1665f0daa.png)

The reality is for me to debug this I need to see the xml access file generated, and to component xml file, and then it still may not be all that clear to me. At this point I do not consider this to be a bug... but a setting issue.

The reality is for me to debug this I need to see the xml access file generated, and to component xml file, and then it still may not be all that clear to me. At this point I do not consider this to be a bug... but a setting issue.
Obscerno commented 2022-05-11 15:26:47 +00:00 (Migrated from github.com)

I can send a JCB Package for the component if that would help? If not, I'll at least attach those XML files:

xml files.zip

I can send a JCB Package for the component if that would help? If not, I'll at least attach those XML files: [xml files.zip](https://github.com/vdm-io/Joomla-Component-Builder/files/8671285/xml.files.zip)

Please connect with me in the JCB group on Telegram, so we can arrange a chat.

Please connect with me in the [JCB group on Telegram](https://t.me/jcb_group), so we can arrange a chat.

As I think looking in a screen-share at your setup and may resolve this.... Telegram has these options and makes it very easy to quickly respond to your issue. As this does seem like a configuration issue, and not a bug.

As I think looking in a screen-share at your setup and may resolve this.... Telegram has these options and makes it very easy to quickly respond to your issue. As this does seem like a configuration issue, and not a bug.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#910
No description provided.