Implement legal document acceptance tracking requiring users to accept terms of service and privacy policy before continuing to use the system. Add automatic generation of standard project files (LICENSE, README.md, RULES.md, cookies.html, termos-de-uso.html, privacidade.html) with download functionality. Enhance prompt building with detailed Portuguese instructions and system requirements. Update seeders with comprehensive legal content and standard files configuration for all prompt templates.
126 lines
3.8 KiB
PHP
Executable File
126 lines
3.8 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Legal;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\LegalDocument;
|
|
use App\Models\UserDocumentAcceptance;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\View\View;
|
|
|
|
class LegalDocumentController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of legal documents.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$this->authorize('viewAny', LegalDocument::class);
|
|
|
|
$documents = LegalDocument::orderBy('type')->orderByDesc('version')->paginate(20);
|
|
|
|
return view('legal.documents.index', compact('documents'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing a legal document.
|
|
*/
|
|
public function edit(string $type)
|
|
{
|
|
$document = LegalDocument::where('type', $type)->latest('version')->first();
|
|
|
|
if (!$document) {
|
|
$document = new LegalDocument(['type' => $type]);
|
|
}
|
|
|
|
$this->authorize('update', $document);
|
|
|
|
return view('legal.documents.edit', compact('document'));
|
|
}
|
|
|
|
/**
|
|
* Update or create a legal document.
|
|
*/
|
|
public function update(Request $request, string $type)
|
|
{
|
|
$this->authorize('create', LegalDocument::class);
|
|
|
|
$validated = $request->validate([
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'content' => ['required', 'string'],
|
|
'version' => ['required', 'string', 'max:50'],
|
|
'published_at' => ['nullable', 'date'],
|
|
]);
|
|
|
|
$document = LegalDocument::where('type', $type)->latest('version')->first();
|
|
|
|
if ($document && $document->version === $validated['version']) {
|
|
$document->update([
|
|
'title' => $validated['title'],
|
|
'content' => $validated['content'],
|
|
'published_at' => $validated['published_at'] ? now() : null,
|
|
]);
|
|
} else {
|
|
$document = LegalDocument::create(array_merge($validated, [
|
|
'type' => $type,
|
|
'published_by' => Auth::id(),
|
|
'published_at' => $validated['published_at'] ?? now(),
|
|
]));
|
|
}
|
|
|
|
return redirect()->route('legal.documents.index')->with('success', 'Documento atualizado com sucesso.');
|
|
}
|
|
|
|
/**
|
|
* Display the legal document page.
|
|
*/
|
|
public function show(string $type): View|RedirectResponse
|
|
{
|
|
$document = LegalDocument::where('type', $type)->latest('version')->firstOrFail();
|
|
|
|
$pendingAcceptance = false;
|
|
if (Auth::check() && Auth::user()->role !== 'superadmin') {
|
|
$accepted = UserDocumentAcceptance::where('user_id', Auth::id())
|
|
->where('legal_document_id', $document->id)
|
|
->exists();
|
|
|
|
if (!$accepted) {
|
|
$pendingAcceptance = true;
|
|
}
|
|
}
|
|
|
|
return view('legal.documents.show', compact('document', 'pendingAcceptance'));
|
|
}
|
|
|
|
/**
|
|
* Accept a legal document.
|
|
*/
|
|
public function accept(string $type): RedirectResponse
|
|
{
|
|
$document = LegalDocument::where('type', $type)->latest('version')->firstOrFail();
|
|
|
|
if (Auth::check()) {
|
|
UserDocumentAcceptance::updateOrCreate(
|
|
[
|
|
'user_id' => Auth::id(),
|
|
'legal_document_id' => $document->id,
|
|
],
|
|
[
|
|
'document_version' => $document->version,
|
|
'ip_address' => request()->ip(),
|
|
'user_agent' => request()->userAgent(),
|
|
'accepted_at' => now(),
|
|
]
|
|
);
|
|
}
|
|
|
|
return redirect()->route('dashboard')
|
|
->with('success', 'Documento aceito com sucesso.');
|
|
}
|
|
}
|