From fbd0239e4eb357dfd2771e1f4af5fc44ca3cc13e Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 6 Aug 2019 15:26:07 +0200 Subject: [PATCH] Added adhoc users re-assign rights Added possibility to assign a task to an adhoc user Added task del_index tag to notification template Added missing GLPI_ITEM_TASK_GROUP Deleted extra-email sending Fixed issue on users for re-assignment Set version to 3.6.4 --- front/processmaker.form.php | 10 ++++++++-- inc/case.class.php | 13 ++++++++++--- inc/notificationtargettask.class.php | 6 +++++- inc/processmaker.class.php | 19 +++++++------------ inc/profile.class.php | 4 ++-- inc/task.class.php | 18 +++++++++++++++--- inc/user.class.php | 20 +++++++++++++------- processmaker.xml | 6 +++--- setup.php | 5 ++++- 9 files changed, 67 insertions(+), 34 deletions(-) diff --git a/front/processmaker.form.php b/front/processmaker.form.php index edd9106..5f44cb5 100644 --- a/front/processmaker.form.php +++ b/front/processmaker.form.php @@ -85,7 +85,7 @@ switch ($_POST["action"]) { } else if (isset($_POST['reassign'])) { // here we should re-assign the current task to $_POST['users_id_recipient'] //$GLPINewPMUserId = PluginProcessmakerUser::getPMUserId( $_POST['users_id_recipient'] ); - if ($_POST['users_id'] != $_POST['users_id_recipient']) { // normally should be different as of the dropdown prevents already used + if ($_POST['users_id'] != $_POST['users_id_recipient'] && $_POST['users_id_recipient'] != 0) { // normally should be different as of the dropdown prevents already used $locCase = new PluginProcessmakerCase; $locCase->getFromDB($_POST['cases_id']); @@ -100,7 +100,13 @@ switch ($_POST["action"]) { Session::addMessageAfterRedirect(__('Error re-assigning task: ', 'processmaker').$pmResponse->message, true, ERROR); } } else { - Session::addMessageAfterRedirect(__('Task already assigned to this person!', 'processmaker'), true, ERROR); + if ($_POST['users_id_recipient'] == 0) { + Session::addMessageAfterRedirect(__('Can\'t un-assign Task!', 'processmaker'), true, ERROR); + } else { + if ($_POST['users_id'] === $_POST['users_id_recipient'] ) { // normally should be different as of the dropdown prevents already used + Session::addMessageAfterRedirect(__('Task already assigned to this person!', 'processmaker'), true, ERROR); + } + } } //} else if (isset($_POST['delete'])) { // // delete case from case table, this will also delete the tasks diff --git a/inc/case.class.php b/inc/case.class.php index 6ba292a..de22142 100644 --- a/inc/case.class.php +++ b/inc/case.class.php @@ -232,10 +232,13 @@ class PluginProcessmakerCase extends CommonDBTM { */ function reassignCase($delIndex, $taskGuid, $delThread, $users_id_source, $users_id_target) { global $PM_SOAP; - $users_guid_source = PluginProcessmakerUser::getPMUserId($users_id_source); + $users_guid_source = ''; // by default + if ($users_id_source !== 0) { // when task is not 'to be claimed' + $users_guid_source = PluginProcessmakerUser::getPMUserId($users_id_source); + } $users_guid_target = PluginProcessmakerUser::getPMUserId($users_id_target); $pmResponse = $PM_SOAP->reassignCase($this->fields['case_guid'], $delIndex, $users_guid_source, $users_guid_target); - // now should managed GLPI Tasks previously assigned to the $users_guid_source + // now should manage GLPI Tasks previously assigned to the $users_guid_source if ($pmResponse->status_code == 0) { // we need to change the delindex of the glpi task and the assigned tech to prevent creation of new tasks // we need the delindex of the current glpi task, and the delindex of the new one @@ -279,7 +282,11 @@ class PluginProcessmakerCase extends CommonDBTM { PluginProcessmakerProcessmaker::addWatcher( $itilobject_itemtype, $glpi_task->fields[ $foreignkey ], $newTech ); $donotif = PluginProcessmakerNotificationTargetProcessmaker::saveNotificationState(false); // do not send notification yet - $glpi_task->update( ['id' => $glpi_task->getID(), $foreignkey => $glpi_task->fields[$foreignkey], 'users_id_tech' => $newTech, 'update' => true] ); + $glpi_task->update( ['id' => $glpi_task->getID(), + $foreignkey => $glpi_task->fields[$foreignkey], + 'users_id_tech' => $newTech, + 'groups_id_tech' => 0, + 'update' => true] ); PluginProcessmakerNotificationTargetProcessmaker::restoreNotificationState($donotif); // Notification management diff --git a/inc/notificationtargettask.class.php b/inc/notificationtargettask.class.php index 948be21..3932b1c 100644 --- a/inc/notificationtargettask.class.php +++ b/inc/notificationtargettask.class.php @@ -105,6 +105,9 @@ class PluginProcessmakerNotificationTargetTask extends PluginProcessmakerNotific // task information $taskobj = $this->obj; + // del index + $this->data['##task.delindex##'] = $taskobj->fields['del_index']; + // is private? $this->data['##task.isprivate##'] = Dropdown::getYesNo(false); if ($taskobj->maybePrivate()) { @@ -175,7 +178,8 @@ class PluginProcessmakerNotificationTargetTask extends PluginProcessmakerNotific 'task.end' => __('End date'), 'task.status' => __('Status'), 'task.lastupdater' => __('Last updater'), - 'task.update' => __('Last update') + 'task.update' => __('Last update'), + 'task.delindex' => __('Delegation index') ]; foreach ($tags as $tag => $label) { $elt= ['tag' => $tag, diff --git a/inc/processmaker.class.php b/inc/processmaker.class.php index dede130..99e9952 100644 --- a/inc/processmaker.class.php +++ b/inc/processmaker.class.php @@ -2913,6 +2913,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { $casevariables = ["GLPI_ITEM_TASK_CONTENT", "GLPI_ITEM_APPEND_TO_TASK", "GLPI_NEXT_GROUP_TO_BE_ASSIGNED", + "GLPI_ITEM_TASK_GROUP", "GLPI_ITEM_TITLE", "GLPI_TICKET_FOLLOWUP_CONTENT", "GLPI_ITEM_FOLLOWUP_CONTENT", @@ -2971,6 +2972,9 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { if (array_key_exists( 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED', $casevariablevalues )) { $groupId = $casevariablevalues[ 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' ]; } + if (array_key_exists( 'GLPI_ITEM_TASK_GROUP', $casevariablevalues )) { + $groupId = $casevariablevalues[ 'GLPI_ITEM_TASK_GROUP' ]; + } $taskStartDate = ''; $taskEndDate = ''; @@ -3237,16 +3241,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { } } - // send email if requested - if (is_array($sendemail)) { - NotificationEvent::raiseEvent('send_email', - $myCase, - ['glpi_send_email' => $sendemail, - 'case' => $myCase - ]); - } - - } + } } else { // must check if current case is a sub-process, and if it has ended, then must reflect parent case into the current item. @@ -3278,7 +3273,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { $parentCaseInfo, $open_task->delIndex, PluginProcessmakerUser::getGLPIUserId($open_task->userId), - 0, + $groupId, $open_task->taskId, $open_task->delThread, [ 'txtTaskContent' => $txtTaskContent, @@ -3289,7 +3284,7 @@ class PluginProcessmakerProcessmaker extends CommonDBTM { // if end date was specified, then must change due date of the PM task if ($taskEndDate != '') { - $PM_DB->update('APP_DELEGATION', ['DEL_TASK_DUE_DATE' => $taskEndDate], ['AND' => ['APP_UID' => $sub_caseInfo->caseId, 'DEL_INDEX' => $open_task->delIndex]]); + $PM_DB->update('APP_DELEGATION', ['DEL_TASK_DUE_DATE' => $taskEndDate], ['AND' => ['APP_UID' => $parentCaseInfo->caseId, 'DEL_INDEX' => $open_task->delIndex]]); //$PM_DB->query( "UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$taskEndDate' WHERE APP_UID='".$sub_caseInfo->caseId."' AND DEL_INDEX=".$open_task->delIndex); } } diff --git a/inc/profile.class.php b/inc/profile.class.php index b1c2fe0..a53a16c 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -20,7 +20,7 @@ class PluginProcessmakerProfile extends CommonDBTM { ['itemtype' => 'PluginProcessmakerConfig', 'label' => __('Cases', 'processmaker'), 'field' => 'plugin_processmaker_case', - 'rights' => [READ => __('Read'), CANCEL => __('Cancel', 'processmaker'), DELETE => __('Delete')]] + 'rights' => [READ => __('Read'), CANCEL => __('Cancel', 'processmaker'), DELETE => __('Delete'), ADHOC_REASSIGN => __('Ad Hoc user re-assign', 'processmaker')]] ]; return $rights; @@ -69,7 +69,7 @@ class PluginProcessmakerProfile extends CommonDBTM { * @param mixed $ID */ static function createAdminAccess($ID) { - self::addDefaultProfileInfos($ID, ['plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_case' => READ + DELETE + CANCEL], true); + self::addDefaultProfileInfos($ID, ['plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_case' => READ + DELETE + CANCEL + ADHOC_REASSIGN], true); } /** diff --git a/inc/task.class.php b/inc/task.class.php index e7c43cc..9c2f214 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -377,8 +377,8 @@ class PluginProcessmakerTask extends CommonITILTask } if (isset($currentUser)) { - if ($currentUser->userId && $task[$tabnum]['del_index']) { - // to load users for task re-assign only when task is not to be 'claimed' and if task is not a sub-case + if (/*$currentUser->userId &&*/ $task[$tabnum]['del_index']) { + // to load users for task re-assign only when task is not a sub-case echo "
".__('Loading...')."
"; echo ""; - } else { + //} else { + // // manages the claim + // // current task is to be claimed + // // get the assigned group to the item task + // $itemtask = $dbu->getItemForItemtype( $task[$tabnum]['itemtype'] ); + // $itemtask->getFromDB( $task[$tabnum]['items_id'] ); + // // check if this group can be found in the current user's groups + // if (!isset($_SESSION['glpigroups']) || !in_array( $itemtask->fields['groups_id_tech'], $_SESSION['glpigroups'] )) { + // $hide_claim_button=true; + // } + } + + if (!$currentUser->userId || !$task[$tabnum]['del_index']) { // manages the claim // current task is to be claimed // get the assigned group to the item task diff --git a/inc/user.class.php b/inc/user.class.php index a8aae84..be981f3 100644 --- a/inc/user.class.php +++ b/inc/user.class.php @@ -28,8 +28,12 @@ class PluginProcessmakerUser extends CommonDBTM { static function getSqlSearchResult ($taskId, $count = true, $right = "all", $entity_restrict = -1, $value = 0, $used = [], $search = '', $limit = '') { global $DB, $PM_DB, $CFG_GLPI; + // first need to get all users from $taskId + $adhoc_users = Session::haveRight('plugin_processmaker_case', ADHOC_REASSIGN) ? 2 : -1; + // TU_TYPE in (1, 2) means 1 is normal, 2 is for adhoc + // TU_RELATION is 1 for user, and 2 for group $res1 = new QuerySubQuery([ - 'SELECT' => ['GROUP_USER.USR_UID AS pm_user_id'], + 'SELECT' => 'GROUP_USER.USR_UID AS pm_user_id', 'FROM' => 'TASK_USER', 'INNER JOIN' => [ 'GROUP_USER' => [ @@ -37,12 +41,15 @@ class PluginProcessmakerUser extends CommonDBTM { 'GROUP_USER' => 'GRP_UID', 'TASK_USER' => 'USR_UID', ['AND' => [ - 'TASk_USER.TU_RELATION' => 2, - 'TASk_USER.TU_TYPE' => 1 + 'TASK_USER.TU_RELATION' => 2, + 'TASK_USER.TU_TYPE' => [1, $adhoc_users] ] ] ] ] + ], + 'WHERE' => [ + 'TAS_UID' => $taskId, ] ]); $res2 = new QuerySubQuery([ @@ -52,7 +59,7 @@ class PluginProcessmakerUser extends CommonDBTM { 'AND' => [ 'TAS_UID' => $taskId, 'TASK_USER.TU_RELATION' => 1, - 'TASk_USER.TU_TYPE' => 1 + 'TASK_USER.TU_TYPE' => [1, $adhoc_users] ] ] ]); @@ -60,7 +67,6 @@ class PluginProcessmakerUser extends CommonDBTM { $res = $PM_DB->request([ 'FROM' => $union ]); - // first need to get all users from $taskId //$db_pm = PluginProcessmakerConfig::getInstance()->getProcessMakerDB(); //$pmQuery = "SELECT GROUP_USER.USR_UID AS pm_user_id FROM TASK_USER // JOIN GROUP_USER ON GROUP_USER.GRP_UID=TASK_USER.USR_UID AND TASK_USER.TU_RELATION = 2 AND TASK_USER.TU_TYPE=1 @@ -85,8 +91,8 @@ class PluginProcessmakerUser extends CommonDBTM { break; case "all" : - //$where = " `glpi_users`.`id` > '1' "; - $query2['WHERE']['AND']['glpi_users.id'] = ['>', 1]; + //$where = " `glpi_users`.`id` > '0' "; + $query2['WHERE']['AND']['glpi_users.id'] = ['>', 0]; break; } diff --git a/processmaker.xml b/processmaker.xml index 76b3fe6..ebac4e0 100644 --- a/processmaker.xml +++ b/processmaker.xml @@ -29,15 +29,15 @@ 9.1 - 3.4.12 + 3.4.13 9.2 - 3.5.3 + 3.5.4 9.3 - 3.6.3 + 3.6.4 9.4 diff --git a/setup.php b/setup.php index 87edfff..9174687 100644 --- a/setup.php +++ b/setup.php @@ -1,8 +1,11 @@