Closed (fixed)
Project:
Drupal.org security advisory coverage applications
Component:
module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2013 at 15:04 UTC
Updated:
8 Feb 2013 at 12:40 UTC
It is a module that exposes Drupal functions to JavaScript through AJAX calls. The initial release only exposes the "drupal_get_path" function, but the module is written so that adding new functions only takes about 2 lines of code.
Project link: http://drupal.org/sandbox/PDNagilum/1828912
Git clone command: git clone --recursive --branch 7.x-1.x http://git.drupal.org:sandbox/PDNagilum/1828912.git javascript_drupal_extension
Drupal version: 7.x
Reviews of other projects:
http://drupal.org/node/1824770#comment-6937908
http://drupal.org/node/1818974#comment-6938010
http://drupal.org/node/1758048#comment-6941074
Comments
Comment #1
PDNagilum commentedComment #2
kasperg commentedInteresting module. Kudos on the excellent inline comments!
I have looked through the code and have some questions and comments you may want to look into:
You can find the results of the automated report at http://ventral.org/pareview/httpgitdrupalorgsandboxpdnagilum1828912git .
db_query('DROP TABLE node')or the like through thejavascript_drupal_extension_ajax_call()function? Perhaps consider a whitelist for allowed functions.javascript_drupal_extension_ajax_callback_urla Drupal javascript setting instead of inline code?admin/config/utilities/javascript-drupal-extensionhas access argument administer javascript_drupal_extension. However administer javascript_drupal_extension is not declared inhook_perm().$_GETand$_POSTis very similar and ripe for refactoring.system_settings_form()there is no need to set the variable values explicitly if your form entries have the same keys as your variable names.I hope these comments can help improve this module and look forward to seing it develop.
Cheers!
Comment #3
PDNagilum commentedThanks for the feedback. Lots of good stuff there :)
What I've done:
Things to do:
Should I set the project status back to "needs review" now?
Comment #4
PDNagilum commentedComment #5
sirup commentedproject page
Please consider including a small discussion about when to use your module: It would be great to have a small guidance about the right approach some specific situations.
For example:
Need to retrieve and create nodes? -> use the services module
Need to send configuration data to the browser that is usable via JS? -> use standard drupal api to populate the global Drupal object
Need to call small dynamic functions? -> use your approach
code review
Your function javascript_drupal_extension_ajax_call will always return an empty string, because the success and failure ajax handlers are called after the surrounding function returns. The only and best ways to retrieve the result is to pass a callback function to the javascript_drupal_extension_ajax_call method.
Your php code handles the POST/GET variable 'output-is-json', but your JS is not sending this one?!
Comment #6
PDNagilum commentedThe javascript_drupal_extension_ajax_call works because of the async:false settings. Because of that setting it will run, and finish, while the function is running and continue. Granted, adding async:false basically halts the process while the function runs its coarse, but it's kinda needed for this type of function-info-retrieval.
The 'output-as-json' and 'content-type' are there for future use. If you later on add your own functions to the module, it's ready for use.
Added in newest commits:
* Settings for parsing of 'content-type' and 'output-as-json'
* Setting to allow for disabling of the whitelist (not recommended)
Comment #7
klausiWe are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and I'll take a look at your project right away :-)
Comment #8
sirup commentedThanks for the explanation PDNagilum, now i see why it is working. Anyway i would suggest to change the behavior so that all functions do not return anything but require a callback as the last parameter. This is the standard behavior and good style in JS - of course this requires you to change the calling code, but it has advantages:
You dont block the browser while waiting for the http response and additionally JS-programmers better understand the call semantics.
I would also recommend to throw an exception when the response did not receive successfully (within your error handler) - returning an empty string can be confusing.
Comment #9
PDNagilum commentedJust implemented two new optional parameters to the function, callback_success and callback_failure. If these are specified, and are functions, they will be called if the AJAX call runs successfully, or if it fails. If the success callback is not defined, then the standard async=false method will run and return within the same function-run.
I also added a throwing of error if the AJAX call fails and a callback_failure is not defined.
Thanks for the idea @sirup :)
@klausi: I'll try to review some projects over the next few days :)
Comment #9.0
PDNagilum commentedAdded link to review of other project
Comment #9.1
PDNagilum commentedAdded another review link
Comment #10
PDNagilum commentedReviews of other projects:
Not sure I've done this correctly to receive the review bonus. Just slap me if I've done something wrong ;)
Comment #11
PDNagilum commentedAdded a more extensive README.txt file, and also added a help-section-code.
Comment #12
klausimanual review:
Although you should definitively fix those issues they are not critical application blockers, so I guess this is RTBC. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #13
PDNagilum commentedThanks for the review :)
1, 2, 3, 4, 5, and 6. Fixed
7. Rewritten for clarity
Comment #14
klausino objections for more than a week, so ...
Thanks for your contribution, PDNagilum!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #15.0
(not verified) commentedAdded another review