diff --git a/app/Http/Requests/EndBorrowingRequest.php b/app/Http/Requests/EndBorrowingRequest.php index a4a3a7f..939921c 100644 --- a/app/Http/Requests/EndBorrowingRequest.php +++ b/app/Http/Requests/EndBorrowingRequest.php @@ -30,7 +30,7 @@ public function rules() { return [ 'selectedBorrowings' => 'required|array', - 'selectedBorrowings.*' => 'integer|distinct', // TODO: Prevent self-return of borrowing + 'selectedBorrowings.*' => 'integer|distinct|no_self_return', 'newInventoryItemsStatus' => [ 'required', 'integer', diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 462aa27..0c70d67 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -26,6 +26,7 @@ public function boot() Validator::extend('inventory_item_available', 'App\Validators\InventoryItemAvailable@validate'); Validator::extend('inventory_item_not_borrowed', 'App\Validators\InventoryItemNotBorrowed@validate'); + Validator::extend('no_self_return', 'App\Validators\NoSelfReturn@validate'); Validator::extend('password_for', 'App\Validators\PasswordFor@validate'); Validator::extend('unchanged_during_borrowing', 'App\Validators\UnchangedDuringBorrowing@validate'); Validator::extend('not_changed_to_borrowed', 'App\Validators\NotChangedToBorrowed@validate'); diff --git a/app/Validators/NoSelfReturn.php b/app/Validators/NoSelfReturn.php new file mode 100644 index 0000000..26977b5 --- /dev/null +++ b/app/Validators/NoSelfReturn.php @@ -0,0 +1,19 @@ +select('borrower_id')->first(); + if ($borrowerId) { + $borrowerId = $borrowerId->borrower_id; + return $borrowerId !== Auth::user()->id; + } + + } +} \ No newline at end of file diff --git a/changelog.md b/changelog.md index de91c48..01d6877 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added +* End borrowing validation + * A user can't confirm the return of its own borrowings. * Edit inventory view * Minimal width of tables for better responsiveness. * Edit users view @@ -18,7 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Users updating and deletion. * Edit users validation * Check for admin self-modification. - + ### Removed * Edit inventory view diff --git a/resources/lang/en/validation/endBorrowing.php b/resources/lang/en/validation/endBorrowing.php index 4f510a2..7855e6b 100644 --- a/resources/lang/en/validation/endBorrowing.php +++ b/resources/lang/en/validation/endBorrowing.php @@ -2,5 +2,6 @@ return [ 'selectedBorrowings.required' => 'Select borrowings to end.', - 'selectedBorrowings.*.distinct' => 'The borrowing of :item by :borrower was selected in multiple times.' + 'selectedBorrowings.*.distinct' => 'The borrowing of :item by :borrower was selected in multiple times.', + 'selectedBorrowings.*.no_self_return' => 'A user can\'t confirm the return of one of its own borrowings.' ]; \ No newline at end of file diff --git a/resources/lang/fr/validation/endBorrowing.php b/resources/lang/fr/validation/endBorrowing.php index 09a762e..1d143dd 100644 --- a/resources/lang/fr/validation/endBorrowing.php +++ b/resources/lang/fr/validation/endBorrowing.php @@ -2,5 +2,6 @@ return [ 'selectedBorrowings.required' => 'Sélectionnez des emprunts à terminer.', - 'selectedBorrowings.*.distinct' => 'L\'emprunt du jeu :item par :borrower a été choisi plusieurs fois.' + 'selectedBorrowings.*.distinct' => 'L\'emprunt du jeu :item par :borrower a été choisi plusieurs fois.', + 'selectedBorrowings.*.no_self_return' => 'Un utilisateur ne peut pas valider le retour de son propre emprunt.' ]; \ No newline at end of file