Bugfix: Validation consumption#225
Open
giovanny07 wants to merge 3 commits intopluginsGLPI:mainfrom
Open
Conversation
stonebuzz
requested changes
May 4, 2026
| ERROR, | ||
| ); | ||
| Html::back(); | ||
| if (!Session::haveRight('ticket', UPDATE) && !Session::haveRight(Entity::$rightname, UPDATE)) { |
Contributor
There was a problem hiding this comment.
Why add a validation check when modifying an entity?
A technician updating a ticket (including data coming from the credit plugin) does not necessarily have the permissions required to update the associated entity.
Comment on lines
+268
to
+308
| $ticket_id = filter_var( | ||
| $input['tickets_id'] ?? null, | ||
| FILTER_VALIDATE_INT, | ||
| ['options' => ['min_range' => 1]], | ||
| ); | ||
| if ($ticket_id === false) { | ||
| Session::addMessageAfterRedirect( | ||
| __s('Ticket is mandatory.', 'credit'), | ||
| true, | ||
| ERROR, | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| $credit_id = filter_var( | ||
| $input['plugin_credit_entities_id'] ?? null, | ||
| FILTER_VALIDATE_INT, | ||
| ['options' => ['min_range' => 1]], | ||
| ); | ||
| if ($credit_id === false) { | ||
| Session::addMessageAfterRedirect( | ||
| __s('Credit voucher entity must be selected.', 'credit'), | ||
| true, | ||
| ERROR, | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| $consumed = filter_var( | ||
| $input['consumed'] ?? null, | ||
| FILTER_VALIDATE_INT, | ||
| ['options' => ['min_range' => 1]], | ||
| ); | ||
| if ($consumed === false) { | ||
| Session::addMessageAfterRedirect( | ||
| __s('Credit voucher quantity must be greater than 0.', 'credit'), | ||
| true, | ||
| ERROR, | ||
| ); | ||
| return false; | ||
| } |
Contributor
There was a problem hiding this comment.
Redundant code with prepareInputForUpdate
This logic duplicates functionality already present in prepareInputForUpdate.
It could be refactored into a dedicated checkInput function, or merged into getValidatedConsumptionInput, which should be renamed accordingly to better reflect its broader responsibility.
|
|
||
| - Improve consumed credits modal readability and open related tickets in a new tab | ||
| - Show credit vouchers list in entity tab for read-only users while keeping add/config forms restricted to editable contexts. | ||
| - Centralize credit consumption validation, prevent invalid voucher selections outside the validity window, and fix the ticket tab quantity field behavior. |
Contributor
There was a problem hiding this comment.
Suggested change
| - Centralize credit consumption validation, prevent invalid voucher selections outside the validity window, and fix the ticket tab quantity field behavior. | |
| - Improve credit validation and voucher handling. |
Rom1-B
requested changes
May 4, 2026
|
|
||
| use Glpi\Exception\Http\BadRequestHttpException; | ||
|
|
||
| Session::haveRight("ticket", UPDATE); |
Contributor
There was a problem hiding this comment.
Suggested change
| Session::haveRight("ticket", UPDATE); | |
| Session::checkRight(\Ticket::class, UPDATE); |
Comment on lines
-37
to
-50
| if ($_REQUEST['plugin_credit_entities_id'] == 0) { | ||
| Session::addMessageAfterRedirect( | ||
| __s('Credit voucher entity must be selected.', 'credit'), | ||
| true, | ||
| ERROR, | ||
| ); | ||
| Html::back(); | ||
| } elseif ($_REQUEST['plugin_credit_quantity'] == 0) { | ||
| Session::addMessageAfterRedirect( | ||
| __s('Credit voucher quantity must be greater than 0.', 'credit'), | ||
| true, | ||
| ERROR, | ||
| ); | ||
| Html::back(); |
Contributor
|
Hi @giovanny07 can you rebase ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Description
This PR centralizes credit consumption validation so both the manual ticket form and the hook-driven followup/task/solution flow
use the same server-side rules. It also prevents selecting vouchers outside their valid begin/end date window and fixes the
ticket-tab JavaScript that broke the quantity field when selecting a voucher.
Validation performed:
find inc front ajax -name '*.php' -print0 | xargs -0 -n1 php -lgit diff --check