Skip to content

Commit

Permalink
fix completion redirect for prod with fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jul 7, 2016
1 parent 2a9b89b commit 342631a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
5 changes: 1 addition & 4 deletions Controller/CompletionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ public function indexAction(Request $request)
$this->saveEntities();

// Redirect
$session = $request->getSession();
$redirectTo = $session->get(CompletionListener::SESSION_STORE);
$redirectTo = $request->query->get('re');

if (!$redirectTo) {
$redirectTo = $communityManager->getConfigTypeProperty(self::TYPE, Configuration::REDIRECT_TO);
} else {
$session->remove(CompletionListener::SESSION_STORE);
}

if ($redirectTo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function process(ContainerBuilder $container)
// Register request listener only when validator exists.
if (!empty($validators)) {
$definition = $container->getDefinition(self::COMPLETION_LISTENER_SERVICE_ID);
$definition->replaceArgument(3, $validators);
$definition->replaceArgument(4, $validators);
} else {
$container->removeDefinition(self::COMPLETION_LISTENER_SERVICE_ID);
}
Expand Down
20 changes: 13 additions & 7 deletions EventListener/CompletionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
*/
class CompletionListener
{
/**
* @var string
*/
const SESSION_STORE = 'sulu_community/completion/redirect_to';

/**
* @var RequestAnalyzerInterface
*/
Expand All @@ -44,6 +39,11 @@ class CompletionListener
*/
protected $tokenStorage;

/**
* @var string
*/
protected $fragmentPath;

/**
* @var CompletionInterface[]
*/
Expand All @@ -55,18 +55,21 @@ class CompletionListener
* @param RequestAnalyzerInterface $requestAnalyzer
* @param RouterInterface $router
* @param TokenStorage $tokenStorage
* @param string $fragmentPath
* @param array $validators
*/
public function __construct(
RequestAnalyzerInterface $requestAnalyzer,
RouterInterface $router,
TokenStorage $tokenStorage,
$fragmentPath,
array $validators
) {
$this->requestAnalyzer = $requestAnalyzer;
$this->router = $router;
$this->tokenStorage = $tokenStorage;
$this->validators = $validators;
$this->fragmentPath = $fragmentPath;
}

/**
Expand All @@ -83,6 +86,7 @@ public function onRequest(GetResponseEvent $event)
|| $request->isMethod('post')
|| $request->isXmlHttpRequest()
|| $request->getPathInfo() === $completionUrl
|| $request->getPathInfo() === $this->fragmentPath
) {
return;
}
Expand All @@ -97,15 +101,17 @@ public function onRequest(GetResponseEvent $event)
return;
}

$uriParameters = [];
if ($request->attributes->get('_route') !== 'sulu_community.confirmation') {
$session = $request->getSession();
$session->set(self::SESSION_STORE, $request->getUri());
$uriParameters['re'] = $request->getRequestUri();
}

$webspaceKey = $this->requestAnalyzer->getWebspace()->getKey();
$validator = $this->getValidator($webspaceKey);

if ($validator && !$validator->validate($user, $webspaceKey)) {
$completionUrl = $this->router->generate('sulu_community.completion', $uriParameters);

$response = new RedirectResponse($completionUrl);
$event->setResponse($response);
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<argument type="service" id="sulu_core.webspace.request_analyzer"/>
<argument type="service" id="router"/>
<argument type="service" id="security.token_storage"/>
<argument>%fragment.path%</argument>
<argument type="collection"/>

<tag name="kernel.event_listener" event="kernel.request" method="onRequest"/>
Expand Down

0 comments on commit 342631a

Please sign in to comment.