User check on getItems #29

Closed
opened 2016-12-28 20:35:41 +00:00 by mwweb · 7 comments
mwweb commented 2016-12-28 20:35:41 +00:00 (Migrated from github.com)

I've been trying to figure out where I may be going wrong with this, and figured that I would finally ask, after having spend many many hours on it.

In the site view models, there is auto-generated code that does permission checks to see if the user is able to access the item. It is similar to this:

                // check if this user has permission to access items
                if (!$user->authorise('site.categories.access', '{{my component}}'))
                {
			$app = JFactory::getApplication();
			$app->enqueueMessage(JText::_('Not authorised!'), 'error');
			// redirect away if not a correct (TODO for now we go to default view)
			$app->redirect(JRoute::_('index.php?option={{my componet}}&view=categories'));
			return false;
                } 

That code is causing a redirect loop, and looking between code on sermon distributor, and what I'm working on, I can't find the cause. Of course, if I manually comment out that section of code, it works fine, which is telling me that it is having difficulty finding the access.

Any suggestions?

And, I tested with sermon distributor, and I get the same "too many redirects" error.

I've been trying to figure out where I may be going wrong with this, and figured that I would finally ask, after having spend many many hours on it. In the site view models, there is auto-generated code that does permission checks to see if the user is able to access the item. It is similar to this: ``` // check if this user has permission to access items if (!$user->authorise('site.categories.access', '{{my component}}')) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('Not authorised!'), 'error'); // redirect away if not a correct (TODO for now we go to default view) $app->redirect(JRoute::_('index.php?option={{my componet}}&view=categories')); return false; } ``` That code is causing a redirect loop, and looking between code on sermon distributor, and what I'm working on, I can't find the cause. Of course, if I manually comment out that section of code, it works fine, which is telling me that it is having difficulty finding the access. Any suggestions? And, I tested with sermon distributor, and I get the same "too many redirects" error.

please do not mix two issues... I will only answer the first question, please open another issue for the second... :)

Okay let me explain....

please do not mix two issues... I will only answer the first question, please open another issue for the second... :) Okay let me explain....

In your code you will see that categories is the default view... and therefore the loop...

In your component you can set what front-end view is the default view (component->settings tab->Site Views->Default View), and for this view you must give public access (once the component is installed) to avoid a loop. Mainly because if a user open a front-end view that he does not have access to it will redirect him to the default view, and show a warning. Therefore if the default view is also not accessible it will cause a loop, redirecting to itself over and over and over....

You will see there is a TODO note in the code as we may want to improve this in the future... but for now that is how it works.

In your code you will see that `categories` is the default view... and therefore the loop... In your component you can set what front-end view is the default view (component->settings tab->Site Views->Default View), and for this view you must give public access (once the component is installed) to avoid a loop. Mainly because if a user open a front-end view that he does not have access to it will redirect him to the default view, and show a warning. Therefore if the default view is also not accessible it will cause a loop, redirecting to itself over and over and over.... You will see there is a TODO note in the code as we may want to improve this in the future... but for now that is how it works.

I started working on a fix, to insure this loop does not happen... will be part of the next release.

I started working on a fix, to insure this loop does not happen... will be part of the next release.
mwweb commented 2016-12-29 19:38:34 +00:00 (Migrated from github.com)

I'm thinking that there may be more than just this. As a test, I took a clean install of Joomla, installed Sermon Distributor that I downloaded from GitHub (via extension.joomla.org), created a Sermon Category, added a menu item for Sermon Distributor->Categories, and one the frontend that menu item loops, resulting in "ERR_TOO_MANY_REDIRECTS".

In looking in Component Builder, I am noticing that in CB->Components->{your component}->Settings Tab->Admin Views, there are 2 columns: "Has Metadata" and "Add Access". Both of those columns do not have the radio selected. If I go through and select them, save, then save the component and go back to look at them, those radios are unselected again.

I'm thinking that there may be more than just this. As a test, I took a clean install of Joomla, installed Sermon Distributor that I downloaded from GitHub (via extension.joomla.org), created a Sermon Category, added a menu item for Sermon Distributor->Categories, and one the frontend that menu item loops, resulting in "ERR_TOO_MANY_REDIRECTS". In looking in Component Builder, I am noticing that in CB->Components->{your component}->Settings Tab->Admin Views, there are 2 columns: "Has Metadata" and "Add Access". Both of those columns do not have the radio selected. If I go through and select them, save, then save the component and go back to look at them, those radios are unselected again.

No there is not more too it, I think you don't understand... please watch this video

About the radio selection issue, open the pop-up close it and open it a second time, then it should show all as it is stored in the database. IF this does not resolves the issue, check the database to see what was stored... the selection issue is not a component builder issue but a repeatable field issue.

No there is not more too it, I think you don't understand... [please watch this video](https://youtu.be/lr22JpRLJaM) About the radio selection issue, open the pop-up close it and open it a second time, then it should show all as it is stored in the database. IF this does not resolves the issue, check the database to see what was stored... the selection issue is not a component builder issue but a repeatable field issue.
mwweb commented 2016-12-30 00:32:02 +00:00 (Migrated from github.com)

Thank you Llewellyn. That video actually helped a lot. It would be nice, eventually, to have the permissions for site views default to Allowed. This is how many components work. But this work around works. And, I tested by putting your fix in my code, manually, and that redirected nicely as well. As always, excellent support and help.

Enjoy the rest of the holiday. My new component should be entering beta sometime in January (hopefully), all built with Component Builder. Out of 12 admin views, they are all working, and out of 19 site views 17 have the basics in place. Still a matter of getting the model and view code into Component Builder, and work on a few details, but Component Builder makes things much nicer.

Thank you Llewellyn. That video actually helped a lot. It would be nice, eventually, to have the permissions for site views default to Allowed. This is how many components work. But this work around works. And, I tested by putting your fix in my code, manually, and that redirected nicely as well. As always, excellent support and help. Enjoy the rest of the holiday. My new component should be entering beta sometime in January (hopefully), all built with Component Builder. Out of 12 admin views, they are all working, and out of 19 site views 17 have the basics in place. Still a matter of getting the model and view code into Component Builder, and work on a few details, but Component Builder makes things much nicer.

Wow, that sounds great...

Wow, that sounds great...
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#29
No description provided.