Skip to content

Commit

Permalink
Added feature GLPI_TASK_PREVENT_REASSIGN to prevent assignment of a l…
Browse files Browse the repository at this point in the history
…ist of users (can be PM UID, GLPI id, GLPI logon) to a specific task (can be task list)

Set version to 3.4.25
  • Loading branch information
tomolimo committed Oct 7, 2020
1 parent 3d955f8 commit f431637
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 31 deletions.
5 changes: 0 additions & 5 deletions ajax/dropdownUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
}
}

if (!function_exists('dpuser_cmp')) {
function dpuser_cmp($a, $b) {
return strcasecmp($a, $b);
}
}

$datas = [];

Expand Down
2 changes: 1 addition & 1 deletion ajax/task_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

PluginProcessmakerUser::dropdown( ['name' => 'users_id_recipient',
'value' => $_REQUEST['users_id'],
'used' => [$_REQUEST['users_id']],
'used' => $_REQUEST['used'],
'entity' => 0, //$item->fields["entities_id"], // not used, as any user can be assigned to any tasks
'entity_sons' => false, // not used, as any user can be assigned to any tasks
'right' => 'all',
Expand Down
24 changes: 12 additions & 12 deletions inc/case.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ function unassignCase($delIndex, $taskGuid, $tasktype, $tasks_id, $itemtype, $op
// unescape some chars and replace CRLF, CR or LF by <br/>
$info = str_replace(["\\'", '\\"', '\r\n', '\r', '\n'], ["'", '"', '<br>', '<br>', '<br>'], $info);

$glpi_task->add([$foreignkey => $glpi_task->fields[$foreignkey],
'is_private' => 1,
$glpi_task->add([$foreignkey => $glpi_task->fields[$foreignkey],
'is_private' => 0, // a post-only user can't create private task
'taskcategories_id' => $pm_process->fields['taskcategories_id'],
'content' => $DB->escape($info),
'users_id' => $PM_SOAP->taskWriter,
'state' => Planning::INFO,
'users_id_tech' => Session::getLoginUserID(),
'content' => $DB->escape($info),
'users_id' => $PM_SOAP->taskWriter,
'state' => Planning::INFO,
'users_id_tech' => Session::getLoginUserID(),
]);

return true;
Expand Down Expand Up @@ -439,13 +439,13 @@ public function reassignTask ($delIndex, $newDelIndex, $delThread, $newDelThread
// unescape some chars and replace CRLF, CR or LF by <br/>
$info = str_replace(["\\'", '\\"', '\r\n', '\r', '\n'], ["'", '"', '<br>', '<br>', '<br>'], $info);

$glpi_task->add([$foreignkey => $glpi_task->fields[$foreignkey],
'is_private' => 1,
$glpi_task->add([$foreignkey => $glpi_task->fields[$foreignkey],
'is_private' => 0, // a post-only user can't create private task
'taskcategories_id' => $pm_process->fields['taskcategories_id'],
'content' => $DB->escape($info),
'users_id' => $PM_SOAP->taskWriter,
'state' => Planning::INFO,
'users_id_tech' => Session::getLoginUserID(),
'content' => $DB->escape($info),
'users_id' => $PM_SOAP->taskWriter,
'state' => Planning::INFO,
'users_id_tech' => Session::getLoginUserID(),
]);
}
}
Expand Down
54 changes: 43 additions & 11 deletions inc/task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,49 @@ static function displayTabContentForItem(CommonGLPI $case, $tabnum = 1, $withtem
// to load users for task re-assign only when task is not a sub-case

echo "<div class='tab_bg_2' id='divUsers-".$currentUser->delIndex."'><div class='loadingindicator'>".__('Loading...')."</div></div>";
echo "<script>$('#divUsers-{$task[$tabnum]['del_index']}').load( '".$CFG_GLPI["root_doc"]."/plugins/processmaker/ajax/task_users.php?"
."cases_id=".$case->getID()
."&items_id=".$case->fields['items_id']
."&itemtype=".$case->fields['itemtype']
."&tasktype=".$task[$tabnum]['itemtype']
."&tasks_id=".$task[$tabnum]['items_id']
."&users_id=".PluginProcessmakerUser::getGLPIUserId($currentUser->userId)
."&taskGuid=".$currentUser->taskId
."&delIndex={$task[$tabnum]['del_index']}"
."&delThread={$currentUser->delThread}"
."&rand=$rand' ); </script>";

// try to get users whom can't be assigned to this task
// already assigned user can't be assigned again to this task
$current_assigned_user = PluginProcessmakerUser::getGLPIUserId($currentUser->userId);
// and then any forbiden users defined from the case itself
$casevariablevalues = $case->getVariables(['GLPI_TASK_PREVENT_REASSIGN']);
$prevent_assign = [];
if (array_key_exists( 'GLPI_TASK_PREVENT_REASSIGN', $casevariablevalues ) && $casevariablevalues[ 'GLPI_TASK_PREVENT_REASSIGN' ] != '') {
$prevent_assign = json_decode($casevariablevalues[ 'GLPI_TASK_PREVENT_REASSIGN' ], true);
}


$used_users = [];
$used_users[] = $current_assigned_user;
if (array_key_exists($currentUser->taskId, $prevent_assign)) {
if (is_array($prevent_assign[$currentUser->taskId])) {
foreach ($prevent_assign[$currentUser->taskId] as $pmuser) {
$usr_id = PluginProcessmakerUser::getGlpiIdFromAny($pmuser);
if ($usr_id) {
$used_users[] = $usr_id;
}
}
} else {
$usr_id = PluginProcessmakerUser::getGlpiIdFromAny($prevent_assign[$currentUser->taskId]);
if ($usr_id) {
$used_users[] = $usr_id;
}
}
}

$data = "{
cases_id : {$case->getID()},
items_id : {$case->fields['items_id']},
itemtype : '{$case->fields['itemtype']}',
tasktype : '{$task[$tabnum]['itemtype']}',
tasks_id : {$task[$tabnum]['items_id']},
users_id : {$current_assigned_user},
taskGuid : '{$currentUser->taskId}',
delIndex : {$task[$tabnum]['del_index']},
delThread : {$currentUser->delThread},
used : [".join(',', array_unique($used_users))."]
}";
echo html::scriptBlock("$('#divUsers-{$task[$tabnum]['del_index']}').load('".$CFG_GLPI["root_doc"]."/plugins/processmaker/ajax/task_users.php', $data);");
}

if (!$currentUser->userId || !$task[$tabnum]['del_index']) {
Expand Down
26 changes: 26 additions & 0 deletions inc/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public static function getGLPIUserId($pmUserId) {
return 0;
}


/**
* Summary of getPMUserId
* returns processmaker user id for given GLPI user id
Expand All @@ -199,6 +200,31 @@ public static function getPMUserId($glpiUserId) {
return false;
}


/**
* Summary of getGlpiIdFromAny
* Returns the GLPI id of the user or false if not found
* Accept either PM GUID, GLPI logon, or GLPI ID
* @param $any
* @return mixed GLPI ID of the user or fasle if not found
*/
public static function getGlpiIdFromAny($any) {
$ret = self::getGLPIUserId($any);
if ($ret) {
return $ret;
}
$ret = self::getPMUserId($any);
if ($ret) {
return $any;
}
$usr = new User;
if ($usr->getFromDBbyName($any)) {
return $usr->getId();
}
return false;
}


///**
// * Summary of getNewPassword
// * @param mixed $username
Expand Down
2 changes: 1 addition & 1 deletion processmaker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<compatibility>9.1</compatibility>
</version>
<version>
<num>3.4.24</num>
<num>3.4.25</num>
<compatibility>9.2</compatibility>
</version>
</versions>
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('PROCESSMAKER_VERSION', '3.4.24');
define('PROCESSMAKER_VERSION', '3.4.25');

// used for case cancellation
define("CANCEL", 256);
Expand Down

0 comments on commit f431637

Please sign in to comment.