1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9use strict;
10use warnings;
11use utf8;
12
13use vars (qw($Self));
14
15# get needed objects
16my $QueueObject  = $Kernel::OM->Get('Kernel::System::Queue');
17my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
18
19# get helper object
20$Kernel::OM->ObjectParamAdd(
21    'Kernel::System::UnitTest::Helper' => {
22        RestoreDatabase  => 1,
23        UseTmpArticleDir => 1,
24    },
25);
26my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
27
28$Kernel::OM->Get('Kernel::Config')->Set(
29    Key   => 'Ticket::Acl::Module',
30    Value => {
31        DummyModule => {
32            Module        => 'scripts::test::Ticket::TicketACL::DummyModule',
33            ReturnType    => 'Ticket',
34            ReturnSubType => 'State',
35            Checks        => ['Ticket'],
36        },
37    },
38);
39
40# set valid options
41my %ValidList = $Kernel::OM->Get('Kernel::System::Valid')->ValidList();
42%ValidList = reverse %ValidList;
43
44# set user options
45my ( $UserLogin, $UserID ) = $Helper->TestUserCreate(
46    Groups => ['admin'],
47);
48
49my $RandomID = $Helper->GetRandomID();
50
51# set queue options
52my $QueueName = 'Queue_' . $RandomID;
53my $QueueID   = $QueueObject->QueueAdd(
54    Name            => $QueueName,
55    ValidID         => $ValidList{'valid'},
56    GroupID         => 1,
57    SystemAddressID => 1,
58    SalutationID    => 1,
59    SignatureID     => 1,
60    Comment         => 'Some comment',
61    UserID          => 1,
62);
63
64# sanity check
65$Self->True(
66    $QueueID,
67    "QueueAdd() ID ($QueueID) added successfully"
68);
69
70# set state options
71my $StateName = 'State_' . $RandomID;
72my $StateID   = $Kernel::OM->Get('Kernel::System::State')->StateAdd(
73    Name    => $StateName,
74    ValidID => 1,
75    TypeID  => 1,
76    UserID  => 1,
77);
78
79# sanity check
80$Self->True(
81    $StateID,
82    "StateAdd() ID ($StateID) added successfully"
83);
84
85# set priority options
86my $PriorityName = 'Priority_' . $RandomID;
87my $PriorityID   = $Kernel::OM->Get('Kernel::System::Priority')->PriorityAdd(
88    Name    => $PriorityName,
89    ValidID => $ValidList{'valid'},
90    UserID  => 1,
91);
92
93# sanity check
94$Self->True(
95    $PriorityID,
96    "PriorityAdd() ID ($PriorityID) added successfully"
97);
98
99my $TicketID = $TicketObject->TicketCreate(
100    Title      => 'Test Ticket for TicketACL Module tests',
101    QueueID    => $QueueID,
102    Lock       => 'lock',
103    StateID    => $StateID,
104    OwnerID    => $UserID,
105    UserID     => 1,
106    PriorityID => $PriorityID,
107);
108
109$Self->True(
110    $TicketID,
111    "Ticket ID ($TicketID) successfully created",
112);
113
114my $AclSuccess = $TicketObject->TicketAcl(
115    TicketID      => $TicketID,
116    ReturnType    => 'Ticket',
117    ReturnSubType => 'State',
118    UserID        => $UserID,
119    Data          => {
120        1 => 'new',
121        2 => 'open',
122    },
123);
124
125$Self->True(
126    $AclSuccess,
127    'ACL from module matched',
128);
129
130my %ACLData = $TicketObject->TicketAclData();
131
132$Self->IsDeeply(
133    \%ACLData,
134    { 1 => 'new' },
135    'AclData from module',
136);
137
138$AclSuccess = $TicketObject->TicketAcl(
139    TicketID      => $TicketID,
140    ReturnType    => 'Ticket',
141    ReturnSubType => 'Service',
142    UserID        => $UserID,
143    Data          => {
144        1 => 'new',
145    },
146);
147
148$Self->False(
149    $AclSuccess,
150    'Non-matching ACL from module',
151);
152
153# cleanup is done by RestoreDatabase.
154
1551;
156