View data export with custom table doesn't work if user is not admin

vn flag

I'm working on a Drupal 9 website displaying custom table data and I need to provide CSV/XLS export links for it.
For the moment, I've defined a view consuming the custom table data thanks to the Views Custom Table module and it works fine. I've installed the Views Data Export module and configured a display to export data as CSV. This display is attached to the base display.
The CSV button is show on the view, and when I'm logged in as admin, everything works fine. When I'm just an authenticated user, and I click on the button, the display attached to the CSV export is rendered and exported in CSV (so there is all the HTML in the file).

I think it is a permission issue: Export uses REST core module and this one is performing permission check on the entity (for example, user is able to access the entity). In my view, there is no entity because data comes from the View Custom Table module (through hook_data()).

I'm not sure if there is a simple solution, or if I need to define my own endpoint (and find a solution to keep exposed filters). Moreover, the Views Data Export PHPExcel module is not available for Drupal 8 and Drupal 9.

cn flag

If what you have done works when logged in as user 1 (Adminstrator), then that sounds like you need to tweak certain permissions and clear cache for it to take effect for the other "users" or "roles".

To test it out, i would create a test user and a role called "test role". Then make sure, you assign the test user to the test role. Then make sure, you give the "test role" what the module requires.... i see below in docs of view export table

You can also check if authenticated user/role has the following checked for it, if you don't want create the test user/role(/admin/people/permissions).

The below permissions come with the module, i suppose and you will see if after module install and cache clear etc.

  • Configure user permissions in Administration » People » Permissions:

    • Add custom table in views

      Give user access to add his custom table to the system.

    • Administer all custom table in views

      Give user access to administer all the custom tables, added by all the users

    • Administer own custom table in views

      Give user access to administer own custom tables

  • Manage custom tables in Administration » Structure » Views » View Custom Table men

Also, double check you have this configs for the data export module (specially #8)

Finally, login as the "test user" and check out out.

Check the logs if certain steps are not working (admin/reports/dblog)

vn flag
Thanks for your help @salah-1 ! The permissions of Views Custom Table only deal with custom tables definition in the backoffice, not with the export. But to be sure, I've done what you said and checked every permissions for an authenticated user. But the problem is still there (after clearing the cache) :/ When I check the logs, I see a notice : `Notice : Undefined index: #content_type dans Drupal\views_data_export\Plugin\views\display\DataExport::buildStandard() (/home/a-adamezyk/dev/orange-cmu/web/modules/contrib/views_data_export/src/Plugin/views/display/DataExport.php ligne 190)`
salah-1 avatar
cn flag
Do you have some kind of array? the error is pointing to undefined array index. Did you write that code? /home/a-adamezyk/dev/orange-cmu/web/modules/contrib/views_data_export/src/Plugin/views/display/DataExport.php? if so look at line 190. If you didn't write that code, then look closely as the content type or fields you defined.
vn flag
I have an array. For the admin, it contains the content_type + csv data. For authenticated user, no content_type and no csv data. I did not write this code, it is from views data export module. In this module, I see that a line is returning the good data for the admin, but not for other roles : `$output = (string) $renderer->renderRoot($build);` But I'm not able to understand why...

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.