Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2423 from ec-europa/ISAICP-6416-alt
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea authored Apr 6, 2021
2 parents 159da33 + 7b544d7 commit 7dc9019
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
29 changes: 9 additions & 20 deletions tests/features/joinup_core/persistent_uris.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Feature:

And "eira" terms:
| tid | name | description |
| http://data.europa.eu/dr8/DreamDomain | Dream Domain | You're safe from pain in the dream domain. |
| http://data.europa.eu/dr8/Dream/Domain | Dream Domain | You're safe from pain in the dream domain. |

And discussion content:
| title | body | collection | state |
Expand Down Expand Up @@ -103,34 +103,23 @@ Feature:

# Our semantic content has a persistent canonical path at Europe's
# official data portal: "http://data.europa.eu/w21/{uuid}". The data portal
# links back to the Joinup servers. In order to resolve the UUIDs we employ
# the intermediate path '/data/{uuid}' which will forward the request to the
# actual page that contains the content in human digestible format.
Given I am on "data/ffb0ffc9-7704-45d3-95b3-42706b6320e5"
Then I should see the heading "Persistent solution"
And I am on "data/w21/ffb0ffc9-7704-45d3-95b3-42706b6320e5"
# links back to the Joinup servers.
Given I am on "data/w21/ffb0ffc9-7704-45d3-95b3-42706b6320e5"
Then I should see the heading "Persistent solution"

Given I am on "data/37b8103e-26e5-4c81-8ce5-43ced02ff7d0"
Then I should see the heading "Persistent collection"
And I am on "data/w21/37b8103e-26e5-4c81-8ce5-43ced02ff7d0"
Given I am on "data/w21/37b8103e-26e5-4c81-8ce5-43ced02ff7d0"
Then I should see the heading "Persistent collection"

Given I am on "data/98004ec9-62f3-4734-a1b6-af7e4838b09c"
Then I should see the heading "Persistent release 23"
And I am on "data/w21/98004ec9-62f3-4734-a1b6-af7e4838b09c"
Given I am on "data/w21/98004ec9-62f3-4734-a1b6-af7e4838b09c"
Then I should see the heading "Persistent release 23"

Given I am on "data/643a2a52-da3b-4594-92bb-295d8134e1fb"
Then I should see the heading "Persistent distribution"
And I am on "data/w21/643a2a52-da3b-4594-92bb-295d8134e1fb"
Given I am on "data/w21/643a2a52-da3b-4594-92bb-295d8134e1fb"
Then I should see the heading "Persistent distribution"

Given I am on "data/4205229d-92b6-4cac-80af-d8c2296d923c"
Then I should see the heading "Persistent licence"
And I am on "data/w21/4205229d-92b6-4cac-80af-d8c2296d923c"
Given I am on "data/w21/4205229d-92b6-4cac-80af-d8c2296d923c"
Then I should see the heading "Persistent licence"

Given I am on "data/dr8/DreamDomain"
Given I am on "data/dr8/Dream/Domain"
Then I should see the heading "Dream Domain"
And I should see "You're safe from pain in the dream domain."
And the url should match "/taxonomy/term/http_e_f_fdata_ceuropa_ceu_fdr8_fDream_fDomain"
14 changes: 5 additions & 9 deletions web/modules/custom/joinup_core/joinup_core.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ joinup_core.file_field_info:
requirements:
_permission: 'administer content types'

# @todo Remove this when the w21 redirect has been updated.
joinup_core.id_redirect.deprecated:
path: '/data/{uuid}'
defaults:
_controller: '\Drupal\joinup_core\Controller\IdRedirect::redirectToRdfEntity'
namespace: w21
requirements:
_access: 'TRUE'

joinup_core.id_redirect:
path: '/data/{namespace}/{uuid}'
defaults:
_controller: '\Drupal\joinup_core\Controller\IdRedirect::redirectToRdfEntity'
requirements:
_access: 'TRUE'
# Even though we are using a custom processor to alter the UUID value to not
# include the /, we need to set the value of UUID to match '.+' because the
# Drupal routing system uses by default the '[^/]' for route parameters.
# @see \Drupal\Core\Routing\Router::doMatchCollection()
uuid: '.+'

joinup_core.rdf_entity_uri_web_converter_page:
path: '/rdf'
Expand Down
9 changes: 9 additions & 0 deletions web/modules/custom/joinup_core/joinup_core.services.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
services:

joinup_core.joinup_version:
class: Drupal\joinup_core\JoinupVersion

logger.channel.joinup_core:
parent: logger.channel_base
arguments: ['joinup_core']

joinup_core.requirements_helper:
class: Drupal\joinup_core\RequirementsHelper
arguments: ['@database']

joinup_core.local_task_links_helper:
class: Drupal\joinup_core\LocalTaskLinksHelper
arguments: ['@entity_type.manager']
Expand All @@ -15,3 +19,8 @@ services:
arguments: ['@entity_field.manager']
tags:
- { name: event_subscriber }

path_processor.joinup_core:
class: Drupal\joinup_core\PathProcessor\IdRedirectUuidProcessor
tags:
- { name: path_processor_inbound, priority: 200 }
3 changes: 3 additions & 0 deletions web/modules/custom/joinup_core/src/Controller/IdRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function redirectToRdfEntity(string $namespace, string $uuid): RedirectRe
return $this->redirect('joinup_core.not_found', [], [], 404);
}

// The UUID has been encoded early to allow slashes.
// @see \Drupal\joinup_core\PathProcessor\IdRedirectNamespaceProcessor::processInbound()
$uuid = urldecode($uuid);
return $this->redirect("entity.$entity_type_id.canonical", [
$entity_type_id => "http://data.europa.eu/$namespace/$uuid",
], [], 301);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare (strict_types = 1);

namespace Drupal\joinup_core\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\joinup_core\Controller\IdRedirect;
use Symfony\Component\HttpFoundation\Request;

/**
* Handles joinup_core.id_redirect route case when {uuid} param contains a '/'.
*
* Because the joinup_core.id_redirect route's {uuid} parameter may contain one
* or more slashes, we encode the URL parameter as Drupal doesn't allow slashes
* in parameters, as opposed to Symfony. We revert the parameter encoding,
* later, in IdRedirect::redirectToRdfEntity().
*
* @see https://www.drupal.org/project/drupal/issues/2741939
* @see https://symfony.com/doc/3.4/routing/slash_in_parameter.html
* @see \Drupal\joinup_core\Controller\IdRedirect::redirectToRdfEntity()
*/
class IdRedirectUuidProcessor implements InboundPathProcessorInterface {

/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request): string {
if (strpos($path, '/data/') === 0 && !$request->query->has('uuid')) {
preg_match('#^/data/(?<namespace>[^/]+)/(?<uuid>.+)$#', $path, $matches);
if (!empty($matches['namespace']) && !empty($matches['uuid'][0]) && IdRedirect::getEntityTypeFromPersistentUriNamespace($matches['namespace'])) {
return '/data/' . $matches['namespace'] . '/' . urlencode($matches['uuid']);
}
}
return $path;
}

}

0 comments on commit 7dc9019

Please sign in to comment.