Skip to content

Commit e0ef0d3

Browse files
committed
feat(formanswer): show info if requester id also validator
1 parent df58b1c commit e0ef0d3

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

inc/formanswer.class.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,18 @@ public function post_addItem() {
12881288

12891289
PluginFormcreatorFormanswerValidation::copyValidatorsToValidation($this);
12901290

1291+
// Auto approve if the current user is a level 1 validator
1292+
$current_user = Session::getLoginUserID();
1293+
if (($this->input['users_id_validator'] ?? 0) != 0) {
1294+
$auto_approval = ($current_user == $this->input['users_id_validator']);
1295+
} else if (($this->input['groups_id_validator'] ?? 0) != 0) {
1296+
$auto_approval = ($current_user !== false && in_array($this->input['groups_id_validator'], $_SESSION['glpigroups'] ?? []));
1297+
}
1298+
if ($auto_approval) {
1299+
PluginFormcreatorFormanswerValidation::updateValidationStatus($this, PluginFormcreatorForm_Validator::VALIDATION_STATUS_ACCEPTED);
1300+
Session::addMessageAfterRedirect(__('You are a validator of the form, then your approval hs been added automatically.', 'formcreator'), false, INFO);
1301+
}
1302+
12911303
$this->sendNotification();
12921304
$formAnswer = clone $this;
12931305
if ($this->input['status'] == self::STATUS_ACCEPTED) {
@@ -1902,18 +1914,12 @@ protected function setValidator(array $input): array {
19021914
} else {
19031915
$usersIdValidator = (int) $validatorItem[1];
19041916
}
1905-
if (Session::getLoginUserID(true) != $usersIdValidator) {
1906-
// The requester is not the validator. Validation needed
1907-
$input['status'] = self::STATUS_WAITING;
1908-
}
1917+
$input['status'] = self::STATUS_WAITING;
19091918
}
19101919

19111920
if (in_array($validatorItem[0], [Group::class])) {
19121921
$groupIdValidator = (int) $validatorItem[1];
1913-
if (Session::getLoginUserID(true) !== false && !in_array($groupIdValidator, $_SESSION['glpigroups'])) {
1914-
// The requester is not a member of the validator group. Validation needed
1915-
$input['status'] = self::STATUS_WAITING;
1916-
}
1922+
$input['status'] = self::STATUS_WAITING;
19171923
}
19181924
}
19191925

0 commit comments

Comments
 (0)