Skip to content

Commit 5033599

Browse files
committed
MC-15977: PageBuilder preview
1 parent 6ca72a9 commit 5033599

File tree

4 files changed

+128
-14
lines changed

4 files changed

+128
-14
lines changed

app/code/Magento/PageBuilder/Controller/ContentType/Preview.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Framework\App\Action\HttpPostActionInterface;
13-
use Magento\Framework\Exception\AuthenticationException;
1413

1514
/**
1615
* Preview controller to render blocks preview on Stage
@@ -27,40 +26,28 @@ class Preview extends \Magento\Framework\App\Action\Action implements HttpPostAc
2726
*/
2827
private $rendererPool;
2928

30-
/**
31-
* @var \Magento\Backend\Model\Auth
32-
*/
33-
private $auth;
34-
3529
/**
3630
* Constructor
3731
*
3832
* @param \Magento\Backend\App\Action\Context $context
3933
* @param \Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
40-
* @param \Magento\Backend\Model\Auth $auth
4134
*/
4235
public function __construct(
4336
\Magento\Backend\App\Action\Context $context,
44-
\Magento\PageBuilder\Model\Stage\RendererPool $rendererPool,
45-
\Magento\Backend\Model\Auth $auth
37+
\Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
4638
) {
4739
parent::__construct($context);
4840

4941
$this->rendererPool = $rendererPool;
50-
$this->auth = $auth;
5142
}
5243

5344
/**
5445
* Generates an HTML preview for the stage
5546
*
5647
* @return \Magento\Framework\Controller\ResultInterface
57-
* @throws \Magento\Framework\Exception\AuthenticationException
5848
*/
5949
public function execute()
6050
{
61-
if (!$this->auth->isLoggedIn()) {
62-
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
63-
}
6451
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
6552
// Some template filters and directive processors expect this to be called in order to function.
6653
$pageResult->initLayout();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageBuilder\Plugin\Framework\App;
7+
8+
/**
9+
* Plugin for front controller interface.
10+
*/
11+
class FrontController
12+
{
13+
/**
14+
* @var \Magento\Backend\Model\Auth
15+
*/
16+
private $auth;
17+
18+
/**
19+
* @param \Magento\Backend\Model\Auth $auth
20+
*/
21+
public function __construct(
22+
\Magento\Backend\Model\Auth $auth
23+
) {
24+
$this->auth = $auth;
25+
}
26+
27+
/**
28+
* Check if user logged in
29+
*
30+
* @param \Magento\Framework\App\FrontControllerInterface $subject
31+
* @param \Magento\Framework\App\RequestInterface $request
32+
*
33+
* @return void
34+
*
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
37+
public function beforeDispatch(
38+
\Magento\Framework\App\FrontControllerInterface $subject,
39+
\Magento\Framework\App\RequestInterface $request
40+
) {
41+
if (strpos($request->getPathInfo(), 'pagebuilder/contenttype/preview')) {
42+
if ($this->auth->getUser()) {
43+
$this->auth->getUser()->reload();
44+
45+
$isLoggedIn = $this->auth->isLoggedIn();
46+
47+
if (!$isLoggedIn) {
48+
$this->forwardRequest($request);
49+
}
50+
} else {
51+
$this->forwardRequest($request);
52+
}
53+
}
54+
}
55+
56+
/**
57+
* Forwards request to the 404 page.
58+
*
59+
* @param \Magento\Framework\App\RequestInterface $request
60+
*
61+
* @return void
62+
*/
63+
private function forwardRequest(
64+
\Magento\Framework\App\RequestInterface $request
65+
) {
66+
$request->initForward();
67+
$request->setActionName('noroute');
68+
}
69+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageBuilder\Plugin\Framework\Session;
7+
8+
/**
9+
* Plugin for SID resolver.
10+
*/
11+
class SidResolver
12+
{
13+
/**
14+
* @var \Magento\Framework\App\RequestInterface
15+
*/
16+
private $request;
17+
18+
/**
19+
* @param \Magento\Framework\App\RequestInterface $request
20+
*/
21+
public function __construct(
22+
\Magento\Framework\App\RequestInterface $request
23+
) {
24+
$this->request = $request;
25+
}
26+
27+
/**
28+
* @param \Magento\Framework\Session\SidResolver $subject
29+
* @param \Closure $proceed
30+
* @param \Magento\Framework\Session\SessionManagerInterface $session
31+
*
32+
* @return string|null
33+
*/
34+
public function aroundGetSid(
35+
\Magento\Framework\Session\SidResolver $subject,
36+
\Closure $proceed,
37+
\Magento\Framework\Session\SessionManagerInterface $session
38+
) {
39+
if (strpos($this->request->getPathInfo(), 'pagebuilder/contenttype/preview')) {
40+
return $this->request->getQuery(
41+
$subject->getSessionIdQueryParam($session)
42+
);
43+
}
44+
45+
return $proceed($session);
46+
}
47+
}

app/code/Magento/PageBuilder/etc/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,15 @@
140140
</argument>
141141
</arguments>
142142
</type>
143+
<type name="Magento\PageBuilder\Plugin\Framework\App\FrontController">
144+
<arguments>
145+
<argument name="auth" xsi:type="object">\Magento\Backend\Model\Auth\Proxy</argument>
146+
</arguments>
147+
</type>
148+
<type name="Magento\Framework\App\FrontControllerInterface">
149+
<plugin name="pagebuilder_preview_permissions_check" type="Magento\PageBuilder\Plugin\Framework\App\FrontController" />
150+
</type>
151+
<type name="Magento\Framework\Session\SidResolver">
152+
<plugin name="pagebuilder_preview_sid_resolving" type="Magento\PageBuilder\Plugin\Framework\Session\SidResolver" />
153+
</type>
143154
</config>

0 commit comments

Comments
 (0)