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

Conversation

wawax
Copy link

@wawax wawax commented Aug 9, 2022

This PR add the support for taking user's default group when assigning a ticket to a user

inc/ticket.class.php Outdated Show resolved Hide resolved
inc/ticket.class.php Outdated Show resolved Hide resolved
inc/ticket.class.php Show resolved Hide resolved
inc/user.class.php Outdated Show resolved Hide resolved
inc/ticket.class.php Outdated Show resolved Hide resolved
Co-authored-by: Cédric Anne <[email protected]>
Copy link
Contributor

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK for me, on the technical point of view.

@stonebuzz Can you do a manual functionnal test and validate this PR ?

@stonebuzz
Copy link
Contributor

Hi @wawax =)

It does not seem to work when creating a ticket (GLPI 10)

  1. Need to check if $ticket->input['_groups_id_assign'] is empty because from GLPI 10 the key exists but is empty if there is no assign group
  2. Need to use reset($ticket->input['_users_id_assign']) to get first user requester
    The input array now has this format :
      [_users_id_requester] => Array
          (
              [_actors_2] => 2
          )
  1. Put groups_id into new array ['_actors_'.$groups_id => $groups_id] into $ticket->input['_groups_id_assign']

Here is a patch if you want to test

diff --git a/inc/ticket.class.php b/inc/ticket.class.php
index 8a5e8cc..ed880ca 100644
--- a/inc/ticket.class.php
+++ b/inc/ticket.class.php
@@ -368,45 +368,34 @@ class PluginEscaladeTicket {
       }
       
       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)) {
+         && $ticket->input['_users_id_assign'] > 0
+         && (!isset($ticket->input['_groups_id_assign'])
+         || $ticket->input['_groups_id_assign'] <= 0
+         || empty($ticket->input['_groups_id_assign']))) {
+
+         $groups_id = 0;
          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']);
-               }
+               $groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
+                  reset($ticket->input['_users_id_assign']), true);
                break;
             case 2:
                // Last 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']);
-               }
+               $groups_id = PluginEscaladeUser::getTechnicianGroup($ticket->input['entities_id'],
+               reset($ticket->input['_users_id_assign']),false);
                break;
-            
+
             case 3:
                //User's default group
-               $ticket->input['_additional_groups_assigns'] 
-                  = PluginEscaladeUser::getUserDefaultGroup($item->fields['users_id']);
-               if (empty($ticket->input['_additional_groups_assigns'])) {
-                  //prevent adding empty group
-                  if (empty($ticket->input['_additional_groups_assigns'])) {
-                     unset($ticket->input['_additional_groups_assigns']);
-                  }
-               }
+               $groups_id = PluginEscaladeUser::getUserDefaultGroup(reset($ticket->input['_users_id_assign']));
                break;
          }
+
+      //prevent adding empty group
+      if (!empty($groups_id)) {
+         $ticket->input['_groups_id_assign'] = ['_actors_'.$groups_id => $groups_id];
+      }
       }
 
       return true;

Best regards

Copy link
Contributor

@stonebuzz stonebuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment

@cedric-anne cedric-anne self-requested a review September 14, 2022 11:18
@cedric-anne cedric-anne marked this pull request as draft November 9, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants