yllen / behaviors

This plugin allows you to add optional behaviors to GLPI.
GNU Affero General Public License v3.0
15 stars 16 forks source link

Does not add technician group when updating ticket #76

Open eramos13 opened 1 year ago

eramos13 commented 1 year ago

In the behavior settings in the update request section the option "Add technician group - First" is enabled, but if I update the technician it does not update the group. This happens both when creating the ticket from the portal, as well as when creating the ticket from the mail receiver. I have already tried solution #71.

To replicate the scenario, create a ticket via the mail receiver, then update the request to assign a technician, you will see that it does not add the technician group.

jcervantes-sipecom commented 1 year ago

Hi, same here, I'm facing the same issue, the groups from requester and technician haven´t been added.

Loiseau2nuit commented 1 year ago

+1 / no group added when choosing a requester or a technician

eramos13 commented 1 year ago

I corrected this problem with the following code in the ticket file /marketplace/behaviors/inc/ticket.class.php

// line 359
//Start code
if ($config->getField('use_requester_user_group') > 0 || isset($ticket->input['_actors'])) {
    if (isset($ticket->input['_actors'])) {
        $actors = $ticket->input['_actors'];
        // save sender if available
    }
    // add group
    if ($config->getField('use_requester_user_group') == 1) {
        // First group
        $grp = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], true);
        if ($grp > 0) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    } else {
        // All groups
        $grps = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], false);
        foreach ($grps as $grp) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    }
    $ticket->input['_actors'] = $actors;
}
//end code
Loiseau2nuit commented 1 year ago

Thanks for the fix Why not pushing it as a pull request ?

jcervantes-sipecom commented 1 year ago

I corrected this problem with the following code in the ticket file /marketplace/behaviors/inc/ticket.class.php

// line 359
//Start code
if ($config->getField('use_requester_user_group') > 0 || isset($ticket->input['_actors'])) {
    if (isset($ticket->input['_actors'])) {
        $actors = $ticket->input['_actors'];
        // save sender if available
    }
    // add group
    if ($config->getField('use_requester_user_group') == 1) {
        // First group
        $grp = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], true);
        if ($grp > 0) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    } else {
        // All groups
        $grps = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], false);
        foreach ($grps as $grp) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    }
    $ticket->input['_actors'] = $actors;
}
//end code

For me it didn't work, when selecting the technitian in "Assigned to" including after saving, the group wasn't add it.

eramos13 commented 1 year ago

I corrected this problem with the following code in the ticket file /marketplace/behaviors/inc/ticket.class.php

// line 359
//Start code
if ($config->getField('use_requester_user_group') > 0 || isset($ticket->input['_actors'])) {
    if (isset($ticket->input['_actors'])) {
        $actors = $ticket->input['_actors'];
        // save sender if available
    }
    // add group
    if ($config->getField('use_requester_user_group') == 1) {
        // First group
        $grp = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], true);
        if ($grp > 0) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    } else {
        // All groups
        $grps = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], false);
        foreach ($grps as $grp) {
            $actors['requester'][] = [
                'itemtype' => 'Group',
                'items_id' => $grp,
                'use_notification' => "1",
                'alternative_email' => ""
            ];
        }
    }
    $ticket->input['_actors'] = $actors;
}
//end code

For me it didn't work, when selecting the technitian in "Assigned to" including after saving, the group wasn't add it.

This solution is to add to the requester's group when the ticket is created using the mail receiver.

The update the technician group I have not checked where in the code to be able to test.

Loiseau2nuit commented 1 year ago

For me, it should be available on demand for each actor's field, requester being of course the most important one

nelsonyoneyama commented 1 year ago

From the line 639 of file inc/ticket.class.php, include this:

// Line 639
// Begin
        if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
                $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                        $grupos = [];
                        foreach ($assigners as $id => $assign) {
                                if ($assign['itemtype'] == 'User') {
                                        if ($config->getField('use_assign_user_group_update') == 1) {
                                                // First group
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                                $grupos = array_merge ($grupos, $grupo);
                                        } else {
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                                $grupos = array_merge ($grupos, $grupo);
                                        }
                                }
                        }
                        $ticket->input['_additional_groups_assigns'] = $grupos;
                }
      }
// End

please test in a homologation environment and let me know if there are any errors

Loiseau2nuit commented 1 year ago

From the line 639 of file inc/ticket.class.php, include this:

// Line 639
// Begin
        if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
                $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                        $grupos = [];
                        foreach ($assigners as $id => $assign) {
                                if ($assign['itemtype'] == 'User') {
                                        if ($config->getField('use_assign_user_group_update') == 1) {
                                                // First group
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                                $grupos = array_merge ($grupos, $grupo);
                                        } else {
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                                $grupos = array_merge ($grupos, $grupo);
                                        }
                                }
                        }
                        $ticket->input['_additional_groups_assigns'] = $grupos;
                }
      }
// End

please test in a homologation environment and let me know if there are any errors

Which version did you patch this on ? (we're using 10.0.9 btw ;-) )

nelsonyoneyama commented 1 year ago

From the line 639 of file inc/ticket.class.php, include this:

// Line 639
// Begin
        if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
                $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                        $grupos = [];
                        foreach ($assigners as $id => $assign) {
                                if ($assign['itemtype'] == 'User') {
                                        if ($config->getField('use_assign_user_group_update') == 1) {
                                                // First group
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                                $grupos = array_merge ($grupos, $grupo);
                                        } else {
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                                $grupos = array_merge ($grupos, $grupo);
                                        }
                                }
                        }
                        $ticket->input['_additional_groups_assigns'] = $grupos;
                }
      }
// End

please test in a homologation environment and let me know if there are any errors

Which version did you patch this on ? (we're using 10.0.9 btw ;-) )

Glpi 10.0.9 and Behaviors 2.7.2

eramos13 commented 1 year ago

From the line 639 of file inc/ticket.class.php, include this:

// Line 639
// Begin
        if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
                $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                        $grupos = [];
                        foreach ($assigners as $id => $assign) {
                                if ($assign['itemtype'] == 'User') {
                                        if ($config->getField('use_assign_user_group_update') == 1) {
                                                // First group
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                                $grupos = array_merge ($grupos, $grupo);
                                        } else {
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                                $grupos = array_merge ($grupos, $grupo);
                                        }
                                }
                        }
                        $ticket->input['_additional_groups_assigns'] = $grupos;
                }
      }
// End

please test in a homologation environment and let me know if there are any errors

I have made some adjustments to your code, so that it adds the first group or all depending on the configuration of the plugin.

//Start code
if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
            $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                    $grupos = [];
                    foreach ($assigners as $id => $assign) {
                        if ($assign['itemtype'] == 'User') {
                                if ($config->getField('use_assign_user_group_update') == 1) {
                                    // First group
                                    $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                    $grupos[] = $grupo;     
                                } else if ($config->getField('use_assign_user_group_update') == 2) {
                                    // All groups
                                    $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                    $grupos = array_merge ($grupos, $grupo);                                    
                                }
                        }
                    }
                    $ticket->input['_additional_groups_assigns'] = $grupos;
                }
}
//end code
jcervantes-sipecom commented 1 year ago

Hi @nelsonyoneyama @eramos13, is it not better to do a pull request?

Loiseau2nuit commented 1 year ago

Actually, after several tests, neither of those two codes work here ... :-(

eramos13 commented 1 year ago

Actually, after several tests, neither of those two codes work here ... :-(

Clear your glpi cache, because both codes I tested in my development environment, then to production and it works without problems.

nelsonyoneyama commented 1 year ago

Actually, after several tests, neither of those two codes work here ... :-(

Could you provide a more detailed explanation of the issue you're encountering along with the specific error message you're receiving?

nelsonyoneyama commented 1 year ago

From the line 639 of file inc/ticket.class.php, include this:

// Line 639
// Begin
        if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
                $assigners = $ticket->input['_actors']['assign'];
                if (count($assigners)) {
                        $grupos = [];
                        foreach ($assigners as $id => $assign) {
                                if ($assign['itemtype'] == 'User') {
                                        if ($config->getField('use_assign_user_group_update') == 1) {
                                                // First group
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                                $grupos = array_merge ($grupos, $grupo);
                                        } else {
                                                $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                                $grupos = array_merge ($grupos, $grupo);
                                        }
                                }
                        }
                        $ticket->input['_additional_groups_assigns'] = $grupos;
                }
      }
// End

please test in a homologation environment and let me know if there are any errors

I have made some adjustments to your code, so that it adds the first group or all depending on the configuration of the plugin.

//Start code
if ($config->getField('use_assign_user_group_update') && isset($ticket->input['_actors'])) {
          $assigners = $ticket->input['_actors']['assign'];
              if (count($assigners)) {
                  $grupos = [];
                  foreach ($assigners as $id => $assign) {
                      if ($assign['itemtype'] == 'User') {
                              if ($config->getField('use_assign_user_group_update') == 1) {
                                  // First group
                                  $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],true);
                                  $grupos[] = $grupo;     
                              } else if ($config->getField('use_assign_user_group_update') == 2) {
                                  // All groups
                                  $grupo = PluginBehaviorsUser::getTechnicianGroup($ticket->fields['entities_id'],$assign['items_id'],false);
                                  $grupos = array_merge ($grupos, $grupo);                                    
                              }
                      }
                  }
                  $ticket->input['_additional_groups_assigns'] = $grupos;
              }
}
//end code

If you include this same code within the static function "beforeAdd," approximately around line 432, the code will assign the technician's groups during ticket creation.

Loiseau2nuit commented 1 year ago

Actually, after several tests, neither of those two codes work here ... :-(

Could you provide a more detailed explanation of the issue you're encountering along with the specific error message you're receiving?

I'm not ghaving any error message up front. It simply doesn't add any group.

I have to dig deeper in logs. I'll let you know if I find something

nelsonyoneyama commented 1 year ago

Actually, after several tests, neither of those two codes work here ... :-(

Could you provide a more detailed explanation of the issue you're encountering along with the specific error message you're receiving?

I'm not ghaving any error message up front. It simply doesn't add any group.

I have to dig deeper in logs. I'll let you know if I find something

Do you use any other plugin in your GLPI? Can you send me your ticket.class.php file to have a look?