init III
This commit is contained in:
482
Perl OTRS/Kernel/System/LinkObject/Appointment.pm
Normal file
482
Perl OTRS/Kernel/System/LinkObject/Appointment.pm
Normal file
@@ -0,0 +1,482 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::Appointment;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::LinkObject',
|
||||
'Kernel::System::Calendar',
|
||||
'Kernel::System::Calendar::Appointment',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::Appointment
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Appointment backend for the appointment link object.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $LinkObjectAppointmentObject = $Kernel::OM->Get('Kernel::System::LinkObject::Appointment');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
fill up the link list with data
|
||||
|
||||
$Success = $LinkObject->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
IgnoreLinkedTicketStateTypes => 0|1, # (optional) default 0
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Self->{LogObject}->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $AppointmentObject = $Kernel::OM->Get('Kernel::System::Calendar::Appointment');
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Self->{LogObject}->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
APPOINTMENT:
|
||||
for my $AppointmentID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get appointment data
|
||||
my %Appointment = $AppointmentObject->AppointmentGet(
|
||||
AppointmentID => $AppointmentID,
|
||||
);
|
||||
|
||||
# remove id from hash if no service data was found
|
||||
if ( !%Appointment ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$AppointmentID};
|
||||
next APPOINTMENT;
|
||||
}
|
||||
|
||||
# add appointment data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$AppointmentID} = \%Appointment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'Appointment',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# TODO: Permission handling
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
return a hash of object descriptions
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => 123,
|
||||
Long => "The Appointment Title",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
Mode => 'Temporary', # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'Appointment',
|
||||
Long => 'Appointment',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get ticket
|
||||
my %Appointment = $Kernel::OM->Get('Kernel::System::Calendar::Appointment')->AppointmentGet(
|
||||
AppointmentID => $Param{Key},
|
||||
);
|
||||
|
||||
return if !%Appointment;
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $Appointment{AppointmentID},
|
||||
Long => $Appointment{Title},
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
Return a hash list of the search results.
|
||||
|
||||
Returns:
|
||||
|
||||
$SearchList = {
|
||||
NOTLINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
$SearchList = $LinkObject->ObjectSearch(
|
||||
SubObject => 'Bla', # (optional)
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# get needed objects
|
||||
my $CalendarObject = $Kernel::OM->Get('Kernel::System::Calendar');
|
||||
my $AppointmentObject = $Kernel::OM->Get('Kernel::System::Calendar::Appointment');
|
||||
|
||||
my %Search;
|
||||
my @CalendarIDs;
|
||||
my @Appointments;
|
||||
|
||||
# Search by appointment title and description, if supplied. The conversion of parameter names is
|
||||
# necessary, since link object search parameters should have unique names.
|
||||
if ( $Param{SearchParams}->{AppointmentTitle} ) {
|
||||
$Search{Title} = $Param{SearchParams}->{AppointmentTitle};
|
||||
}
|
||||
if ( $Param{SearchParams}->{AppointmentDescription} ) {
|
||||
$Search{Description} = $Param{SearchParams}->{AppointmentDescription};
|
||||
}
|
||||
|
||||
# Search by specific calendar IDs.
|
||||
if (
|
||||
$Param{SearchParams}->{AppointmentCalendarID}
|
||||
&& IsArrayRefWithData( $Param{SearchParams}->{AppointmentCalendarID} )
|
||||
)
|
||||
{
|
||||
@CalendarIDs = @{ $Param{SearchParams}->{AppointmentCalendarID} };
|
||||
}
|
||||
|
||||
# Search in all available calendars for the user.
|
||||
else {
|
||||
my @CalendarList = $CalendarObject->CalendarList(
|
||||
UserID => $Param{UserID},
|
||||
Permission => 'rw',
|
||||
ValidID => 1,
|
||||
);
|
||||
|
||||
@CalendarIDs = map { $_->{CalendarID} } @CalendarList;
|
||||
}
|
||||
|
||||
for my $CalendarID (@CalendarIDs) {
|
||||
my @CalendarAppointments = $AppointmentObject->AppointmentList(
|
||||
%Search,
|
||||
CalendarID => $CalendarID,
|
||||
Result => 'HASH',
|
||||
);
|
||||
push @Appointments, @CalendarAppointments;
|
||||
}
|
||||
|
||||
# add appointment data
|
||||
my %SearchList;
|
||||
for my $Appointment (@Appointments) {
|
||||
$SearchList{NOTLINKED}->{Source}->{ $Appointment->{AppointmentID} } = $Appointment;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'Appointment',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'Appointment',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'Appointment',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'Appointment',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
link delete pre event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'Appointment',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'Appointment',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
link delete post event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'Appointment',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'Appointment',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
521
Perl OTRS/Kernel/System/LinkObject/FAQ.pm
Normal file
521
Perl OTRS/Kernel/System/LinkObject/FAQ.pm
Normal file
@@ -0,0 +1,521 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::FAQ;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::FAQ',
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
use Kernel::System::VariableCheck qw(IsArrayRefWithData);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::FAQ
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
FAQ backend for the link object.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $FAQObjectBackend = $Kernel::OM->Get('Kernel::System::LinkObject::FAQ');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
fill up the link list with data
|
||||
|
||||
$Success = $LinkObject->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
ITEMID:
|
||||
for my $ItemID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
my %FAQData = $FAQObject->FAQGet(
|
||||
ItemID => $ItemID,
|
||||
ItemFields => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove id from hash if no FAQ data was found
|
||||
if ( !%FAQData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$ItemID};
|
||||
next ITEMID;
|
||||
}
|
||||
|
||||
# add FAQ data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$ItemID} = \%FAQData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'FAQ',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check module registry of AgentFAQZoom
|
||||
my $ModuleReg = $Kernel::OM->Get('Kernel::Config')->Get('Frontend::Module')->{AgentFAQZoom};
|
||||
|
||||
# do not grant access if frontend module is not registered
|
||||
return if !$ModuleReg;
|
||||
|
||||
# grant access if module permission has no Group or GroupRo defined
|
||||
if ( !IsArrayRefWithData( $ModuleReg->{GroupRo} ) && !IsArrayRefWithData( $ModuleReg->{Group} ) ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
|
||||
|
||||
PERMISSION:
|
||||
for my $Permission (qw(GroupRo Group)) {
|
||||
|
||||
next PERMISSION if !$ModuleReg->{$Permission};
|
||||
next PERMISSION if ref $ModuleReg->{$Permission} ne 'ARRAY';
|
||||
|
||||
for my $Group ( @{ $ModuleReg->{$Permission} } ) {
|
||||
|
||||
# get the group id
|
||||
my $GroupID = $GroupObject->GroupLookup( Group => $Group );
|
||||
|
||||
my $Type;
|
||||
if ( $Permission eq 'GroupRo' ) {
|
||||
$Type = 'ro';
|
||||
}
|
||||
elsif ( $Permission eq 'Group' ) {
|
||||
$Type = 'rw';
|
||||
}
|
||||
|
||||
# get user groups, where the user has the appropriate privilege
|
||||
my %Groups = $GroupObject->GroupMemberList(
|
||||
UserID => $Param{UserID},
|
||||
Type => $Type,
|
||||
Result => 'HASH',
|
||||
);
|
||||
|
||||
# grant access if agent is a member in the group
|
||||
return 1 if $Groups{$GroupID};
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
return a hash of object descriptions
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => "FAQ# 1234",
|
||||
Long => "FAQ# 1234: FAQTitle",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'FAQ',
|
||||
Long => 'FAQ',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
my %FAQ = $Kernel::OM->Get('Kernel::System::FAQ')->FAQGet(
|
||||
ItemID => $Param{Key},
|
||||
ItemFields => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return if !%FAQ;
|
||||
|
||||
# define description text
|
||||
my $FAQHook = $Kernel::OM->Get('Kernel::Config')->Get('FAQ::FAQHook');
|
||||
my $DescriptionText = "$FAQHook $FAQ{Number}";
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $DescriptionText,
|
||||
Long => "$DescriptionText: $FAQ{Title}",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
return a hash list of the search results
|
||||
|
||||
Return
|
||||
$SearchList = {
|
||||
NOT-LINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
$SearchList = $LinkObjectBackend->ObjectSearch(
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# add wild-cards
|
||||
my %Search;
|
||||
if ( $Param{SearchParams}->{Title} ) {
|
||||
$Search{Title} = '*' . $Param{SearchParams}->{Title} . '*';
|
||||
}
|
||||
if ( $Param{SearchParams}->{Number} ) {
|
||||
$Search{Number} = '*' . $Param{SearchParams}->{Number} . '*';
|
||||
}
|
||||
if ( $Param{SearchParams}->{What} ) {
|
||||
$Search{What} = '*' . $Param{SearchParams}->{What} . '*';
|
||||
}
|
||||
|
||||
my $FAQObject = $Kernel::OM->Get('Kernel::System::FAQ');
|
||||
|
||||
# search the FAQs
|
||||
my @ItemIDs = $FAQObject->FAQSearch(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
Order => 'Created',
|
||||
Sort => 'down',
|
||||
Limit => 50,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
ITEMID:
|
||||
for my $ItemID (@ItemIDs) {
|
||||
|
||||
my %FAQData = $FAQObject->FAQGet(
|
||||
ItemID => $ItemID,
|
||||
ItemFields => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next ITEMID if !%FAQData;
|
||||
|
||||
# add FAQ data
|
||||
$SearchList{NOTLINKED}->{Source}->{$ItemID} = \%FAQData;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'FAQ',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'FAQ',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'FAQ',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'FAQ',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
link delete pre event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'FAQ',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'FAQ',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
link delete post event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'FAQ',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'FAQ',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
515
Perl OTRS/Kernel/System/LinkObject/ITSMChange.pm
Normal file
515
Perl OTRS/Kernel/System/LinkObject/ITSMChange.pm
Normal file
@@ -0,0 +1,515 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::ITSMChange;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::ITSMChange',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::ITSMChange - LinkObject backend for ITSMChange
|
||||
|
||||
=cut
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object.
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $LinkObjectITSMChangeObject = $Kernel::OM->Get('Kernel::System::LinkObject::ITSMChange');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
Fill up the link list with data
|
||||
|
||||
$Success = $LinkObjectBackend->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
CHANGEID:
|
||||
for my $ChangeID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get change data
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove id from hash if ChangeGet() returns no results
|
||||
if ( !$ChangeData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$ChangeID};
|
||||
next CHANGEID;
|
||||
}
|
||||
|
||||
# add change data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$ChangeID} = $ChangeData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
Checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'ITSMChange',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get config of change zoom frontend module
|
||||
$Self->{Config} = $Kernel::OM->Get('Kernel::Config')->Get('ITSMChange::Frontend::AgentITSMChangeZoom');
|
||||
|
||||
# check permissions
|
||||
my $Access = $Kernel::OM->Get('Kernel::System::ITSMChange')->Permission(
|
||||
Type => $Self->{Config}->{Permission},
|
||||
ChangeID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return $Access;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
Return a hash of object descriptions.
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => "Change# 2009102110001674",
|
||||
Long => "Change# 2009102110001674: The Change Title",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'Change',
|
||||
Long => 'Change',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get change data
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return if !$ChangeData;
|
||||
return if !%{$ChangeData};
|
||||
|
||||
# define description text
|
||||
my $ChangeHook = $Kernel::OM->Get('Kernel::Config')->Get('ITSMChange::Hook');
|
||||
my $DescriptionText = "$ChangeHook $ChangeData->{ChangeNumber}";
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $DescriptionText,
|
||||
Long => "$DescriptionText: $ChangeData->{ChangeTitle}",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
Return a hash list of the search results.
|
||||
|
||||
$SearchList = $LinkObjectBackend->ObjectSearch(
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
$SearchList = {
|
||||
NOTLINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# add wildcards
|
||||
my %Search;
|
||||
for my $Element (qw(ChangeNumber ChangeTitle WorkOrderTitle)) {
|
||||
if ( $Param{SearchParams}->{$Element} ) {
|
||||
$Search{$Element} = '*' . $Param{SearchParams}->{$Element} . '*';
|
||||
}
|
||||
}
|
||||
|
||||
# search the changes
|
||||
# no need to use OrderBy here, because it is sorted in TableCreateComplex and TableCreateSimple
|
||||
my $ChangeIDsRef = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeSearch(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
UsingWildcards => 1,
|
||||
MirrorDB => 1,
|
||||
|
||||
# TODO:
|
||||
# use sysconfig option for 'limit' instead, decide wheater this option would be only
|
||||
# valid for linking changes, or just use a global setting for all linking stuff
|
||||
Limit => 200,
|
||||
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
CHANGEID:
|
||||
for my $ChangeID ( @{$ChangeIDsRef} ) {
|
||||
|
||||
# get change data
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $ChangeID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next ChangeID if !$ChangeData;
|
||||
|
||||
# add change data
|
||||
$SearchList{NOTLINKED}->{Source}->{$ChangeID} = $ChangeData;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
Link add pre event module.
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMChange',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMChange',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
Link add pre event module.
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMChange',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMChange',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# trigger ChangeLinkAddPost-Event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMChange')->EventHandler(
|
||||
Event => 'ChangeLinkAddPost',
|
||||
Data => {
|
||||
ChangeID => $Param{Key},
|
||||
Object => $Object, # the other object of the link
|
||||
ID => $ID, # id of the other object
|
||||
Type => $Param{Type}, # the link type
|
||||
%Param,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
Link delete pre event module.
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMChange',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMChange',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
Link delete post event module.
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMChange',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMChange',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# trigger ChangeLinkDeletePost-Event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMChange')->EventHandler(
|
||||
Event => 'ChangeLinkDeletePost',
|
||||
Data => {
|
||||
ChangeID => $Param{Key},
|
||||
Object => $Object, # the other object of the link
|
||||
ID => $ID, # id of the other object
|
||||
Type => $Param{Type}, # the link type
|
||||
%Param,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
544
Perl OTRS/Kernel/System/LinkObject/ITSMConfigItem.pm
Normal file
544
Perl OTRS/Kernel/System/LinkObject/ITSMConfigItem.pm
Normal file
@@ -0,0 +1,544 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::ITSMConfigItem;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::GeneralCatalog',
|
||||
'Kernel::System::ITSMConfigItem',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::ITSMConfigItem - LinkObject module for ITSMConfigItem
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $LinkObjectITSMConfigItemObject = $Kernel::OM->Get('Kernel::System::LinkObject::ITSMConfigItem');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
fill up the link list with data
|
||||
|
||||
$Success = $LinkObjectBackend->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get last version data
|
||||
my $VersionData = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionGet(
|
||||
ConfigItemID => $ConfigItemID,
|
||||
XMLDataGet => 0,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove id from hash if config item can not get
|
||||
if ( !$VersionData || ref $VersionData ne 'HASH' || !%{$VersionData} ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$ConfigItemID};
|
||||
next CONFIGITEMID;
|
||||
}
|
||||
|
||||
# add version data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$ConfigItemID} = $VersionData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'ITSMConfigItem',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get config of configitem zoom frontend module
|
||||
$Self->{Config} = $Kernel::OM->Get('Kernel::Config')->Get('ITSMConfigItem::Frontend::AgentITSMConfigItemZoom');
|
||||
|
||||
# check for access rights
|
||||
my $Access = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->Permission(
|
||||
Scope => 'Item',
|
||||
ItemID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
Type => $Self->{Config}->{Permission},
|
||||
);
|
||||
|
||||
return $Access;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
return a hash of object descriptions
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => "ConfigItem# 1234455",
|
||||
Long => "ConfigItem# 1234455: The Config Item Title",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'ConfigItem',
|
||||
Long => 'ConfigItem',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get last version data
|
||||
my $VersionData = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionGet(
|
||||
ConfigItemID => $Param{Key},
|
||||
XMLDataGet => 0,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return if !$VersionData;
|
||||
return if ref $VersionData ne 'HASH';
|
||||
return if !%{$VersionData};
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => "ConfigItem# $VersionData->{Number}",
|
||||
Long => "ConfigItem# $VersionData->{Number}: $VersionData->{Name}",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
return a hash list of the search results
|
||||
|
||||
Return
|
||||
$SearchList = {
|
||||
C<NOTLINKED> => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
$SearchList = $LinkObjectBackend->ObjectSearch(
|
||||
SubObject => '25', # (optional)
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# set focus
|
||||
my %Search;
|
||||
for my $Element (qw(Number Name)) {
|
||||
if ( $Param{SearchParams}->{$Element} ) {
|
||||
$Search{$Element} = '*' . $Param{SearchParams}->{$Element} . '*';
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$Param{SubObject} ) {
|
||||
|
||||
# get the config with the default subobjects
|
||||
my $DefaultSubobject = $Kernel::OM->Get('Kernel::Config')->Get('LinkObject::DefaultSubObject') || {};
|
||||
|
||||
# extract default class name
|
||||
my $DefaultClass = $DefaultSubobject->{ITSMConfigItem} || '';
|
||||
|
||||
# get class list
|
||||
my $ClassList = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemList(
|
||||
Class => 'ITSM::ConfigItem::Class',
|
||||
);
|
||||
|
||||
return if !$ClassList;
|
||||
return if ref $ClassList ne 'HASH';
|
||||
|
||||
# lookup the class id
|
||||
my %ClassListReverse = reverse %{$ClassList};
|
||||
$Param{SubObject} = $ClassListReverse{$DefaultClass} || '';
|
||||
}
|
||||
|
||||
return if !$Param{SubObject};
|
||||
|
||||
# search the config items
|
||||
my $ConfigItemIDs = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemSearchExtended(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
ClassIDs => [ $Param{SubObject} ],
|
||||
PreviousVersionSearch => 0,
|
||||
UsingWildcards => 1,
|
||||
OrderBy => ['Number'],
|
||||
OrderByDirection => ['Up'],
|
||||
Limit => 50,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
CONFIGITEMID:
|
||||
for my $ConfigItemID ( @{$ConfigItemIDs} ) {
|
||||
|
||||
# get last version data
|
||||
my $VersionData = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->VersionGet(
|
||||
ConfigItemID => $ConfigItemID,
|
||||
XMLDataGet => 0,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next CONFIGITEMID if !$VersionData;
|
||||
next CONFIGITEMID if ref $VersionData ne 'HASH';
|
||||
next CONFIGITEMID if !%{$VersionData};
|
||||
|
||||
# add version data
|
||||
$SearchList{NOTLINKED}->{Source}->{$ConfigItemID} = $VersionData;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMConfigItem',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMConfigItem',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMConfigItem',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMConfigItem',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# recalculate the current incident state of this CI
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->CurInciStateRecalc(
|
||||
ConfigItemID => $Param{Key},
|
||||
);
|
||||
|
||||
# trigger LinkAdd event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->EventHandler(
|
||||
Event => 'LinkAdd',
|
||||
Data => {
|
||||
ConfigItemID => $Param{Key},
|
||||
Comment => $ID . '%%' . $Object,
|
||||
Type => $Param{Type},
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
link delete pre event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMConfigItem',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMConfigItem',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
link delete post event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMConfigItem',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMConfigItem',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# recalculate the current incident state of this CI
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->CurInciStateRecalc(
|
||||
ConfigItemID => $Param{Key},
|
||||
);
|
||||
|
||||
# trigger LinkDelete event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMConfigItem')->EventHandler(
|
||||
Event => 'LinkDelete',
|
||||
Data => {
|
||||
ConfigItemID => $Param{Key},
|
||||
Comment => $ID . '%%' . $Object,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
557
Perl OTRS/Kernel/System/LinkObject/ITSMWorkOrder.pm
Normal file
557
Perl OTRS/Kernel/System/LinkObject/ITSMWorkOrder.pm
Normal file
@@ -0,0 +1,557 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::ITSMWorkOrder;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::ITSMChange',
|
||||
'Kernel::System::ITSMChange::ITSMWorkOrder',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::ITSMWorkOrder - LinkObject ITSMWorkOrder module
|
||||
|
||||
=cut
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object.
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $LinkObjectITSMWorkOrderObject = $Kernel::OM->Get('Kernel::System::LinkObject::ITSMWorkOrder');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
Fill up the link list with data.
|
||||
|
||||
$Success = $LinkObjectBackend->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrderData = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove id from hash if WorkOrderGet() returns no results
|
||||
if ( !$WorkOrderData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$WorkOrderID};
|
||||
next WORKORDERID;
|
||||
}
|
||||
|
||||
# get change data for this workorder
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $WorkOrderData->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove workorder id from hash if change for this workorder returns no results
|
||||
if ( !$ChangeData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$WorkOrderID};
|
||||
next WORKORDERID;
|
||||
}
|
||||
|
||||
# add the change data to workorder data
|
||||
my %Data = (
|
||||
%{$WorkOrderData},
|
||||
ChangeData => $ChangeData,
|
||||
);
|
||||
|
||||
# add workorder data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$WorkOrderID} = \%Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
Checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'ITSMWorkOrder',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# get config of workorder zoom frontend module
|
||||
$Self->{Config} = $Kernel::OM->Get('Kernel::Config')->Get('ITSMWorkOrder::Frontend::AgentITSMWorkOrderZoom');
|
||||
|
||||
# check permissions
|
||||
my $Access = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->Permission(
|
||||
Type => $Self->{Config}->{Permission},
|
||||
WorkOrderID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return $Access;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
Return a hash of object descriptions.
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
%Description = (
|
||||
Normal => "Workorder# 2009102110001674-1",
|
||||
Long => "Workorder# 2009102110001674-1: The Workorder Title",
|
||||
);
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'Workorder',
|
||||
Long => 'Workorder',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrderData = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return if !$WorkOrderData;
|
||||
return if !%{$WorkOrderData};
|
||||
|
||||
# get change data for this workorder
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $WorkOrderData->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return if !$ChangeData;
|
||||
return if !%{$ChangeData};
|
||||
|
||||
# define description text
|
||||
my $WorkOrderHook = $Kernel::OM->Get('Kernel::Config')->Get('ITSMWorkOrder::Hook');
|
||||
my $DescriptionText = "$WorkOrderHook $ChangeData->{ChangeNumber}-$WorkOrderData->{WorkOrderNumber}";
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $DescriptionText,
|
||||
Long => "$DescriptionText: $WorkOrderData->{WorkOrderTitle}",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
Return a hash list of the search results.
|
||||
|
||||
$SearchList = $LinkObjectBackend->ObjectSearch(
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
$SearchList = {
|
||||
NOTLINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# add wildcards
|
||||
my %Search;
|
||||
for my $Element (qw(ChangeNumber ChangeTitle WorkOrderTitle)) {
|
||||
if ( $Param{SearchParams}->{$Element} ) {
|
||||
$Search{$Element} = '*' . $Param{SearchParams}->{$Element} . '*';
|
||||
}
|
||||
}
|
||||
|
||||
# search the workorders
|
||||
# no need to use OrderBy here, because it is sorted in TableCreateComplex and TableCreatSimple
|
||||
my $WorkOrderIDsRef = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderSearch(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
UsingWildcards => 1,
|
||||
MirrorDB => 1,
|
||||
|
||||
# TODO:
|
||||
# use sysconfig option for 'limit' instead, decide wheater this option would be only
|
||||
# valid for linking workorders, or just use a global setting for all linking stuff
|
||||
Limit => 200,
|
||||
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
WORKORDERID:
|
||||
for my $WorkOrderID ( @{$WorkOrderIDsRef} ) {
|
||||
|
||||
# get workorder data
|
||||
my $WorkOrderData = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
|
||||
WorkOrderID => $WorkOrderID,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next WORKORDERID if !$WorkOrderData;
|
||||
|
||||
# get change data for this workorder
|
||||
my $ChangeData = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
|
||||
ChangeID => $WorkOrderData->{ChangeID},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next WORKORDERID if !$ChangeData;
|
||||
|
||||
# add the change data to workorder data
|
||||
my %Data = (
|
||||
%{$WorkOrderData},
|
||||
ChangeData => $ChangeData,
|
||||
);
|
||||
|
||||
# add workorder data
|
||||
$SearchList{NOTLINKED}->{Source}->{$WorkOrderID} = \%Data;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
Link add pre event module.
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMWorkOrder',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMWorkOrder',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
Link add pre event module.
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMWorkOrder',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMWorkOrder',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# trigger WorkOrderLinkAddPost-Event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->EventHandler(
|
||||
Event => 'WorkOrderLinkAddPost',
|
||||
Data => {
|
||||
WorkOrderID => $Param{Key},
|
||||
Object => $Object, # the other object of the link
|
||||
ID => $ID, # id of the other object
|
||||
Type => $Param{Type}, # the link type
|
||||
%Param,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
Link delete pre event module.
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMWorkOrder',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMWorkOrder',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
Link delete post event module.
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'ITSMWorkOrder',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'ITSMWorkOrder',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do not trigger event for temporary links
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get information about linked object
|
||||
my $ID = $Param{TargetKey} || $Param{SourceKey};
|
||||
my $Object = $Param{TargetObject} || $Param{SourceObject};
|
||||
|
||||
# trigger WorkOrderLinkDeletePost-Event
|
||||
$Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->EventHandler(
|
||||
Event => 'WorkOrderLinkDeletePost',
|
||||
Data => {
|
||||
WorkOrderID => $Param{Key},
|
||||
Object => $Object, # the other object of the link
|
||||
ID => $ID, # id of the other object
|
||||
Type => $Param{Type}, # the link type
|
||||
%Param,
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
519
Perl OTRS/Kernel/System/LinkObject/Service.pm
Normal file
519
Perl OTRS/Kernel/System/LinkObject/Service.pm
Normal file
@@ -0,0 +1,519 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::Service;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Group',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Service',
|
||||
'Kernel::Language',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::Service
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Service backend for the service link object.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=cut
|
||||
|
||||
=head2 new()
|
||||
|
||||
create an object
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $LinkObjectServiceObject = $Kernel::OM->Get('Kernel::System::LinkObject::Service');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
fill up the link list with data
|
||||
|
||||
$Success = $LinkObjectBackend->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
SERVICEID:
|
||||
for my $ServiceID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get service data
|
||||
my %ServiceData = $Kernel::OM->Get('Kernel::System::Service')->ServiceGet(
|
||||
ServiceID => $ServiceID,
|
||||
IncidentState => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# remove id from hash if no service data was found
|
||||
if ( !%ServiceData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$ServiceID};
|
||||
next SERVICEID;
|
||||
}
|
||||
|
||||
# add service data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$ServiceID} = \%ServiceData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'Service',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check module registry of AgentITSMServiceZoom
|
||||
my $ModuleReg = $Kernel::OM->Get('Kernel::Config')->Get('Frontend::Module')->{AgentITSMServiceZoom};
|
||||
|
||||
# do not grant access if frontend module is not registered
|
||||
return if !$ModuleReg;
|
||||
|
||||
# grant access if module permisson has no Group or GroupRo defined
|
||||
if ( !$ModuleReg->{GroupRo} && !$ModuleReg->{Group} ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
PERMISSION:
|
||||
for my $Permission (qw(GroupRo Group)) {
|
||||
|
||||
next PERMISSION if !$ModuleReg->{$Permission};
|
||||
next PERMISSION if ref $ModuleReg->{$Permission} ne 'ARRAY';
|
||||
|
||||
for my $Group ( @{ $ModuleReg->{$Permission} } ) {
|
||||
|
||||
# get the group id
|
||||
my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Group );
|
||||
|
||||
my $Type;
|
||||
if ( $Permission eq 'GroupRo' ) {
|
||||
$Type = 'ro';
|
||||
}
|
||||
elsif ( $Permission eq 'Group' ) {
|
||||
$Type = 'rw';
|
||||
}
|
||||
|
||||
# get user groups, where the user has the appropriate privilege
|
||||
my %Groups = $Kernel::OM->Get('Kernel::System::Group')->GroupMemberList(
|
||||
UserID => $Param{UserID},
|
||||
Type => $Type,
|
||||
Result => 'HASH',
|
||||
);
|
||||
|
||||
# grant access if agent is a member in the group
|
||||
return 1 if $Groups{$GroupID};
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
return a hash of object descriptions
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => "Service ServiceName",
|
||||
Long => "Service ParentService::ServiceName",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $ServiceStrg = $Kernel::OM->Get('Kernel::Language')->Translate('Service');
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => $ServiceStrg,
|
||||
Long => $ServiceStrg,
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get service
|
||||
my %Service = $Kernel::OM->Get('Kernel::System::Service')->ServiceGet(
|
||||
ServiceID => $Param{Key},
|
||||
IncidentState => 0,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
return if !%Service;
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $ServiceStrg . " '$Service{NameShort}'",
|
||||
Long => $ServiceStrg . " '$Service{Name}'",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
return a hash list of the search results
|
||||
|
||||
Returns:
|
||||
|
||||
$SearchList = {
|
||||
NOTLINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
$SearchList = $LinkObjectBackend->ObjectSearch(
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# add wildcards
|
||||
my %Search;
|
||||
if ( $Param{SearchParams}->{Name} ) {
|
||||
$Search{Name} = '*' . $Param{SearchParams}->{Name} . '*';
|
||||
}
|
||||
|
||||
# search the services
|
||||
my @ServiceIDs = $Kernel::OM->Get('Kernel::System::Service')->ServiceSearch(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
Limit => 50,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
SERVICEID:
|
||||
for my $ServiceID (@ServiceIDs) {
|
||||
|
||||
# get service data
|
||||
my %ServiceData = $Kernel::OM->Get('Kernel::System::Service')->ServiceGet(
|
||||
ServiceID => $ServiceID,
|
||||
IncidentState => 1,
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
next SERVICEID if !%ServiceData;
|
||||
|
||||
# add service data
|
||||
$SearchList{NOTLINKED}->{Source}->{$ServiceID} = \%ServiceData;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'Service',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'Service',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'Service',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'Service',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
link delete pre event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'Service',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'Service',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
link delete post event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'Service',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'Service',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# update the current incident state type from CIs of the service
|
||||
# in order to ensure that the dynamic incident calculation is reset after
|
||||
# unlinking a CI which has been in an incident state
|
||||
$Kernel::OM->Get('Kernel::System::Service')->ServicePreferencesSet(
|
||||
ServiceID => $Param{Key},
|
||||
Key => 'CurInciStateTypeFromCIs',
|
||||
Value => '',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
600
Perl OTRS/Kernel/System/LinkObject/Ticket.pm
Normal file
600
Perl OTRS/Kernel/System/LinkObject/Ticket.pm
Normal file
@@ -0,0 +1,600 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::LinkObject::Ticket;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Ticket',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::LinkObject::Ticket
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Ticket backend for the ticket link object.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Don't use the constructor directly, use the ObjectManager instead:
|
||||
|
||||
my $LinkObjectTicketObject = $Kernel::OM->Get('Kernel::System::LinkObject::Ticket');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 LinkListWithData()
|
||||
|
||||
fill up the link list with data
|
||||
|
||||
$Success = $LinkObject->LinkListWithData(
|
||||
LinkList => $HashRef,
|
||||
IgnoreLinkedTicketStateTypes => 0|1, # (optional) default 0
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkListWithData {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(LinkList UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# check link list
|
||||
if ( ref $Param{LinkList} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'LinkList must be a hash reference!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
# get config, which ticket state types should not be included in linked tickets overview
|
||||
my @IgnoreLinkedTicketStateTypes = @{
|
||||
$Kernel::OM->Get('Kernel::Config')->Get('LinkObject::IgnoreLinkedTicketStateTypes')
|
||||
// []
|
||||
};
|
||||
|
||||
my %IgnoreLinkTicketStateTypesHash;
|
||||
map { $IgnoreLinkTicketStateTypesHash{$_}++ } @IgnoreLinkedTicketStateTypes;
|
||||
|
||||
for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
|
||||
|
||||
for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
|
||||
|
||||
TICKETID:
|
||||
for my $TicketID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
|
||||
|
||||
# get ticket data
|
||||
my %TicketData = $TicketObject->TicketGet(
|
||||
TicketID => $TicketID,
|
||||
UserID => $Param{UserID},
|
||||
DynamicFields => 0,
|
||||
);
|
||||
|
||||
# remove id from hash if ticket can not get
|
||||
if ( !%TicketData ) {
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$TicketID};
|
||||
next TICKETID;
|
||||
}
|
||||
|
||||
# if param is set, remove entries from hash with configured ticket state types
|
||||
if (
|
||||
$Param{IgnoreLinkedTicketStateTypes}
|
||||
&& $IgnoreLinkTicketStateTypesHash{ $TicketData{StateType} }
|
||||
)
|
||||
{
|
||||
delete $Param{LinkList}->{$LinkType}->{$Direction}->{$TicketID};
|
||||
next TICKETID;
|
||||
}
|
||||
|
||||
# add ticket data
|
||||
$Param{LinkList}->{$LinkType}->{$Direction}->{$TicketID} = \%TicketData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 ObjectPermission()
|
||||
|
||||
checks read permission for a given object and UserID.
|
||||
|
||||
$Permission = $LinkObject->ObjectPermission(
|
||||
Object => 'Ticket',
|
||||
Key => 123,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectPermission {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::Ticket')->TicketPermission(
|
||||
Type => 'ro',
|
||||
TicketID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
=head2 ObjectDescriptionGet()
|
||||
|
||||
return a hash of object descriptions
|
||||
|
||||
Return
|
||||
%Description = (
|
||||
Normal => "Ticket# 1234455",
|
||||
Long => "Ticket# 1234455: The Ticket Title",
|
||||
);
|
||||
|
||||
%Description = $LinkObject->ObjectDescriptionGet(
|
||||
Key => 123,
|
||||
Mode => 'Temporary', # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectDescriptionGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Object Key UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# create description
|
||||
my %Description = (
|
||||
Normal => 'Ticket',
|
||||
Long => 'Ticket',
|
||||
);
|
||||
|
||||
return %Description if $Param{Mode} && $Param{Mode} eq 'Temporary';
|
||||
|
||||
# get ticket
|
||||
my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
|
||||
TicketID => $Param{Key},
|
||||
UserID => $Param{UserID},
|
||||
DynamicFields => 0,
|
||||
);
|
||||
|
||||
return if !%Ticket;
|
||||
|
||||
my $ParamHook = $Kernel::OM->Get('Kernel::Config')->Get('Ticket::Hook') || 'Ticket#';
|
||||
$ParamHook .= $Kernel::OM->Get('Kernel::Config')->Get('Ticket::HookDivider') || '';
|
||||
|
||||
# create description
|
||||
%Description = (
|
||||
Normal => $ParamHook . "$Ticket{TicketNumber}",
|
||||
Long => $ParamHook . "$Ticket{TicketNumber}: $Ticket{Title}",
|
||||
);
|
||||
|
||||
return %Description;
|
||||
}
|
||||
|
||||
=head2 ObjectSearch()
|
||||
|
||||
return a hash list of the search results
|
||||
|
||||
Returns:
|
||||
|
||||
$SearchList = {
|
||||
NOTLINKED => {
|
||||
Source => {
|
||||
12 => $DataOfItem12,
|
||||
212 => $DataOfItem212,
|
||||
332 => $DataOfItem332,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
$SearchList = $LinkObject->ObjectSearch(
|
||||
SubObject => 'Bla', # (optional)
|
||||
SearchParams => $HashRef, # (optional)
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ObjectSearch {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
if ( !$Param{UserID} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need UserID!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# set default params
|
||||
$Param{SearchParams} ||= {};
|
||||
|
||||
# set focus
|
||||
my %Search;
|
||||
if ( $Param{SearchParams}->{TicketFulltext} ) {
|
||||
$Search{Fulltext} = '*' . $Param{SearchParams}->{TicketFulltext} . '*';
|
||||
}
|
||||
if ( $Param{SearchParams}->{TicketTitle} ) {
|
||||
$Search{Title} = '*' . $Param{SearchParams}->{TicketTitle} . '*';
|
||||
}
|
||||
|
||||
if ( IsArrayRefWithData( $Param{SearchParams}->{ArchiveID} ) ) {
|
||||
if ( $Param{SearchParams}->{ArchiveID}->[0] eq 'AllTickets' ) {
|
||||
$Search{ArchiveFlags} = [ 'y', 'n' ];
|
||||
}
|
||||
elsif ( $Param{SearchParams}->{ArchiveID}->[0] eq 'NotArchivedTickets' ) {
|
||||
$Search{ArchiveFlags} = ['n'];
|
||||
}
|
||||
elsif ( $Param{SearchParams}->{ArchiveID}->[0] eq 'ArchivedTickets' ) {
|
||||
$Search{ArchiveFlags} = ['y'];
|
||||
}
|
||||
}
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
# search the tickets
|
||||
my @TicketIDs = $TicketObject->TicketSearch(
|
||||
%{ $Param{SearchParams} },
|
||||
%Search,
|
||||
Limit => 50,
|
||||
Result => 'ARRAY',
|
||||
ConditionInline => 1,
|
||||
ContentSearchPrefix => '*',
|
||||
ContentSearchSuffix => '*',
|
||||
FullTextIndex => 1,
|
||||
OrderBy => 'Down',
|
||||
SortBy => 'Age',
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my %SearchList;
|
||||
TICKETID:
|
||||
for my $TicketID (@TicketIDs) {
|
||||
|
||||
# get ticket data
|
||||
my %TicketData = $TicketObject->TicketGet(
|
||||
TicketID => $TicketID,
|
||||
UserID => $Param{UserID},
|
||||
DynamicFields => 0,
|
||||
);
|
||||
|
||||
next TICKETID if !%TicketData;
|
||||
|
||||
# add ticket data
|
||||
$SearchList{NOTLINKED}->{Source}->{$TicketID} = \%TicketData;
|
||||
}
|
||||
|
||||
return \%SearchList;
|
||||
}
|
||||
|
||||
=head2 LinkAddPre()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
SourceObject => 'Ticket',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPre(
|
||||
Key => 123,
|
||||
TargetObject => 'Ticket',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkAddPost()
|
||||
|
||||
link add pre event module
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
SourceObject => 'Ticket',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkAddPost(
|
||||
Key => 123,
|
||||
TargetObject => 'Ticket',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkAddPost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
if ( $Param{SourceObject} && $Param{SourceObject} eq 'Ticket' && $Param{SourceKey} ) {
|
||||
|
||||
# lookup ticket number
|
||||
my $TicketNumber = $TicketObject->TicketNumberLookup(
|
||||
TicketID => $Param{SourceKey},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# add ticket history entry
|
||||
$TicketObject->HistoryAdd(
|
||||
TicketID => $Param{Key},
|
||||
CreateUserID => $Param{UserID},
|
||||
HistoryType => 'TicketLinkAdd',
|
||||
Name => "\%\%$TicketNumber\%\%$Param{SourceKey}\%\%$Param{Key}",
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( $Param{TargetObject} && $Param{TargetObject} eq 'Ticket' && $Param{TargetKey} ) {
|
||||
|
||||
# lookup ticket number
|
||||
my $TicketNumber = $TicketObject->TicketNumberLookup(
|
||||
TicketID => $Param{TargetKey},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# add ticket history entry
|
||||
$TicketObject->HistoryAdd(
|
||||
TicketID => $Param{Key},
|
||||
CreateUserID => $Param{UserID},
|
||||
HistoryType => 'TicketLinkAdd',
|
||||
Name => "\%\%$TicketNumber\%\%$Param{TargetKey}\%\%$Param{Key}",
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePre()
|
||||
|
||||
link delete pre event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
SourceObject => 'Ticket',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePre(
|
||||
Key => 123,
|
||||
TargetObject => 'Ticket',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePre {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 LinkDeletePost()
|
||||
|
||||
link delete post event module
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
SourceObject => 'Ticket',
|
||||
SourceKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
or
|
||||
|
||||
$True = $LinkObject->LinkDeletePost(
|
||||
Key => 123,
|
||||
TargetObject => 'Ticket',
|
||||
TargetKey => 321,
|
||||
Type => 'Normal',
|
||||
State => 'Valid',
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub LinkDeletePost {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check needed stuff
|
||||
for my $Argument (qw(Key Type State UserID)) {
|
||||
if ( !$Param{$Argument} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Argument!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 1 if $Param{State} eq 'Temporary';
|
||||
|
||||
# get ticket object
|
||||
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
|
||||
|
||||
if ( $Param{SourceObject} && $Param{SourceObject} eq 'Ticket' && $Param{SourceKey} ) {
|
||||
|
||||
# lookup ticket number
|
||||
my $TicketNumber = $TicketObject->TicketNumberLookup(
|
||||
TicketID => $Param{SourceKey},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# add ticket history entry
|
||||
$TicketObject->HistoryAdd(
|
||||
TicketID => $Param{Key},
|
||||
CreateUserID => $Param{UserID},
|
||||
HistoryType => 'TicketLinkDelete',
|
||||
Name => "\%\%$TicketNumber\%\%$Param{SourceKey}\%\%$Param{Key}",
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( $Param{TargetObject} && $Param{TargetObject} eq 'Ticket' && $Param{TargetKey} ) {
|
||||
|
||||
# lookup ticket number
|
||||
my $TicketNumber = $TicketObject->TicketNumberLookup(
|
||||
TicketID => $Param{TargetKey},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
# add ticket history entry
|
||||
$TicketObject->HistoryAdd(
|
||||
TicketID => $Param{Key},
|
||||
CreateUserID => $Param{UserID},
|
||||
HistoryType => 'TicketLinkDelete',
|
||||
Name => "\%\%$TicketNumber\%\%$Param{TargetKey}\%\%$Param{Key}",
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user