Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork69
Some Updates#51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Some Updates#51
Uh oh!
There was an error while loading.Please reload this page.
Conversation
- queryString:We have to be able to see the id of the dataTable by looking at the ajax request, since we might want to handle more than one data tables in one route.- Custom JS functions:The code now allows jQuery and JS codes to be printed as literal functions.- SmartDataTables:Also we want to specify if the request will be handled from the new SmartDataTables service.So,Let me explain what SmartDataTables mean for me. My company uses a s* ton of datatables and I am so tired of copy pasing a new route/method over and over again.SmartDataTables simply adds a field called `$isSmartDataTable` to the `abstract DataTable` class which is by default `false`. On your child class you can overwrite this.Ex:```php /** * Dynamically detects which DataTable to initialize for backend processing and responds. * *@var boolean */ protected $isSmartDataTable = true;```By doing so you let the dataTable add a `smartDataTable` field to the ajax request which has the value of the class which is a "SmartDataTable". If we were to make a UsersDataTable and mark it as "smart". The query will have a parameter like this: `smartDataTable=App\DataTables\UsersDataTable`.The next step is to check all web requests via a Middleware if the contain the parameter `smartDataTable`. If they do, we will simply resolve the data table class and respond to it accordingly. (Just like the `render` method does.)```php if (!$request->has('smartDataTable')) { return $next($request); } $dataTable = app($request->smartDataTable); if ($request->ajax() && $request->wantsJson()) { return app()->call([$dataTable, 'ajax']); }```
yajra commentedDec 26, 2017
@OzanKurt the PR looks good, I have the same idea on my todo list. Glad you initiated this. Some points:
Will to test this as soon as I can. Thanks! |
OzanKurt commentedDec 26, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I am not sure how I can split those now thou. :(
Yes, this should be done. I will be working about that anyways since I am currently building a "base starter template project" for my company, everything has to be perfect.
We can change where it works by editing the
Thanks a thing I should also do 👍 |
src/Html/Builder.php Outdated
| foreach (array_dot($parameters)as$key =>$value) { | ||
| if ($this->isCallbackFunction($value,$key)) { | ||
| if ($this->isCallbackFunction($value,$key) ||$this->isJavascriptFunction($value,$key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@OzanKurt I think this is just the line you need along with theisJavascriptFunction function for the new PR. Thanks!
OzanKurt commentedDec 26, 2017
I don't know how to make two different pull requests at once, so I reverted the I added information about what I did to the commit message:86cc8ad |
yajra commentedDec 27, 2017
I just released your snippet for the js function. Thanks! On the other hand, do you think it's ok to pass the FQCN on the query string? Having a look on my notes, this is how I planned to implement this.
namespaceApp\Http\Middleware;useClosure;class DataTablesMiddlewareextends SmartDataTableMiddleware{protected$dataTables = ['users' =>'App\DataTables\UsersDataTable','posts' =>'App\DataTables\PostsDataTable', ];} This way, we only need to include Let me know what you think? Thanks! |
OzanKurt commentedDec 27, 2017
I also thought about the code security as you did, for me this was the fastest solution I was able to come up with. That I coded a project for British Taekwondo Federation, where I needed to display a dataTable to 4 different user roles differently. Like: protected$dataTables = ['adminUsers' =>'App\DataTables\Admin\UsersDataTable','instructorUsers' =>'App\DataTables\Instructor\UsersDataTable',// And so on... ]; The problem with this is that the classes I am using extent a base class. Where I can simply mark them as: protected$smartDataTables =true; In this case I would need to add protected$smartDataTables ='adminUsers'; But still seams reasonable. Finally, I personally believe that FQCN won't harm us in terms of security. The max. I would do is to remove the "Application Namespace" from it, so it looks like: Since Laravel has the command to change this |
OzanKurt commentedDec 29, 2017
We can also use a tiny en/decryption algorithm to secure the class names. https://nazmulahsan.me/simple-two-way-function-encrypt-decrypt-string/ |
lk77 commentedJan 10, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hello, i think using encryption is a bad thing for readability, perhaps an additionnal sign key would be suitable : something like this, and check the hash in the request maybe. It will be used with datatable buttons ? |
OzanKurt commentedJan 10, 2018
|
lk77 commentedJan 10, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It depends on the used algorithm, with Bcrypt it's 60 characters, it's a bit long perhaps, but some FQCN can be as long as the hash. I think using only the base class name could be enough, but it can cause conflict with other datatables of same name, so i don't know. In my code, i have multiple datatables on the same page, with same url, and i'm using the dataTableVariable property of service datatable, but it is set by hand in the child class so not a real problem, and im using |
OzanKurt commentedJan 10, 2018
We need a reversible encryption method to decrypt the class name after the request thou. |
drbyte commentedMar 28, 2018
re: FQCN, I think what@yajrasuggested earlier about a mapping list in the middleware is what this package should offer out of the box. Then if someone wants to add their own changes, either to expose their own FQCN or to Hash:: it, or whatever, they can extend this package's middleware to do their own thing. |
yajra commentedMay 7, 2022
Sorry was not able to review and this is already outdated. Closing, thanks! |
queryString:
We have to be able to see the id of the dataTable by looking at the ajax request, since we might want to handle more than one data tables in one route.
Custom JS functions:
The code now allows jQuery and JS codes to be printed as literal functions.
SmartDataTables:
Also we want to specify if the request will be handled from the new SmartDataTables service.
So,
Let me explain what SmartDataTables mean for me. My company uses a s* ton of datatables and I am so tired of copy pasing a new route/method over and over again.
SmartDataTables simply adds a field called
$isSmartDataTableto theabstract DataTableclass which is by defaultfalse. On your child class you can overwrite this.Ex:
By doing so you let the dataTable add a
smartDataTablefield to the ajax request which has the value of the class which is a "SmartDataTable". If we were to make a UsersDataTable and mark it as "smart". The query will have a parameter like this:smartDataTable=App\DataTables\UsersDataTable.The next step is to check all web requests via a Middleware if the contain the parameter
smartDataTable. If they do, we will simply resolve the data table class and respond to it accordingly. (Just like therendermethod does.)