You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2019-01-18 15:16:25

Daviid
Member
Registered: 2018-12-20
Posts: 12

Behaviors Mandatory Requester

I've set the requester as mandatory when opening a ticket.
But if I don't set one the ticket is still created.

POST variables

-----------------------------146043902153
Content-Disposition: form-data; name="_users_id_requester"

0
-----------------------------146043902153
Content-Disposition: form-data; name="_users_id_requester_notif[use_notification][]"

1
-----------------------------146043902153
Content-Disposition: form-data; name="_users_id_requester_notif[alternative_email][]"


-----------------------------146043902153
Content-Disposition: form-data; name="entities_id"

0

Adding this to the code to test the conditionals:

$debugText = "";
 if ($config->getField('is_requester_mandatory')) {
    $debugText .= "\n Requester is mandatory";
 } else {
    $debugText .= "\n Requester is not mandatory";
 }

 if (is_array($ticket->input['_users_id_requester'])) {
    $debugText .= "\n _users_id_requester is array";
    if (empty($ticket->input['_users_id_requester'])) {
        $debugText .= "\n _users_id_requester is empty";
    } else {
        $debugText .= "\n _users_id_requester is not empty";
    }
 } else {
    $debugText .= "\n _users_id_requester is not array";
    $debugText .= "\n _users_id_requester value = ".$ticket->input['_users_id_requester'];
 }

 if (isset($ticket->input['_users_id_requester_notif']['alternative_email']) {
    $debugText .= "\n input['_users_id_requester_notif']['alternative_email'] is set";
 } else {
    $debugText .= "\n input['_users_id_requester_notif']['alternative_email'] is not set";
 }


 if (empty($ticket->input['_users_id_requester_notif']['alternative_email'])) {
    $debugText .= "\n input['_users_id_requester_notif']['alternative_email'] is empty";
 } else {
    $debugText .= "\n input['_users_id_requester_notif']['alternative_email'] is not empty";
    $debugText .= "\n input['_users_id_requester_notif']['alternative_email'] value = ".$ticket->input['_users_id_requester_notif']['alternative_email'];
 }
file_put_contents("/tmp/debug.txt",$debugText);

I get this:

Requester is mandatory
_users_id_requester is not array
_users_id_requester value = 0
input['_users_id_requester_notif']['alternative_email'] is set
input['_users_id_requester_notif']['alternative_email'] is not empty
input['_users_id_requester_notif']['alternative_email'] value = Array

The snippet in question:

if (!isset($ticket->input['_auto_import'])
          && isset($_SESSION['glpiactiveprofile']['interface'])
          && ($_SESSION['glpiactiveprofile']['interface'] == 'central')) {

         if ($config->getField('is_requester_mandatory')
             && ((is_array($ticket->input['_users_id_requester'])
                  && empty($ticket->input['_users_id_requester']))
                 || (!is_array($ticket->input['_users_id_requester'])
                     && !$ticket->input['_users_id_requester']))
             && (!isset($ticket->input['_users_id_requester_notif']['alternative_email'])
                 || empty($ticket->input['_users_id_requester_notif']['alternative_email']))) {
            Session::addMessageAfterRedirect(__('Requester is mandatory', 'behaviors'), true, ERROR);
            $ticket->input = [];
            return true;

         }
      }

Edit:
Meanwhile I'll comment out the

&& (!isset($ticket->input['_users_id_requester_notif']['alternative_email'])
                 || empty($ticket->input['_users_id_requester_notif']['alternative_email']))

bit.
I assume this is for when the requester has no user in GLPI so you can input the email?

Last edited by Daviid (2019-01-18 15:25:28)

Offline

#2 2019-01-21 17:02:48

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 14,575

Re: Behaviors Mandatory Requester

This part is a correction of a bug. Look at  https://forge.glpi-project.org/issues/3281


CentOS 6.5 - CentOS 7
PHP 5.6 - PHP 7 - MySQL 5.6  + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#3 2019-01-22 09:27:48

Daviid
Member
Registered: 2018-12-20
Posts: 12

Re: Behaviors Mandatory Requester

yllen wrote:

This part is a correction of a bug. Look at  https://forge.glpi-project.org/issues/3281

But I tried creating a ticket with no requester user and I didn't touch the email input.
And the ticket was created with no requester email and no requester user.

Here's what the print_r on alternative email returns.

Requester is mandatory
_users_id_requester is not array
_users_id_requester value = 0
input['_users_id_requester_notif']['alternative_email'] is set
input['_users_id_requester_notif']['alternative_email'] is not empty
input['_users_id_requester_notif']['alternative_email'] value = Array
print_r(input['_users_id_requester_notif']['alternative_email'])  = 1

Edit: I understand that this should error because no user or email has been provided.
AJNE7hq.png

Edit 2:I also tried "Email followup No"

Last edited by Daviid (2019-01-22 09:32:51)

Offline

Board footer

Powered by FluxBB