-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathCloseParentAfterClosedChilds.pm
118 lines (96 loc) · 3.3 KB
/
CloseParentAfterClosedChilds.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# --
# OTOBO is a web-based ticketing system for service organisations.
# --
# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
# Copyright (C) 2019-2023 Rother OSS GmbH, https://otobo.de/
# --
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# --
package Kernel::System::Ticket::Acl::CloseParentAfterClosedChilds;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::LinkObject',
'Kernel::System::Log',
'Kernel::System::Ticket',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Config Acl)) {
if ( !$Param{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
# check if child tickets are not closed
return 1 if !$Param{TicketID} || !$Param{UserID};
# link tickets
my $Links = $Kernel::OM->Get('Kernel::System::LinkObject')->LinkList(
Object => 'Ticket',
Key => $Param{TicketID},
State => 'Valid',
Type => 'ParentChild',
UserID => $Param{UserID},
);
return 1 if !$Links;
return 1 if ref $Links ne 'HASH';
return 1 if !$Links->{Ticket};
return 1 if ref $Links->{Ticket} ne 'HASH';
return 1 if !$Links->{Ticket}->{ParentChild};
return 1 if ref $Links->{Ticket}->{ParentChild} ne 'HASH';
return 1 if !$Links->{Ticket}->{ParentChild}->{Target};
return 1 if ref $Links->{Ticket}->{ParentChild}->{Target} ne 'HASH';
my $OpenSubTickets = 0;
TICKETID:
for my $TicketID ( sort keys %{ $Links->{Ticket}->{ParentChild}->{Target} } ) {
# get ticket
my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
TicketID => $TicketID,
DynamicFields => 0,
);
if ( $Ticket{StateType} !~ m{ \A (close|merge|remove) }xms ) {
$OpenSubTickets = 1;
last TICKETID;
}
}
# generate acl
if ($OpenSubTickets) {
$Param{Acl}->{CloseParentAfterClosedChilds} = {
# match properties
Properties => {
# current ticket match properties
Ticket => {
TicketID => [ $Param{TicketID} ],
},
},
# return possible options (black list)
PossibleNot => {
# possible ticket options (black list)
Ticket => {
State => $Param{Config}->{State},
},
Action => ['AgentTicketClose'],
},
};
}
return 1;
}
1;