Giter Club home page Giter Club logo

Comments (10)

lingfish avatar lingfish commented on July 29, 2024

Just a question -- why?

from django-ordered-model.

jdavisp3 avatar jdavisp3 commented on July 29, 2024

Because GET requests should not, by definition, change state.

http://programmers.stackexchange.com/questions/188860/why-shouldnt-a-get-request-change-data-on-the-server

from django-ordered-model.

zopieux avatar zopieux commented on July 29, 2024

The keyword to search for is CSRF.

from django-ordered-model.

lingfish avatar lingfish commented on July 29, 2024

Fair enough -- so does anyone plan to give the author a pull req?

from django-ordered-model.

mverleg avatar mverleg commented on July 29, 2024

There are a few practical problems:

  • Method move_up_down_links doesn't have access to request directly, so it can't generate a csrf tokens.
  • Forms cannot be nested, so the POST request has to be generated with javascript instead, which means it won't work without javascript.
  • Requiring POST would break functionality for anyone who used a custom template, probably without visible error.

I still think it's important though, it's not secure now, one can easily manipulate order through a simple CSRF url posted somewhere.

from django-ordered-model.

jdavisp3 avatar jdavisp3 commented on July 29, 2024

I think this was fixed?

from django-ordered-model.

jdavisp3 avatar jdavisp3 commented on July 29, 2024

Oh, not yet.

from django-ordered-model.

shuckc avatar shuckc commented on July 29, 2024

Might be possible to make the up/down links all submit the main form (rather than a nested form, or random get request) with different actions for each button. Would allow dropping all the custom url generation as it would all go via. the existing page change handler, with some magic in the Form generation to recover the action and emit an event or similar to update the model. I'm not nearly enough of a django hacker to get it working though.

from django-ordered-model.

shuckc avatar shuckc commented on July 29, 2024

I've been looking at what django-mptt does (they have a drag-drop re-ordering form widget) and it is quite similar to what I suggested. They use the admin jQuery integration to fire a POST request back to the original page form handler, which they intercept in the changelist_view(self, request) hook.

https://github.com/django-mptt/django-mptt/blob/master/mptt/admin.py#L147

Client-side, the result from the Ajax call is ignored, and jQuery simply reloads the current page to show the new ordering:

https://github.com/django-mptt/django-mptt/blob/master/mptt/static/mptt/draggable-admin.js#L223

This seems a neat solution. We would need to add inheritance to any changelist page that includes an OrderedTabularInline (replacing the url extending code we have at the moment).

from django-ordered-model.

ralokt avatar ralokt commented on July 29, 2024

@shuckc I take it you mean this? https://caniuse.com/#feat=form-submit-attributes

Because as far as I see it, there is no need to do away with the existing move_view or any jQuery shenanigans - it should be sufficient to change order_controls.html to use buttons with the formaction attribute for it to work.

Of course, it would be nice if the move_view were also be changed to validate that it is used with POST or PUT.

I'm prepared to do this if it's considered a worthwhile change.

from django-ordered-model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.