mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-27 00:59:18 +02:00
feat: prevent duplicate TFE submissions with logging and user feedback
- Add DuplicateThesisException (typed, carries existing thesis metadata) - Add Database::findDuplicateThesis(): matches on year + author + normalised title (exact, prefix, Levenshtein ≤10% of longer string) - ThesisCreateController::submit() runs duplicate check before any DB write and throws DuplicateThesisException on match - AppLogger::logDuplicate() writes status=duplicate entries to the JSON-lines log for audit purposes - App::flash/consumeFlash extended to support 'warning' flash type - admin/actions/formulaire.php: catches DuplicateThesisException, logs it, flashes an HTML warning toast with a clickable link to the existing thesis, and repopulates the form fields - partage/index.php: same catch block; surfaces a plain-text flash-warning banner on the student form with identifier, title, and year of the match; form is repopulated via session - toast.php: renders toast--warning variant - admin.css: .toast--warning + link colour rules - form.css: .flash-warning style for the partage form
This commit is contained in:
25
app/src/DuplicateThesisException.php
Normal file
25
app/src/DuplicateThesisException.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Thrown when a submission would create a thesis that is too similar to an
|
||||
* already-existing record.
|
||||
*
|
||||
* Carries enough information for the caller to build a useful warning message
|
||||
* with a link to the existing thesis.
|
||||
*/
|
||||
class DuplicateThesisException extends RuntimeException
|
||||
{
|
||||
public function __construct(
|
||||
public readonly int $existingThesisId,
|
||||
public readonly string $existingIdentifier,
|
||||
public readonly string $existingTitle,
|
||||
public readonly string $existingAuthor,
|
||||
public readonly int $existingYear,
|
||||
string $message = ''
|
||||
) {
|
||||
if ($message === '') {
|
||||
$message = "Un TFE similaire existe déjà ($existingIdentifier — $existingAuthor, $existingYear).";
|
||||
}
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user