Add customizable Legal Notice page

This commit is contained in:
Daniel Supernault 2022-08-15 23:39:33 -06:00
parent 96f13530e1
commit 0b7d0a9627
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
7 changed files with 58 additions and 7 deletions

View file

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth, Cache;
use App\Page;
use App\Services\ConfigCacheService;
class PageController extends Controller
{
@ -18,7 +19,8 @@ class PageController extends Controller
'/site/about' => 'site:about',
'/site/privacy' => 'site:privacy',
'/site/terms' => 'site:terms',
'/site/kb/community-guidelines' => 'site:help:community-guidelines'
'/site/kb/community-guidelines' => 'site:help:community-guidelines',
'/site/legal-notice' => 'site:legal-notice'
];
}
@ -60,10 +62,11 @@ class PageController extends Controller
$page->title = $request->input('title');
$page->active = (bool) $request->input('active');
$page->save();
if($page->cached) {
$keys = $this->cacheKeys();
$key = $keys[$page->slug];
Cache::forget($key);
$keys = $this->cacheKeys();
$key = $keys[$page->slug];
Cache::forget($key);
if($page->slug === '/site/legal-notice') {
ConfigCacheService::put('instance.has_legal_notice', $page->active);
}
return response()->json(['msg' => 200]);
}
@ -75,14 +78,17 @@ class PageController extends Controller
]);
$page = Page::findOrFail($request->input('id'));
$keys = $this->cacheKeys();
$key = $keys[$page->slug];
$page->delete();
Cache::forget($key);
return redirect(route('admin.settings.pages'));
}
public function generatePage(Request $request)
{
$this->validate($request, [
'page' => 'required|string|in:about,terms,privacy,community_guidelines',
'page' => 'required|string|in:about,terms,privacy,community_guidelines,legal_notice',
]);
$page = $request->input('page');
@ -103,6 +109,10 @@ class PageController extends Controller
case 'community_guidelines':
Page::firstOrCreate(['slug' => '/site/kb/community-guidelines']);
break;
case 'legal_notice':
Page::firstOrCreate(['slug' => '/site/legal-notice']);
break;
}
return redirect(route('admin.settings.pages'));

View file

@ -154,4 +154,14 @@ class SiteController extends Controller
return redirect($url);
}
public function legalNotice(Request $request)
{
$page = Cache::remember('site:legal-notice', now()->addDays(120), function() {
$slug = '/site/legal-notice';
return Page::whereSlug($slug)->whereActive(true)->first();
});
abort_if(!$page, 404);
return View::make('site.legal-notice')->with(compact('page'))->render();
}
}

View file

@ -53,6 +53,8 @@ class ConfigCacheService
'account.autofollow',
'account.autofollow_usernames',
'config.discover.features',
'instance.has_legal_notice',
// 'system.user_mode'
];

View file

@ -84,4 +84,6 @@ return [
],
'enable_cc' => env('ENABLE_CONFIG_CACHE', false),
'has_legal_notice' => env('INSTANCE_LEGAL_NOTICE', false),
];

View file

@ -11,7 +11,7 @@
<p class="lead text-white mt-n4 mb-0">Manage public and custom page content</p>
</div>
@if($pages->count() < 4)
@if($pages->count() < 5)
<div class="col-12">
<hr>
<div class="btn-group">
@ -43,6 +43,13 @@
<button type="submit" class="btn btn-default font-weight-bold">Customize Guidelines Page</button>
</form>
@endif
@if(!$pages->contains('slug', '=', '/site/legal-notice'))
<form class="form-inline" method="post" action="/i/admin/settings/pages/create">
@csrf
<input type="hidden" name="page" value="legal_notice">
<button type="submit" class="btn btn-default font-weight-bold">Customize Legal Notice Page</button>
</form>
@endif
</div>
</div>
@endif

View file

@ -0,0 +1,19 @@
@extends('layouts.app')
@section('content')
<div class="container mt-5">
<div class="col-12">
<p class="font-weight-bold text-lighter text-uppercase">{{ $page->title ?? 'Legal Notice' }}</p>
<div class="card border shadow-none">
<div class="card-body p-md-5 text-justify mx-md-3" style="white-space: pre-line">
@if($page && $page->content)
{!! $page->content !!}
@endif
</div>
</div>
</div>
</div>
@endsection
@push('meta')
<meta property="og:description" content="{{ $page->title ?? 'Legal Notice' }}">
@endpush

View file

@ -513,6 +513,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('newsroom/archive', 'NewsroomController@archive');
Route::get('newsroom/search', 'NewsroomController@search');
Route::get('newsroom', 'NewsroomController@index');
Route::get('legal-notice', 'SiteController@legalNotice');
});
Route::group(['prefix' => 'timeline'], function () {