Closed terdinatore closed 1 year ago
Hi @terdinatore,
thanks for using the plugin and your feedback.
I am currently not using it actively and therefore I am a bit out of the code. However as far as I remember setting 'on_behalf_of' with the $user_id
of the Zammad client made it possible to create the ticket as the client instead of the user that has API access. This is described e.g. here: https://github.com/zammad/zammad/issues/1805
However it would be interesting if this works without the workaround now. Can you please try to remove the whole block:
// Set on behalf
$customer = new ZammadWp\Zammad([
'on_behalf_user' => $user_id
]);
And to change this line into:
$ticket = $zammad->ticket()->createTicket($ticket);
Please report back if the tickets still get created correctly and that they are created by the correct user in Zammad.
Thank you, your answer was quite insightful. It helped me to rule out a configuration error in my side, I have the needed admin.user
permission set correctly.
There seems to be something wrong with Zammad itself. I will open an issue there when I get to it.
I have changed the code as you suggested and it seems to not change the behaviour compared to my fix.
As zammad#1805 suggests, the user creating the ticket in the activity stream is not the user the ticket will be opened for, now. But then again in the ticket itself the user is correct, which is different compared to the issue and actually the expected behaviour.
If I may suggest, one could adjust the options this way:
ZAMMAD_CREATE_TICKET_ON_BEHALF_OF_CREATOR
(Default: True) / Reflects current behaviour. If false use $zammad to create ticket instead of $customerZAMMAD_CREATE_TICKET_ALWAYS_ON_BEHALF_OF_USER_ID
To set a specific user id to create tickets. Overules the upper optionThank you and have nice day
Glad to hear this is fixed for you and thanks for the good suggestions. I will take them into cosideration as soon as I get back to the code. Leaving this open for reference until this is done.
Kind regards
@terdinatore I am closing this for now without any changes on the codebase. It is a while ago and so far none else has had that issue. Please feel free to reopen if neccessary.
Thanks and kind regards,
Philipp
Mid December I updated to the newest Zammad version 5.0 (Docker Compose) and today I noticed that the plugin stopped working. After some research in the logs I was able to see that for some reason ticket creation requests are rejected with
422: Unprocessable Entity
along with"error": Invalid value '7' for field 'group_id' !
It seems that the issue wasn't the API that changed, but the permissions that get selected when the
X-On-Behalf-Of
header is set. See Picture. Without the option tickets can be created just fine.To fix the issue I removed line 189 below. Behavior is not changed by this since
[customer_id]
is still sent in the createTicket requesthttps://github.com/ouun/zammad-wp/blob/394f90d71b2c62d164f5c4edbb033429e1527859/includes/functions/hf-plugin-integration.php#L189
It could be that this is some special case that appears only because of the way permissions are set on my instance. But let me know what you think of this, like if that line of code was needed or not.
I can do further research if wanted.