Skip to content

Commit 571e9ce

Browse files
committed
feat(formanswer): update anwers when validating
but not when refusing Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent dbc5ae4 commit 571e9ce

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

inc/formanswer.class.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ public function showForm($ID, $options = []) {
489489
$form = $this->getForm();
490490

491491
$canEdit = $this->fields['status'] == self::STATUS_REFUSED
492-
&& $_SESSION['glpiID'] == $this->fields['requester_id'];
492+
&& Session::getLoginUserID() == $this->fields['requester_id']
493+
|| $this->fields['status'] == self::STATUS_WAITING
494+
&& $this->canValidate();
493495

494496
// form title
495497
echo "<h1 class='form-title'>";
@@ -578,9 +580,10 @@ public function showForm($ID, $options = []) {
578580

579581
echo '</li>';
580582
}
581-
if ($canEdit) {
583+
584+
if ($canEdit || $editMode) {
582585
echo Html::scriptBlock('$(function() {
583-
plugin_formcreator.showFields($("form[name=\'form\']"));
586+
plugin_formcreator.showFields($("form[name=\'' . $formName . '\']"));
584587
})');
585588
}
586589

@@ -729,8 +732,14 @@ public function prepareInputForUpdate($input) {
729732
$input['status'] = self::STATUS_ACCEPTED;
730733
if (isset($input['refuse_formanswer'])) {
731734
$input['status'] = self::STATUS_REFUSED;
735+
// Update is restricted to a subset of fields
736+
$input = [
737+
'id' => $input['id'],
738+
'status' => $input['status'],
739+
'comment' => isset($input['comment']) ? $input['comment'] : 'NULL',
740+
];
741+
$skipValidation = true;
732742
}
733-
$skipValidation = true;
734743
} else {
735744
// The form answer is being updated
736745
$input['status'] = self::STATUS_WAITING;
@@ -741,13 +750,6 @@ public function prepareInputForUpdate($input) {
741750
return false;
742751
}
743752

744-
// Update is restricted to a subset of fields
745-
$input = [
746-
'id' => $input['id'],
747-
'status' => $input['status'],
748-
'comment' => isset($input['comment']) ? $input['comment'] : 'NULL',
749-
];
750-
751753
return $input;
752754
}
753755

0 commit comments

Comments
 (0)