-
Notifications
You must be signed in to change notification settings - Fork 57
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: previews for unpublished pages #277
Conversation
I am testing with the following graphql query, we'll need to setup some sort of similar test scenario. note in both scenarios my frontend preview code has to copy the id or page_type out of the token to pass to the graphql query. I feel like maybe I should go deeper and just have the token take precendence over everything else if it is present.
|
ba2ccf3
to
b67f98a
Compare
I force pushed an update where token takes priority over all other args is present and the params required for fulfillment of a token query are extracted from the token. My update test graphql looks more like
I still need help figuring out how to set the test scenarios for 2 token types (saved and unpublished, unsaved and unpublished), all the published scenarios should be covered by existing tests. We may also want to add tests to ensure unpublished content isn't accessible without the token. I'm not sure that those tests should necessarily hold up this PR since we don't already have coverage on those feature and this is a bug that could be impacting production sites. |
b67f98a
to
30838a1
Compare
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.
@dopry do you still need help with generating a token for new pages?
unpublished pages are no more special than others. You can just do token = PageModelWithPreviewMixin.create_page_preview().token
grapple/types/pages.py
Outdated
""" | ||
is there a particular version of wagtail that requires checking that | ||
get_page_from_preview_token exists? is there a version of wagtail | ||
at which we can drop this conditional safely? |
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.
get_page_from_preview_token
comes for wagtail-headless-preview and is Wagtail-versiona agnostic
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.
So this is really just a check to see if headless preview is installed and enabled?
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.
would we be better served with an isHeadlessPreviewEnabled() function?
grapple/types/pages.py
Outdated
return cls.get_page_from_preview_token(token) | ||
|
||
""" | ||
we get parent_id and page_type when previewing a page that has not been |
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.
parent_id is added for convenience. if I recall correctly we needed to vary things a bit when generating the token. When you have an ID that gives enough to go on.
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.
we could eliminate the if id: code path here if the page_type was always sent. It might not be as 'fast', but it would reduce the amount of code we need to maintain.
I'll try to get another pass on this by EOM. |
9f7d06e
to
879c10c
Compare
@zerolab I got the tests setup. I'm not happy with how I'm mocking the unsaved page as per my haiku, but it seems to work. I feel like wagtail-headless-preview is actually a better place for much of this code. I'll try to make a PR against it in the next few weeks to improve the DX here a little and for anyone else building on it. |
df2c199
to
059910f
Compare
059910f
to
6cf227c
Compare
uh-oh, I missed this one for 0.19. Will review on Friday and make 0.19.1 release 🙈 |
I was just about to ask. :) I'd love to see previews fixed. At some point in the future I'll try to take a pass on wagtail-headless-preview, but I'd rather those concerns not block this now. |
🎉 hooray 🎉 |
Thank you for your PRs, much appreciated! |
applies to #275
I couldn't find any tests for the token calls and don't have a clue where to start generating them.