Created
February 8, 2017 16:25
-
-
Save reneeb/6d99616c3d2cf47dc89a16704cf404f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<otrs_config version="1.0" init="Config"> | |
<ConfigItem Name="GenericInterface::Operation::Module###Ticket::TicketHistoryGet" Required="0" Valid="1"> | |
<Description Translatable="1">GenericInterface module registration for the operation layer.</Description> | |
<Group>GenericInterface</Group> | |
<SubGroup>GenericInterface::Operation::ModuleRegistration</SubGroup> | |
<Setting> | |
<Hash> | |
<Item Key="Name">TicketHistoryGet</Item> | |
<Item Key="Controller">Ticket</Item> | |
<Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item> | |
</Hash> | |
</Setting> | |
</ConfigItem> | |
</otrs_config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- | |
# Copyright (C) 2017 Perl-Services.de, http://perl-services.de | |
# -- | |
# This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
# the enclosed file COPYING for license information (AGPL). If you | |
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. | |
# -- | |
package Kernel::GenericInterface::Operation::Ticket::TicketHistoryGet; | |
use strict; | |
use warnings; | |
use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData); | |
use base qw( | |
Kernel::GenericInterface::Operation::Common | |
Kernel::GenericInterface::Operation::Ticket::Common | |
); | |
our $ObjectManagerDisabled = 1; | |
=head1 NAME | |
Kernel::GenericInterface::Operation::Ticket::TicketyHistorGet - GenericInterface Operation backend to get ticket history | |
=head1 SYNOPSIS | |
=head1 PUBLIC INTERFACE | |
=over 4 | |
=cut | |
=item new() | |
usually, you want to create an instance of this | |
by using Kernel::GenericInterface::Operation->new(); | |
=cut | |
sub new { | |
my ( $Type, %Param ) = @_; | |
my $Self = {}; | |
bless( $Self, $Type ); | |
# check needed objects | |
for my $Needed (qw(DebuggerObject WebserviceID)) { | |
if ( !$Param{$Needed} ) { | |
return { | |
Success => 0, | |
ErrorMessage => "Got no $Needed!", | |
}; | |
} | |
$Self->{$Needed} = $Param{$Needed}; | |
} | |
return $Self; | |
} | |
=item Run() | |
perform TicketGet Operation. This function is able to return | |
one or more ticket entries in one call. | |
my $Result = $OperationObject->Run( | |
Data => { | |
UserLogin => 'some agent login', # UserLogin or SessionID is required | |
SessionID => 123, | |
Password => 'some password', # if UserLogin is sent then Password is required | |
TicketID => '32,33', # required, could be coma separated IDs or an Array | |
}, | |
); | |
$Result = { | |
Success => 1, # 0 or 1 | |
ErrorMessage => '', # In case of an error | |
Data => { | |
TicketHistory => [ | |
{ | |
TicketID => 123, | |
History => [ | |
], | |
}, | |
], | |
}, | |
}; | |
=cut | |
sub Run { | |
my ( $Self, %Param ) = @_; | |
my $Result = $Self->Init( | |
WebserviceID => $Self->{WebserviceID}, | |
); | |
if ( !$Result->{Success} ) { | |
return $Self->ReturnError( | |
ErrorCode => 'Webservice.InvalidConfiguration', | |
ErrorMessage => $Result->{ErrorMessage}, | |
); | |
} | |
my ( $UserID, $UserType ) = $Self->Auth( | |
%Param, | |
); | |
return $Self->ReturnError( | |
ErrorCode => 'TicketGet.AuthFail', | |
ErrorMessage => "TicketGet: Authorization failing!", | |
) if !$UserID; | |
# check needed stuff | |
for my $Needed (qw(TicketID)) { | |
if ( !$Param{Data}->{$Needed} ) { | |
return $Self->ReturnError( | |
ErrorCode => 'TicketGet.MissingParameter', | |
ErrorMessage => "TicketGet: $Needed parameter is missing!", | |
); | |
} | |
} | |
my $ErrorMessage = ''; | |
# all needed variables | |
my @TicketIDs; | |
if ( IsStringWithData( $Param{Data}->{TicketID} ) ) { | |
@TicketIDs = split( /,/, $Param{Data}->{TicketID} ); | |
} | |
elsif ( IsArrayRefWithData( $Param{Data}->{TicketID} ) ) { | |
@TicketIDs = @{ $Param{Data}->{TicketID} }; | |
} | |
else { | |
return $Self->ReturnError( | |
ErrorCode => 'TicketGet.WrongStructure', | |
ErrorMessage => "TicketGet: Structure for TicketID is not correct!", | |
); | |
} | |
TICKET: | |
for my $TicketID (@TicketIDs) { | |
my $Access = $Self->CheckAccessPermissions( | |
TicketID => $TicketID, | |
UserID => $UserID, | |
UserType => $UserType, | |
); | |
next TICKET if $Access; | |
return $Self->ReturnError( | |
ErrorCode => 'TicketGet.AccessDenied', | |
ErrorMessage => 'TicketGet: User does not have access to the ticket!', | |
); | |
} | |
my $ReturnData = { | |
Success => 1, | |
}; | |
my @Histories; | |
# start ticket loop | |
TICKET: | |
for my $TicketID (@TicketIDs) { | |
# get ticket object | |
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket'); | |
my @Lines = $Self->HistoryGet( | |
TicketID => $TicketID, | |
UserID => $UserID, | |
); | |
push @Histories, { | |
TicketID => $TicketID, | |
History => \@Lines, | |
}; | |
} # finish ticket loop | |
if ( !scalar @Item ) { | |
$ErrorMessage = 'Could not get Ticket history data' | |
. ' in Kernel::GenericInterface::Operation::Ticket::TicketHistoryGet::Run()'; | |
return $Self->ReturnError( | |
ErrorCode => 'TicketGet.NotTicketData', | |
ErrorMessage => "TicketGet: $ErrorMessage", | |
); | |
} | |
# set ticket data into return structure | |
$ReturnData->{Data}->{TicketHistory} = \@Item; | |
# return result | |
return $ReturnData; | |
} | |
1; | |
=back | |
=head1 TERMS AND CONDITIONS | |
This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
the enclosed file COPYING for license information (AGPL). If you | |
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment