To filter selection queues (To field) per Customer in Agent Ticket Phone (New Phone Ticket)

Moderator: crythias

Post Reply
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

To filter selection queues (To field) per Customer in Agent Ticket Phone (New Phone Ticket)

Post by Giulio Soleni »

Hi,
I enabled Customer Group relation and now I would like to filter the queue selection list on "New Phone Ticket" also depending on the permissions of the selected customer and not only of the agent user to create a new ticket in a queue.

To this end I edited the definition of _GetTos subroutine in /opt/otrs/Kernel/Modules/AgentTicketPhone.pm with this lines:

Code: Select all

sub _GetTos {
    my ( $Self, %Param ) = @_;

    # get config object
    my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

    # check own selection
    my %NewTos;
    if ( $ConfigObject->Get('Ticket::Frontend::NewQueueOwnSelection') ) {
        %NewTos = %{ $ConfigObject->Get('Ticket::Frontend::NewQueueOwnSelection') };
    }
    else {

        # SelectionType Queue or SystemAddress?
        my %Tos;
        if ( $ConfigObject->Get('Ticket::Frontend::NewQueueSelectionType') eq 'Queue' ) {
            %Tos = $Kernel::OM->Get('Kernel::System::Ticket')->MoveList(
                %Param,
                Type    => 'create',
                Action  => $Self->{Action},
                QueueID => $Self->{QueueID},
                UserID  => $Self->{UserID},
            );
        }
        else {
            %Tos = $Kernel::OM->Get('Kernel::System::DB')->GetTableData(
                Table => 'system_address',
                What  => 'queue_id, id',
                Valid => 1,
                Clamp => 1,
            );
        }

        # get create permission queues
        my %UserGroups = $Kernel::OM->Get('Kernel::System::Group')->PermissionUserGet(
            UserID => $Self->{UserID},
            Type   => 'create',
        );

## FIRST EDIT BY ME... ADDED THE FOLLOWING 
        my $CustomerID = $Param{CustomerUserID};
        my %CustomerGroups = {};
        %CustomerGroups = $Kernel::OM->Get('Kernel::System::CustomerGroup')->GroupMemberList(
            UserID => $CustomerID,
            Type   => 'rw',
            Result => 'HASH',
        );
## ...TILL HERE

        # build selection string
        QUEUEID:
        for my $QueueID ( sort keys %Tos ) {
            my %QueueData = $Kernel::OM->Get('Kernel::System::Queue')->QueueGet( ID => $QueueID );

            # permission check, can we create new tickets in queue
            next QUEUEID if !$UserGroups{ $QueueData{GroupID} };
            
## ADDED THE FOLLOWING PERMISSION CHECK            
            next QUEUEID if !$CustomerGroups{ $QueueData{GroupID} };
## END OF EDITING BY ME

            my $String = $ConfigObject->Get('Ticket::Frontend::NewQueueSelectionString')
                || '<Realname> <<Email>> - Queue: <Queue>';
            $String =~ s/<Queue>/$QueueData{Name}/g;
            $String =~ s/<QueueComment>/$QueueData{Comment}/g;
            if ( $ConfigObject->Get('Ticket::Frontend::NewQueueSelectionType') ne 'Queue' )
            {
                my %SystemAddressData = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressGet(
                    ID => $Tos{$QueueID},
                );
                $String =~ s/<Realname>/$SystemAddressData{Realname}/g;
                $String =~ s/<Email>/$SystemAddressData{Name}/g;
            }
            $NewTos{$QueueID} = $String;
        }
    }

    # add empty selection
    $NewTos{''} = '-';
    return \%NewTos;
}
Now when I select some customers the result is as expected... however when I select some others (with different permissions) I have a weird behavior and the list of available queues remain stuck with a "Loading..." lable (like in the attached pic).
Immagine.png
would you be so kind to help me and provide me with any hint to understand what could be the issue?

Thank you
Giulio

EDIT: I could notice that it seems to work correctly for customer users defined in the internal OTRS database, while for customer users loaded from ActiveDirectory, the queue selection list results in that "Loading..." label
You do not have the required permissions to view the files attached to this post.
Last edited by Giulio Soleni on 14 Aug 2016, 09:58, edited 2 times in total.
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: To filter selection queues (To field) per Customer in Agent Ticket Phone (New Phone Ticket)

Post by Giulio Soleni »

From a further analysis I could see that the "Loading..." prompt for the "To queue" entry appears when I change the selection from a customer to another with different permissions (regardless it is a customer from internal db or from AD ... as I initially thought).
I guess that the queue list is not recalculated when a new customer is selected.

It would be a great help to me if someone could give me a hint on how to recalculate the queue list as soon as the selected customer is changed.

Thank you
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: To filter selection queues (To field) per Customer in Agent Ticket Phone (New Phone Ticket)

Post by Giulio Soleni »

I think I have come to a clue, even if I am still not able to fix the issue.
For some reason that I am not able to understand, after the selection of a first customer and the switch to another one, the list of available queues for the destination (To queue) shows only first level queues and not subqueues.
I noticed that after repeated attempts, because as soon as I added a line:

Code: Select all

$String =~ s/\:\:/--/g;
right before the line

Code: Select all

$NewTos{$QueueID} = $String;
within the sub _GetTos, the destination queues were indeed presentedcorrectly for all the customers selected, but in a "plain list" format ... that is without any sub-queue level:
Immagine.png
That's only a matter of data presentation ... because if for example I select "ACME--Support Y--Sub Support Y" the ticket is correctly created within the "ACME::Support Y::Sub Support Y" queue.

I am close to the solution ... but any help from you to understand why the presentation of the queues does not work as it should, would be really appreciated

Thank you,
Giulio
You do not have the required permissions to view the files attached to this post.
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.
Post Reply