yunojuno / django-request-token

Django app that uses JWT to manage one-time and expiring tokens to protected URLs. Not related to DRF.
MIT License
47 stars 23 forks source link

Can't search by token in admin #59

Closed djm closed 1 year ago

djm commented 1 year ago

Seeing ?rt=<token> is the most common way issues will be reported.

And yet there is no easy way to go from to finding the actual RequestToken in the admin.

We should improve support for this.

hugorodgerbrown commented 1 year ago

Took a look at this to work out why the token isn't stored on the object itself (which is the obvious solution). It's because the id of the object is encoded into the token, and that is only available post-save. So you'd have to save the object initially to get an id, then set the token on the model, then save again. This only applies to the initial creation (as once it's saved for the first time it will always have an id).

If you only ever create objects using create_token then updating that method to do a double save would work, but it would many any 'raw' RequestToken creation would fail. Breaking change.

djm commented 1 year ago

Indeed! I was wondering about this flow instead:

Then we don't have to mess around with creation/schema changes.

I believe this can be accomplished by overriding the ModelAdmin.get_search_results "view" but have somehow never used it in anger.

hugorodgerbrown commented 1 year ago

Had to take the day off today, so fixed this in #60.