Page 1 of 1

Restrict export options

Posted: Sat Mar 02, 2024 3:59 am
by daveb

I would like to stop exports of large files to avoid timeouts. The page is used for multiple purposes so requiring search criteria does not work. I would like to do this by checking if search criteria have been entered and then deciding whether to stop the export. In Page_Export:

$doc->Text = $this->SearchWhere;
 if ($this->SearchWhere == "")
 {
   $this->SearchWhere = '" 0 == NULL"' ;
 } 

The SearchWhere has the correct clause and shows in the exported header, but I can not find a value that makes the search fail . The Page_Export and Row_Export only appear to switch back and forth, but not allow the export to be cancelled.


Re: Restrict export options

Posted: Sat Mar 02, 2024 10:03 am
by arbei

The Page_Export and Row_Export are for customizing export content only. When the events are fired, the page is already exporting. You better check the search criteria in Page_Load and use Security()->setCanExport(false) to disable export.


Re: Restrict export options

Posted: Thu Mar 07, 2024 5:59 am
by daveb

I was trying to check that the Security option was correct and tried it unconditionally to stop all exports, but the exports still ran. Is the

Security()->setCanExport(false)

the correct function to use? If I can get that right, then I can work on the criteria to selectively stop the export.

Thanks


Re: Restrict export options

Posted: Thu Mar 07, 2024 11:20 am
by arbei

If you are not checking search criteria, you better use TablePermission_Loaded server event and use $this->setCanExport(false). If you need to check search criteria, you need to use an event fired after the search criteria is loaded, TablePermission_Loaded is too early. If the user cannot export, the export button will not be shown. Of course, canExport() only works if security with users table is enabled.
Also, note that export is done by API, the API does not have any info about the search criteria. If you use the URL to access the API directly, the export still works unless TablePermission_Loaded server event is used.


Re: Restrict export options

Posted: Fri Mar 08, 2024 3:06 am
by daveb

I want the export to run unless there are no criteria set. I tried to set the security() value in the Page_Load event to check that it would stop the export - then I could figure out the criteria later. I have decided to create another view for exporting - then I can use the "require search criteria" option as it will not interfere with the add/edit pages