# --
# 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).
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.
=cut
1;