Skip to content

Commit

Permalink
Merge branch 'feature/21375_validation_ratio_in_issue' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 1, 2021
2 parents 429453d + e1a9d18 commit 2e4edc0
Show file tree
Hide file tree
Showing 21 changed files with 1,093 additions and 441 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"scripts": {
"cs": "vendor/bin/phpcs -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/ RoboFile.php",
"cbf": "vendor/bin/phpcbf -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/ RoboFile.php",
"lint": "vendor/bin/parallel-lint --exclude vendor ."
}
}
60 changes: 60 additions & 0 deletions front/form_validator.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2021 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/

include ('../../../inc/includes.php');

Session::checkRight('entity', UPDATE);

// Check if plugin is activated...
if (!(new Plugin())->isActivated('formcreator')) {
Html::displayNotFoundError();
}

if (!isset($_POST['plugin_formcreator_forms_id'])) {
// should not happen
Html::back();
}
$formId = (int) $_POST['plugin_formcreator_forms_id'];
$formValidator = new PluginFormcreatorForm_Validator();
$form = new PluginFormcreatorForm();
if (isset($_POST['add'])) {
// Add a new Form
Session::checkRight('entity', UPDATE);
$formValidator->addMultipleItems($_POST);
Html::redirect($form->getFormURLWithID($formId));
} else if (isset($_POST['set_validation_percent'])) {
$form->update([
'id' => $formId,
'validation_percent' => $_POST['validation_percent'],
]);
Html::redirect($form->getFormURLWithID($formId));
}
Html::back();
25 changes: 15 additions & 10 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,34 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
*/
function plugin_formcreator_getCondition($itemtype) {
$table = $itemtype::getTable();
$currentUserId = Session::getLoginUserID();

if ($itemtype == PluginFormcreatorFormAnswer::class) {
if (Session::haveRight('config', UPDATE)) {
return '';
}
if (PluginFormcreatorCommon::canValidate()) {
$groupUser = new Group_User();
$groups = $groupUser->getUserGroups($_SESSION['glpiID']);
$condition = " (`$table`.`users_id_validator` =". $_SESSION['glpiID'];
$groups = $groupUser->getUserGroups($currentUserId);
$condition = " (`$table`.`users_id_validator` = $currentUserId";
if (count($groups) < 1) {
$condition .= ")";
} else {
$groupIDs = [];
foreach ($groups as $group) {
$groupIDs[] = $group['id'];
}
$groupIDs = implode(',', $groupIDs);
$condition .= " OR `$table`.`groups_id_validator` IN ($groupIDs) )";
return $condition;
}

// Add current user's groups to the condition
$groupIDs = [];
foreach ($groups as $group) {
$groupIDs[] = $group['id'];
}
$groupIDs = implode(',', $groupIDs);
$condition .= " OR `$table`.`groups_id_validator` IN ($groupIDs)";
$condition .= ")";
return $condition;
}
}

return " `$table`.`requester_id` = " . $_SESSION['glpiID'];
return " `$table`.`requester_id` = $currentUserId";
}

/**
Expand Down
5 changes: 0 additions & 5 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,6 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
]
]);
foreach ($rows as $actor) {
// If actor type is validator and if the form doesn't have a validator, continue to other actors
if ($actor['actor_type'] == PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR && !$form->fields['validation_required']) {
continue;
}

switch ($actor['actor_type']) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_AUTHOR :
$userIds = [$formanswer->fields['requester_id']];
Expand Down
5 changes: 4 additions & 1 deletion inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ public static function getTicketStatusForIssue(Ticket $item) : array {
'timeline_position ASC'
], 1);
$user = 0;
$reloadedItem = new Ticket();
$reloadedItem->getFromDB($item->getID());
$validationPercent = $reloadedItem->fields['validation_percent'];
$ticketValidationCount = count($ticketValidations);
if ($ticketValidationCount) {
$row = array_shift($ticketValidations);
Expand All @@ -289,7 +292,7 @@ public static function getTicketStatusForIssue(Ticket $item) : array {
}
}

return ['status' => $status, 'user' => $user];
return ['status' => $status, 'user' => $user, 'validation_percent' => $validationPercent];
}

/**
Expand Down
Loading

0 comments on commit 2e4edc0

Please sign in to comment.