Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add redirect for legacy e2 urls #2948

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sourcecode/hub/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ AUTH0_CLIENT_SECRET=
# e.g. https://dev--abcdef.eu.auth0.com - must not end in a slash
AUTH0_BASE_URL=

# Should only be used for legacy environments
EDLIB_LEGACY_DOMAIN=www.edlib.test

# These should not be used, except in development and some legacy environments
NDLA_LEGACY_DOMAIN=hub-ndla-legacy.edlib.test
NDLA_LEGACY_CONTENTAUTHOR_HOST=ca.edlib.test
Expand Down
5 changes: 5 additions & 0 deletions sourcecode/hub/app/Http/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,9 @@ public function statistics(ContentStatisticsRequest $request, Content $content):
],
]);
}

public function redirectFromEdlib2Id(Content $edlib2Content): RedirectResponse
{
return redirect()->route('content.embed', [$edlib2Content]);
}
}
9 changes: 9 additions & 0 deletions sourcecode/hub/app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function boot(): void
])->limit(1)->firstOrFail();
});

Route::bind('edlib2Content', fn(string $value) => Content::ofTag([
'prefix' => 'edlib2_id',
'name' => $value,
])->limit(1)->firstOrFail());

$this->configureRateLimiting();

$this->routes(function (NdlaLegacyConfig $ndlaLegacy) {
Expand All @@ -63,6 +68,10 @@ public function boot(): void
Route::middleware('stateless')
->get('/up', HealthController::class);

Route::middleware('stateless')
->domain(config('app.edlib-legacy-domain', 'invalid.'))
->group(base_path('routes/edlib-legacy.php'));

Route::middleware('ndla-legacy')
->domain($ndlaLegacy->isEnabled() ? $ndlaLegacy->getDomain() : 'invalid.')
->group(base_path('routes/ndla-legacy.php'));
Expand Down
2 changes: 2 additions & 0 deletions sourcecode/hub/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'contact-url' => env('APP_CONTACT_URL', ''),

'edlib-legacy-domain' => env('EDLIB_LEGACY_DOMAIN'),

/*
|--------------------------------------------------------------------------
| Application Environment
Expand Down
1 change: 1 addition & 0 deletions sourcecode/hub/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DUSK_DRIVER_URL" value="http://chromedriver:9515"/>
<env name="EDLIB_LEGACY_DOMAIN" value="www.edlib.test"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
10 changes: 10 additions & 0 deletions sourcecode/hub/routes/edlib-legacy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use App\Http\Controllers\ContentController;
use Illuminate\Support\Facades\Route;

Route::get('/s/resources/{edlib2Content}')
->uses([ContentController::class, 'redirectFromEdlib2Id'])
->whereUuid('edlib2Content');
11 changes: 11 additions & 0 deletions sourcecode/hub/tests/Feature/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public function testCanLaunchContentByEdlib2UsageId(): void
->assertRedirect('https://hub-test.edlib.test/content/' . $content->id . '/embed');
}

public function testRedirectsFromLegacyResourceUrls(): void
{
$content = Content::factory()
->withPublishedVersion()
->tag('edlib2_id:a3dcbd28-bf37-4123-ac5e-ba2f72a8f420')
->create();

$this->get('http://www.edlib.test/s/resources/a3dcbd28-bf37-4123-ac5e-ba2f72a8f420')
->assertRedirect('http://hub-test.edlib.test/content/' . $content->id . '/embed');
}

public function testCannotPreviewUnpublishedContent(): void
{
$content = Content::factory()
Expand Down