How to allow access to Ajax functions in SimpleVocab Plugin


#1

Hello all, I’m trying to create a custom page that shows a list of all the different Authors that are associated to items in the site, just like the SimpleVocab admin interface gives you. So i had the idea of creating a page that loaded the same Ajax request that returns the table with the list of all texts for a given item. For that, i used the SimplePages Plugin, and modified it according to http://interactivemechanics.com/2014/12/08/page-templates-omeka-simple-pages/.

At the moment, it works well, but it only shows if you are logged in as an admin or super user. After some research, i think the problem is that the request Url is available in /admin/simple-vocab/index/element-texts/format/html?element_id=39, so it blocks access to any non user. How could i give access to that URL to any visitor? I tried editing the hookDefineAcl() function in the SimpleVocabPlugin.php file, so it looks like this:

public function hookDefineAcl($args)
{
// Restrict access to super and admin users.
$args[‘acl’]->addResource(‘SimpleVocab_Index’);
$args[‘acl’]->allow(null, ‘SimpleVocab_Index’ );

}

I don’t know if i should reinstall the plugin, or if i’m missing a parameter in there.

Thanking you in advance.


#2

Do you actually have to be logged in as admin or super, or just logged in at all? In general, any admin/ URL will require you to be logged in, but the ACL you note should allow users of any role.

Using a public-side URL would remove the issue of logins being required.


#3

I slightly misunderstood the question, I somehow didn’t process you were just trying to use the existing AJAX action. You’ll have issues trying to get to that URL not in admin; the view for it is set up to be admin-only. Moving its view (views/admin/index/element-texts.ajax.php) from views/admin to views/shared should make the public URL actually work.


#4

Moved the view file, but its still not working. Should i also change the url for the Ajax request? I guess not since the page still loads fine while logged in.


#5

I’ll add here the details of the request:

  1. Request URL: /admin/simple-vocab/index/element-texts/format/html?element_id=39

  2. Request Method: GET

  3. Status Code: 302 Found

  4. Referrer Policy: no-referrer-when-downgrade

And the response:

  1. Cache-Control: no-store, no-cache, must-revalidate

  2. Connection: keep-alive

  3. Content-Encoding: gzip

  4. Content-Type: text/html; charset=UTF-8

  5. Date: Fri, 01 Feb 2019 21:54:20 GMT

  6. Expires: Thu, 19 Nov 1981 08:52:00 GMT

  7. Host-Header: 192fc2e7e50945beb8231a492d6a8024

  8. Location: /admin/users/login

  9. Pragma: no-cache

  10. Server: nginx

  11. Transfer-Encoding: chunked

  12. Vary: Accept-Encoding

  13. X-Proxy-Cache: BYPASS


#6

Yes, the URL of the request would have to change (to not have admin/ at the front).


#7

After removing /admin from the request URL, its still not working, but something strange occurs. Now, instead of redirecting to the login page when the Ajax request occurs, the response from the Ajax request is itself the html of the login page, which seems very strange to me.

Edit: Got it working after uncommenting the second statement in the hookDefineAcl function in SimpleVocabPlugin.php file. Thank you very much for your support.