diff --git a/app/GrassrootsGrantsPage.php b/app/GrassrootsGrantsPage.php index 44aacce37..f8125906e 100644 --- a/app/GrassrootsGrantsPage.php +++ b/app/GrassrootsGrantsPage.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Facades\URL; class GrassrootsGrantsPage extends Model { @@ -53,4 +54,12 @@ public static function config(): self 'round_title' => 'Round 1 of Grants', ]); } + + public function previewSignedUrl(int $days = 14): string + { + return URL::temporarySignedRoute( + 'grassroots-grants.preview', + now()->addDays($days), + ); + } } diff --git a/app/Http/Controllers/GrassrootsGrantsController.php b/app/Http/Controllers/GrassrootsGrantsController.php new file mode 100644 index 000000000..b10c1c464 --- /dev/null +++ b/app/Http/Controllers/GrassrootsGrantsController.php @@ -0,0 +1,40 @@ +loadPage(); + + if ($page->is_preview_mode) { + abort(404); + } + + return view('static.grassroots-grants', [ + 'page' => $page, + 'previewMode' => false, + ]); + } + + public function preview(): View + { + return view('static.grassroots-grants', [ + 'page' => $this->loadPage(), + 'previewMode' => true, + ]); + } + + private function loadPage(): GrassrootsGrantsPage + { + return GrassrootsGrantsPage::config()->load([ + 'activeHubs.activeProjects.links', + 'activeHubs.activeProjects.images', + ]); + } +} diff --git a/app/Nova/GrassrootsGrantsPage.php b/app/Nova/GrassrootsGrantsPage.php index 4208ac22d..d5f51d8c7 100644 --- a/app/Nova/GrassrootsGrantsPage.php +++ b/app/Nova/GrassrootsGrantsPage.php @@ -53,7 +53,19 @@ public function fields(Request $request): array Panel::make('Publishing', [ Boolean::make('Preview mode', 'is_preview_mode') - ->help('When enabled, the page shows a preview banner and the footer link stays hidden.'), + ->help('When enabled, /grassroots-grants returns 404 and only the signed preview URL below works. The footer link stays hidden until preview mode is off.'), + Text::make('Preview URL', function () { + if (! $this->resource?->exists) { + return 'Save first to generate preview URL.'; + } + + $url = $this->resource->previewSignedUrl(); + + return ''.$url.''; + }) + ->onlyOnDetail() + ->asHtml() + ->help('Share this signed link for review. It expires in 14 days. Regenerate by reopening this page in Nova.'), ])->collapsable(), Panel::make('Hero', [ diff --git a/resources/views/static/grassroots-grants.blade.php b/resources/views/static/grassroots-grants.blade.php index 1f7fddb26..561076b8e 100644 --- a/resources/views/static/grassroots-grants.blade.php +++ b/resources/views/static/grassroots-grants.blade.php @@ -58,10 +58,10 @@ @section('content')
- @if($page && $page->is_preview_mode) + @if(($previewMode ?? false) === true)
- Preview mode: this page is not published yet. + Preview mode: this page is not published yet. Share only the signed preview link from Nova.
@endif diff --git a/routes/web.php b/routes/web.php index 73c5cde7c..957dd1292 100644 --- a/routes/web.php +++ b/routes/web.php @@ -236,8 +236,11 @@ ->name('contact-us'); Route::get('/faqs', [StaticPageController::class, 'static']) ->name('faqs'); -Route::get('/grassroots-grants', [StaticPageController::class, 'static']) +Route::get('/grassroots-grants', [\App\Http\Controllers\GrassrootsGrantsController::class, 'show']) ->name('grassroots-grants'); +Route::get('/grassroots-grants-preview', [\App\Http\Controllers\GrassrootsGrantsController::class, 'preview']) + ->middleware('signed') + ->name('grassroots-grants.preview'); //Static training pages Route::get('/training', [TrainingController::class, 'index'])->name('training.index'); Route::get(