Filter not posted while uploading file
Filter not posted while uploading file
Hi,
I'm trying to filter the results on my table on a specific id (foreign_id), so I only return the child records that are related to a specific parent record (1-on-n relation in a parent-child solution).
****// DataTables PHP library
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'document' )
->fields(
Field::inst( 'foreign_id' ),
Field::inst( 'description' ),
Field::inst( 'type_id' ),
Field::inst( 'publishdate' ),
Field::inst( 'active' ),
Field::inst( 'uuid' )
->setFormatter( 'Format::ifEmpty', null )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/site/workload/documents/n__ID__.__EXTN__' )
->db( 'files', 'id', array(
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
) )
->validator( function ( $file ) {
return$file['size'] >= 500000 ?
"Files must be smaller than 500K" :
null;
} )
->allowedExtensions( array( 'png', 'jpg', 'gif' ), "Please upload an image" )
)
)
->where( 'foreign_id', $_POST['foreign_id'] )
->process( $_POST )
->json();
****
Because of the filter on the child records, I post the foreign_id to the server side php, but when I upload the file the foreign_id isn't posted and it results in a warning (notice). Not posting the foreign_id to filter the results means that the whole table is returned with a security issue that everyone can see each others data. I'm stuck on this issue and I hope someone knows a solution.
Kind regards,
nessinits
Replies
I believe I have solved the problem partially.
I've added the foreign_id as GET in the ajax request (as a part of the url defined). The document results are limited to the records matching the foreign_id, now.
However the server side response still returns every file in the files table now. I've no idea how I can limit the result on this.
Some additional information:
Only the last file (id 15, because it matches uuid 15 in the data) should be in the response. Hope someone knows what I'm doing wrong.
Could this be a security issue?
Your "where" condition has no operator.
https://editor.datatables.net/manual/php/conditions#Simple-usage
Don't believe that's the problem:
operator - The conditional operator (e.g. =, <, >, etc). This parameter is optional - the default is =.
Ah - sorry, didn't see that.
Currently the
Upload
class does not have its ownwhere
condition - that is something that I will look into adding for a future release.It could be considered a security issue if you don't want all of the files to be listed (although it is worth noting that it would be trivial to change the GET parameter allowing the end user to find the other files, so a
where
for the upload alone wouldn't solve that).Allan
Thanks for your help, Allan.
This discussion can be closed