Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to take user's default group on escalade #123

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function hide_show_history(val) {
0 => __("No"),
1 => __('First'),
2 => __('Last'),
3 => __('Default user\'s group', 'escalade')
];

$rand = mt_rand();
Expand Down
81 changes: 50 additions & 31 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,31 +366,44 @@ static function assignUserGroup(Ticket $ticket) {
|| $_SESSION['plugins']['escalade']['config']['use_assign_user_group_creation'] == 0) {
return false;
}

if (isset($ticket->input['_users_id_assign'])
&& $ticket->input['_users_id_assign'] > 0
&& (!isset($ticket->input['_groups_id_assign'])
|| $ticket->input['_groups_id_assign'] <= 0)) {
if ($_SESSION['plugins']['escalade']['config']['use_assign_user_group'] == 1) {
// First group
$ticket->input['_groups_id_assign']
= PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
$ticket->input['_users_id_assign'],
true);
//prevent adding empty group
if (empty($ticket->input['_groups_id_assign'])) {
unset($ticket->input['_groups_id_assign']);
}
} else {
// All groups
$ticket->input['_additional_groups_assigns']
= PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
$ticket->input['_users_id_assign'],
false);
//prevent adding empty group
if (empty($ticket->input['_additional_groups_assigns'])) {
unset($ticket->input['_additional_groups_assigns']);
}
switch ($_SESSION['plugins']['escalade']['config']['use_assign_user_group']) {
case 1 :
// First group
$ticket->input['_groups_id_assign']
= PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
$ticket->input['_users_id_assign'],
true);
//prevent adding empty group
if (empty($ticket->input['_groups_id_assign'])) {
unset($ticket->input['_groups_id_assign']);
}
break;
case 2:
// All groups
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
$ticket->input['_additional_groups_assigns']
= PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
$ticket->input['_users_id_assign'],
false);
//prevent adding empty group
if (empty($ticket->input['_additional_groups_assigns'])) {
unset($ticket->input['_additional_groups_assigns']);
}
break;

case 3:
$groups_id = PluginEscaladeUser::getUserDefaultGroup($item->fields['users_id']);
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
if (!$groups_id) {
wawax marked this conversation as resolved.
Show resolved Hide resolved
//prevent adding empty group
if (empty($ticket->input['_additional_groups_assigns'])) {
unset($ticket->input['_additional_groups_assigns']);
}
}
break;
}
}

Expand Down Expand Up @@ -534,16 +547,22 @@ static function item_add_user(Ticket_User $item, $type = CommonITILActor::ASSIGN
return true;
}

if ($_SESSION['plugins']['escalade']['config']['use_assign_user_group'] == 1) {
// First group
$groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->fields['entities_id'],
$item->fields['users_id'],
true);
} else {
// All groups
$groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->fields['entities_id'],
$item->fields['users_id'],
false);
switch ($_SESSION['plugins']['escalade']['config']['use_assign_user_group']) {
case 1:
// First group
$groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->fields['entities_id'],
$item->fields['users_id'],
true);
break;
case 2:
// All groups
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
$groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->fields['entities_id'],
$item->fields['users_id'],
false);
break;
case 3:
$groups_id = PluginEscaladeUser::getUserDefaultGroup($item->fields['users_id']);
break;
}

if (!empty($groups_id)) {
Expand Down
11 changes: 11 additions & 0 deletions inc/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ static function getTechnicianGroup($entity, $userid, $first = true) {
return self::getUserGroup($entity, $userid, '`is_assign`', $first);
}

static function getUserDefaultGroup($users_id) {
$groups_id = 0;

$user = new User();
$user->getFromDB($users_id);
if ($user->getField('groups_id')) {
$groups_id = $user->getField('groups_id');
}
return $groups_id;
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
}

function showForm($ID, array $options = []) {

$is_exist = $this->getFromDBByCrit(['users_id' => $ID]);
Expand Down