Skip to content

Commit

Permalink
Merge pull request fsulib#10 from qadan/entity-checks
Browse files Browse the repository at this point in the history
checking for actual entities before redirect
  • Loading branch information
jordandukart authored Aug 4, 2020
2 parents d5d7785 + 1f23513 commit 4569395
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/EventSubscriber/IpRedirectAttacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,24 @@ public function attachIpRedirect(GetResponseEvent $response) {
$redirect_url = NULL;
// Redirect for nodes.
if (substr($route_name, 0, 11) == 'entity.node') {
$redirect_url = $this->nodeAccess->getIpEmbargoedRedirectUrl($response->getRequest()->attributes->get('node'), $this->user);
$node = $response->getRequest()->attributes->get('node');
if ($node) {
$redirect_url = $this->nodeAccess->getIpEmbargoedRedirectUrl($node, $this->user);
}
}
// Redirect for media.
elseif (substr($route_name, 0, 12) == 'entity.media') {
$redirect_url = $this->mediaAccess->getIpEmbargoedRedirectUrl($response->getRequest()->attributes->get('media'), $this->user);
$media = $response->getRequest()->attributes->get('media');
if ($media) {
$redirect_url = $this->mediaAccess->getIpEmbargoedRedirectUrl($media, $this->user);
}
}
// Redirect for files.
elseif (substr($route_name, 0, 11) == 'entity.file') {
$redirect_url = $this->fileAccess->getIpEmbargoedRedirectUrl($response->getRequest()->attributes->get('file'), $this->user);
$file = $response->getRequest()->attributes->get('file');
if ($file) {
$redirect_url = $this->fileAccess->getIpEmbargoedRedirectUrl($file, $this->user);
}
}
if ($redirect_url) {
$response->setResponse(new RedirectResponse($redirect_url));
Expand Down

0 comments on commit 4569395

Please sign in to comment.