Skip to content

Commit

Permalink
Merge branch 'release/8.12.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
marteinn committed Aug 22, 2023
2 parents 10f02e2 + 0397f3c commit e72adb4
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 40 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Removed

## [8.12.3] - 2023-08-22

### Fixed
- Fix bug preventing request.is_preview from being set (@marteinn)
- Hide wagtail userbar when in preview panel (@marteinn)
- Make sure in_preview_panel is set (@marteinn)
- Drop non running get_preview_url override from base page (@marteinn)

### Removed
- Remove deprecated wagtail.contrib.modeladmin app from INSTALLED_APPS (@marteinn)

## [8.12.2] - 2023-08-16

### Changed
Expand Down
6 changes: 4 additions & 2 deletions Company-Project/frontend/pages/_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export async function getServerSideProps({ req, preview, previewData }) {
return { props: {} };
}

const { contentType, token, host } = previewData;
const { contentType, token, host, inPreviewPanel } = previewData;

// TODO: Add proper token verification and error message
try {
const { json: pagePreviewData } = await getPagePreview(
contentType,
token,
{},
{
in_preview_panel: inPreviewPanel,
},
{
headers: {
cookie: req.headers.cookie,
Expand Down
5 changes: 4 additions & 1 deletion Company-Project/frontend/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export default async (req, res) => {
// return res.status(401).json({ message: 'Invalid slug' })
// }

const referer = req.headers?.referer || ""
const inPreviewPanel = referer.includes("in_preview_panel=true")

res.setPreviewData(
{ contentType, token, host },
{ contentType, token, host, inPreviewPanel },
{
path: '/_preview',
}
Expand Down
16 changes: 0 additions & 16 deletions Company-Project/src/main/pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,3 @@ def to_dict(
def get_serializer_class(self) -> Type[Serializer]:
cls: Type[Serializer] = import_string(self.serializer_class)
return cls

def get_preview_url(self, token):
"""
Override wagtail_headless_preview/get_preview_url and append hostname
"""
import urllib

preview_url = super().get_preview_url(token)
preview_url = (
preview_url
+ "&"
+ urllib.parse.urlencode(
{"host": f"{self.get_site().hostname}:{self.get_site().port}"}
)
)
return preview_url
4 changes: 4 additions & 0 deletions Company-Project/src/main/pages/base_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def get_wagtail_userbar(self, page):
if not request:
return None

in_preview_panel = getattr(request, "in_preview_panel", False)
if in_preview_panel:
return None

if not hasattr(request, "user"):
return None

Expand Down
5 changes: 5 additions & 0 deletions Company-Project/src/nextjs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class PagePreviewAPIViewSet(BaseAPIViewSet):

def listing_view(self, request):
page = self.get_object()
setattr(request, "is_preview", True)

in_preview_panel = request.GET.get("in_preview_panel", None) == "true"
setattr(request, "in_preview_panel", in_preview_panel)

return page.serve(request)

def get_object(self):
Expand Down
1 change: 0 additions & 1 deletion Company-Project/src/pipit/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"wagtail",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.modeladmin",
"wagtail.contrib.routable_page",
"wagtail.contrib.settings",
"modelcluster",
Expand Down
6 changes: 4 additions & 2 deletions {{cookiecutter.project_name}}/frontend/pages/_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export async function getServerSideProps({ req, preview, previewData }) {
return { props: {} };
}

const { contentType, token, host } = previewData;
const { contentType, token, host, inPreviewPanel } = previewData;

// TODO: Add proper token verification and error message
try {
const { json: pagePreviewData } = await getPagePreview(
contentType,
token,
{},
{
in_preview_panel: inPreviewPanel,
},
{
headers: {
cookie: req.headers.cookie,
Expand Down
5 changes: 4 additions & 1 deletion {{cookiecutter.project_name}}/frontend/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export default async (req, res) => {
// return res.status(401).json({ message: 'Invalid slug' })
// }

const referer = req.headers?.referer || ""
const inPreviewPanel = referer.includes("in_preview_panel=true")

res.setPreviewData(
{ contentType, token, host },
{ contentType, token, host, inPreviewPanel },
{
path: '/_preview',
}
Expand Down
16 changes: 0 additions & 16 deletions {{cookiecutter.project_name}}/src/main/pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,3 @@ def to_dict(
def get_serializer_class(self) -> Type[Serializer]:
cls: Type[Serializer] = import_string(self.serializer_class)
return cls

def get_preview_url(self, token):
"""
Override wagtail_headless_preview/get_preview_url and append hostname
"""
import urllib

preview_url = super().get_preview_url(token)
preview_url = (
preview_url
+ "&"
+ urllib.parse.urlencode(
{"host": f"{self.get_site().hostname}:{self.get_site().port}"}
)
)
return preview_url
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def get_wagtail_userbar(self, page):
if not request:
return None

in_preview_panel = getattr(request, "in_preview_panel", False)
if in_preview_panel:
return None

if not hasattr(request, "user"):
return None

Expand Down
5 changes: 5 additions & 0 deletions {{cookiecutter.project_name}}/src/nextjs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class PagePreviewAPIViewSet(BaseAPIViewSet):

def listing_view(self, request):
page = self.get_object()
setattr(request, "is_preview", True)

in_preview_panel = request.GET.get("in_preview_panel", None) == "true"
setattr(request, "in_preview_panel", in_preview_panel)

return page.serve(request)

def get_object(self):
Expand Down
1 change: 0 additions & 1 deletion {{cookiecutter.project_name}}/src/pipit/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"wagtail",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.modeladmin",
"wagtail.contrib.routable_page",
"wagtail.contrib.settings",
"modelcluster",
Expand Down

0 comments on commit e72adb4

Please sign in to comment.