onespacemedia / cms

A collection of Django extensions that add content-management facilities to Django projects.
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

Add token generator for offline pages #192

Closed AidanCurrah closed 4 years ago

AidanCurrah commented 4 years ago

This PR add a token generator that accepts a path and returns a hash. In addition, the OnlineBase model has a new function get_preview_url that appends ?preview=PATH_HASH if the model is offline. Finally, the PublicationMiddleware now has two different conditions for allowing a user to view an offline page.

  1. The same as the old check, except it just checks if the GET parameter preview exists
  2. The value of the GET parameter preview is equal to the hash of the requested path.

This means elsewhere (OSM Jet), we can add links to object.get_preview_url to have shareable links to offline pages that can be viewed by people not logged in.

lewiscollard commented 4 years ago

I actually really like the simplicity of this approach. :)