From 65b6eaf8580482db38af03ac1c204b053774eadd Mon Sep 17 00:00:00 2001 From: BAYARD Eric Date: Tue, 28 Feb 2023 15:27:07 +0100 Subject: [PATCH] =?UTF-8?q?ADD=20:=20ajout=20des=20suivis=20dans=20les=20r?= =?UTF-8?q?=C3=A8gles=20m=C3=A9tier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/ruleitilfollowup.form.php | 37 ++++ front/ruleitilfollowup.php | 37 ++++ inc/define.php | 3 +- inc/itilfollowup.class.php | 18 ++ inc/ruleitilfollowup.class.php | 228 +++++++++++++++++++++++ inc/ruleitilfollowupcollection.class.php | 129 +++++++++++++ 6 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 front/ruleitilfollowup.form.php create mode 100644 front/ruleitilfollowup.php create mode 100644 inc/ruleitilfollowup.class.php create mode 100644 inc/ruleitilfollowupcollection.class.php diff --git a/front/ruleitilfollowup.form.php b/front/ruleitilfollowup.form.php new file mode 100644 index 0000000000..e666ae3a65 --- /dev/null +++ b/front/ruleitilfollowup.form.php @@ -0,0 +1,37 @@ +. + * --------------------------------------------------------------------- + */ + +include ('../inc/includes.php'); + +$rulecollection = new RuleItilFollowupCollection($_SESSION['glpiactive_entity']); + +include (GLPI_ROOT . "/front/rule.common.form.php"); diff --git a/front/ruleitilfollowup.php b/front/ruleitilfollowup.php new file mode 100644 index 0000000000..5094ad33b6 --- /dev/null +++ b/front/ruleitilfollowup.php @@ -0,0 +1,37 @@ +. + * --------------------------------------------------------------------- + */ + +include ('../inc/includes.php'); + +$rulecollection = new RuleItilFollowupCollection($_SESSION['glpiactive_entity']); + +include (GLPI_ROOT . "/front/rule.common.php"); diff --git a/inc/define.php b/inc/define.php index dc7efdfddf..fa8a5715f2 100644 --- a/inc/define.php +++ b/inc/define.php @@ -360,7 +360,8 @@ 'RuleRightCollection', 'RuleSoftwareCategoryCollection', 'RuleTicketCollection', - 'RuleAssetCollection']; + 'RuleAssetCollection', + 'RuleItilFollowupCollection']; // Items which can planned something $CFG_GLPI['planning_types'] = ['ChangeTask', 'ProblemTask', 'Reminder', diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php index be3360f271..735dcc0128 100644 --- a/inc/itilfollowup.class.php +++ b/inc/itilfollowup.class.php @@ -414,6 +414,24 @@ function prepareInputForAdd($input) { if (!isset($input['date'])) { $input["date"] = $_SESSION["glpi_currenttime"]; } + + $entid = 0; + if (isset($input['entities_id'])) { + $entid = $input['entities_id']; + } else { + if (isset($this->fields['entities_id'])) { + $entid = $this->fields['entities_id']; + } + } + $rules = new RuleItilFollowupCollection($entid); + + $input = $rules->processAllRules($input, + $input, + ['recursive' => true], + ['condition' => RuleTicket::ONADD]); + + $input = Toolbox::stripslashes_deep($input); + return $input; } diff --git a/inc/ruleitilfollowup.class.php b/inc/ruleitilfollowup.class.php new file mode 100644 index 0000000000..851f6d8594 --- /dev/null +++ b/inc/ruleitilfollowup.class.php @@ -0,0 +1,228 @@ +. + * --------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + + +class RuleItilFollowup extends Rule { + + // From Rule + static $rightname = 'rule_ticket'; + public $can_sort = true; + + const PARENT = 1024; + + + const ONADD = 1; + const ONUPDATE = 2; + + function getTitle() { + return __('Business rules for tickets followups'); + } + + /** + * @since 0.85 + **/ + static function getConditionsArray() { + + return [static::ONADD => __('Add'), + static::ONUPDATE => __('Update'), + static::ONADD|static::ONUPDATE => sprintf(__('%1$s / %2$s'), __('Add'), + __('Update'))]; + } + + function executeActions($output, $params, array $input = []) { + if (count($this->actions)) { + foreach ($this->actions as $action) { + switch ($action->fields["action_type"]) { + case "assign" : + $output[$action->fields["field"]] = $action->fields["value"]; + + if ($action->fields["field"] === 'status') { + $output['_'.$action->fields["field"]] = $action->fields["value"]; + // Add a flag to remember that status was forced by rule + $output['_do_not_compute_status'] = true; + } + + break; + } + } + } + + return $output; + } + + function getCriterias() { + + static $criterias = []; + + if (count($criterias)) { + return $criterias; + } + + $criterias['itemtype']['name'] = 'Type du parent'; + $criterias['itemtype']['field'] = '__itilfollowup__itemtype'; + $criterias['itemtype']['type'] = 'dropdown_followup_itemtype'; + + $criterias['__itilfollowup_author']['name'] = 'Auteur du suivi'; + $criterias['__itilfollowup_author']['field'] = '__itilfollowup_author'; + $criterias['__itilfollowup_author']['type'] = 'dropdown_followup_usertype'; + $criterias['__itilfollowup_author']['allow_condition'] = [ + Rule::PATTERN_IS, + Rule::PATTERN_IS_NOT, + ]; + + return $criterias; + } + + function getActions() { + $actions = []; + + $actions['status']['name'] = 'Status du parent'; + $actions['status']['type'] = 'dropdown_status'; + + return $actions; + } + + function displayCriteriaSelectPattern($name, $ID, $condition, $value = "", $test = false) { + $crit = $this->getCriteria($ID); + $display = false; + $tested = false; + + if (isset($crit['field'])) { + if ($crit['field'] == '__itilfollowup_author') { + Dropdown::showFromArray($name, $this->genereArrayDropdownFollowupUsertype()); + return; + } + if ($crit['field'] == '__itilfollowup__itemtype') { + Dropdown::showFromArray($name, $this->genereArrayDropdownFollowupItemtype()); + return; + } + } + + return parent::displayCriteriaSelectPattern($name, $ID, $condition, $value, $test); + } + + function checkCriteria(&$criteria, &$input) { + if (isset($input['items_id'])) { + $idParent = $input['items_id']; + } else { + return false; + } + if (isset($input['itemtype'])) { + $itemtype = $input['itemtype']; + } else { + return false; + } + if (isset($input['users_id'])) { + $users_id_add_followup = $input['users_id']; + } else { + return false; + } + + if (isset($criteria->fields['criteria'])) { + if ($criteria->fields['criteria'] == '__itilfollowup_author') { + switch ($itemtype) { + case 'Ticket': + $common = new Ticket_User; + $tab_actors = $common->find(['tickets_id' => $idParent, 'type' => $criteria->fields['pattern'], 'users_id' => $users_id_add_followup], [], 1); + break; + + case 'Change': + $common = new Change_User; + $tab_actors = $common->find(['changes_id' => $idParent, 'type' => $criteria->fields['pattern'], 'users_id' => $users_id_add_followup]); + break; + + case 'Problem': + $common = new Problem_User; + $tab_actors = $common->find(['problems_id' => $idParent, 'type' => $criteria->fields['pattern'], 'users_id' => $users_id_add_followup]); + break; + + default: + return false; + } + + if ($tab_actors == 0) { + return false; + } + return true; + } + + if ($criteria->fields['criteria'] == 'itemtype') { + if ($criteria->fields['pattern'] == $itemtype) { + return true; + } + return false; + } + } + + return parent::checkCriteria($criteria, $input); + + } + + function getCriteriaDisplayPattern($ID, $condition, $pattern) { + $crit = $this->getCriteria($ID); + + if (isset($crit['type'])) { + switch ($crit['type']) { + case "dropdown_followup_usertype" : + $tab = $this->genereArrayDropdownFollowupUsertype(); + return $tab[$pattern]; + case "dropdown_followup_itemtype" : + $tab = $this->genereArrayDropdownFollowupItemtype(); + return $tab[$pattern]; + + } + } + return parent::getCriteriaDisplayPattern($ID, $condition, $pattern); + + } + + function genereArrayDropdownFollowupUsertype () { + return [ + CommonITILActor::OBSERVER => _n('Watcher', 'Watchers', 1), + CommonITILActor::REQUESTER => _n('Requester', 'Demandeurs', 1), + CommonITILActor::ASSIGN => __('Technician'), + ]; + } + + function genereArrayDropdownFollowupItemtype () { + return [ + 'Ticket' => _n('Ticket', 'Tickets', 1), + 'Change' => _n('Change', 'Changes', 1), + 'Problem' => _n('Problem', 'Problems', 1), + ]; + } + +} diff --git a/inc/ruleitilfollowupcollection.class.php b/inc/ruleitilfollowupcollection.class.php new file mode 100644 index 0000000000..04367dc81b --- /dev/null +++ b/inc/ruleitilfollowupcollection.class.php @@ -0,0 +1,129 @@ +. + * --------------------------------------------------------------------- + */ + +if (!defined('GLPI_ROOT')) { + die("Sorry. You can't access this file directly"); +} + +class RuleItilFollowupCollection extends RuleCollection { + + // From RuleCollection + static $rightname = 'rule_ticket'; + public $use_output_rule_process_as_next_input = true; + public $menu_option = 'itilfollowup'; + + + /** + * @param $entity (default 0) + **/ + function __construct($entity = 0) { + $this->entity = $entity; + } + + + /** + * @since 0.84 + **/ + static function canView() { + return Session::haveRightsOr(self::$rightname, [READ, RuleItilFollowup::PARENT]); + } + + + function canList() { + return static::canView(); + } + + + function getTitle() { + return __('Business rules for tickets followups'); + } + + + /** + * @see RuleCollection::preProcessPreviewResults() + **/ + function preProcessPreviewResults($output) { + + $output = parent::preProcessPreviewResults($output); + return Ticket::showPreviewAssignAction($output); + } + + + /** + * @see RuleCollection::showInheritedTab() + **/ + function showInheritedTab() { + return (Session::haveRight(self::$rightname, RuleItilFollowup::PARENT) && ($this->entity)); + } + + + /** + * @see RuleCollection::showChildrensTab() + **/ + function showChildrensTab() { + + return (Session::haveRight(self::$rightname, READ) + && (count($_SESSION['glpiactiveentities']) > 1)); + } + + + /** + * @see RuleCollection::prepareInputDataForProcess() + **/ + function prepareInputDataForProcess($input, $params) { + + // Pass x-priority header if exists + if (isset($input['_head']['x-priority'])) { + $input['_x-priority'] = $input['_head']['x-priority']; + } + $input['_groups_id_of_requester'] = []; + // Get groups of users + if (isset($input['_users_id_requester'])) { + if (!is_array($input['_users_id_requester'])) { + $requesters = [$input['_users_id_requester']]; + } else { + $requesters = $input['_users_id_requester']; + } + foreach ($requesters as $uid) { + foreach (Group_User::getUserGroups($uid) as $g) { + $input['_groups_id_of_requester'][$g['id']] = $g['id']; + } + } + } + + if (isset($input['itilcategories_id'])) { + $input['itilcategories_id_cn'] = $input['itilcategories_id']; + } + return $input; + } + +}