By seth97 on
How can I do so that auto complete ignores the access restrictions?
I have taxonomy fields in my user profile that are using the autocomplete function. If I restrict the access of anonymous users so that they are not allowed to access content I get the error message from auto complete:
"An HTTP error 403 occured.
http//www.example.com/taxonomy/autocomplete/11"
Is there any way to override the access restriction for auto complete, so that anonymous users also gets the information when filling out the fields?
Thanks!
Comments
It it is possible to
It it is possible to override the default menu access permissions by redefining a menu path (with the permissions you require) *after* the default path is already defined. This is described in detail in the Drupal Pro Development book http://www.drupalbook.com/. The easiest way IIRC is to use hook_menu() in a custom module and put the relevant menu item definition in a
if (!$may_cache) {}code block (so that your definition is not cached and hence overrides the default, cached definition which is presumably in taxonomy.module).gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Hi gpk, Thanks for your
Hi gpk,
Thanks for your response!
I have the Drupal Pro Development book, although I am not a pro developer!
I don't know where auto complete gets the access control.
I tired the module Taxonomy Access Control. Even if I give anonymous user access to View, Update, Delete, Create and List a category, the user will get the error message that autocomplete has failed.
So, I don't know if playing around with the access control to taxonomy will help me or if I should try to define something for auto complete.
Thanks!
Access control on paths
Access control on paths (such as taxonomy/autocomplete/...) is set up in hook_menu(). So looking in taxonomy_menu() in taxonomy.module I see
Now turn to p. 44 of the book. In your own mymodule_menu() you will want to set 'access' = TRUE.
QED! (Assuming you are comfortable creating a simple module ... it's really not hard.)
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
I tried this....
Hi gpk!
I tried creating this module (mymenu.module), but I got the same auto complete error as before. What am I doing wrong?
Thanks!
Put a ! immediately before
Put a ! immediately before $may_cache, so that your menu definition is *not* cached.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
still does not work...
I tired that but it didn't work, still the same error message.
Any ideas?
Thanks!
You need to return
You need to
return $items;.gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
no luck...
This is how my module looks now, but it still doesn't work?
Thanks!
Hmmm looks OK...
Hmmm looks OK...
1. Is your module enabled?
2. Do you have any taxonomy access control operating on the site?
3. May be time to start troubleshooting. Try setting the callback to be a simple function within your module with 2 arguments ($vid, $string='') and use
drupal_set_message("Hello, vid=$vid and string='$string'");or somesuch to ensure that your callback is getting called with the right arguments. Other similar simple tests can be done... e.g. make sure the menu hook is being called etc.You can also access the autocompletion info at taxonomy/autocomplete/vid/string, e.g. taxonomy/autocomplete/1/e
By the way how do you get
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
my module now....
My user profile is based on Michelle's tutorial version 2:
http://shellmultimedia.com/tutorials/user-profiles
1) The module is enabled.
2) I do not have taxonomy access control operating on the site.
3) I tried what you suggested (I think?). I get the message Hello, vid= and string='test' on every page.
This is the module I am using:
If I access taxonomy/autocomplete/15/U937 I get Access denied for anonymous users but I get access for a normal user.
Ah hmmm almost but not quite
Ah hmmm almost but not quite what I had in mind!!! At least we are sure the menu hook is being called since you get the diag. message on every page view! :-D
Try the following (untested) .module code (but preferably omit the closing ?>):
It might also be worth clearing table cache_menu though this should not really make a difference I think.
If necessary I may have to try this ...! Also conceivably the profile modules/setup could be making a difference somewhere.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
doesn't work...
Thanks for all your work!
But it still doesn't work....
If I login as an authenticated user and go to:
MY_SITE/taxonomy/autocomplete/15/U937
I get an empty page with the text:
{ "U937": "U937" }
After that I get the message at the top of the next page:
About to call taxonomy_autocomplete() with vid=15 and string='U937'
If I am an anonymous users and go to:
MY_SITE/taxonomy/autocomplete/15/U937
I get the message:
'Access denied
You are not authorized to access this page.'
Thanks!
I get the message: 'Access
In this case do you still get the message from the wrapper on the next full pageview?
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
The solution
OK the problem appears to be that non-cached menu items don't completely overwrite cached items if they share the same path. In particular, the original 'access' key is not overwritten.
The answer is therefore to use a cached menu item but to set the module's weight in the {system} table to be greater than than that of the taxonomy module. A weight of 1 is sufficient. The revised menu definition for the path does then completely overwrite the original definition.
As well as this .module file:
you will need this .install file:
You will need to disable the module and then completely uninstall it using the Uninstall tab on the modules listing page before re-enabling it.
Note that any change you might make to the definition of a cached menu item e.g. in mymenu_menu() won't take effect until after the table {menu_cache} is cleared. You can either do this manually, or with devel.module, or by submitting the modules admin page.
An interesting little problem, this one ;-)
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
It works !
Great work GPK!
I am impressed by your knowledge! I have been struggling with this for quite some time!
Thank you very much!!!
Seth
>knowledge
>knowledge
Nah, it's just a matter of knowing where to look. In this case, menu.inc --> specifically, http://api.drupal.org/api/function/_menu_append_contextual_items/5, and the Note near the top of p.45 of the Pro book. And also suspecting that pp. 44 - 45 might not be telling the whole truth...
What gave the game away was testing different settings in mymenu_menu() and finding that the 'access' key was having no effect whatsoever on any user, be they logged in or anonymous.
Glad to have helped anyway, and learnt a bit myself.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
How to use these
So how do I use these? I get that they are part of a module, but what module?
Am I supposed to make a new module? Do these replace those files of a module? Do I paste this code into the .install & .module files of an existing module?
Sounds like the solution I need, but how do I implement in Drupal 6?
new module
Yes, it is a new module!
It does not replace anything, create a totally new module!
I have no idea if it works with D6, I am running it on D5.....
You would also need to
You would also need to create a .info file for your module "mymenu".
The code here only works on D5. D6 has a new menu system, and all you would need to do is implement http://api.drupal.org/api/function/hook_menu_alter/6 in the custom new module. No .install file would be needed.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Also see core issue #284887:
Also see core issue #284887: Check for access to autocomplete paths during form building