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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# Copyright (C) 2021 Znuny GmbH, https://znuny.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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
use strict;
use warnings;
use utf8;
use vars (qw($Self));
$Kernel::OM->ObjectParamAdd(
'Kernel::System::UnitTest::Helper' => {
RestoreDatabase => 1,
UseTmpArticleDir => 1,
},
);
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
# Set fixed time to create user in pst.
# Then when it is set to invalid, it have been invalid for more than a month.
$HelperObject->FixedTimeSet(
$Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
String => '2019-06-15 00:00:00',
},
)->ToEpoch()
);
my $CommandObject = $Kernel::OM->Get('Kernel::System::Console::Command::Maint::Ticket::InvalidUserCleanup');
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
my $ArticleBackendObject = $ArticleObject->BackendForChannel( ChannelName => 'Internal' );
$Kernel::OM->Get('Kernel::Config')->Set(
Key => 'CheckMXRecord',
Value => 0,
);
# Enable ticket watcher feature.
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Ticket::Watcher',
Value => 1,
);
my ( $UserName1, $UserID1 ) = $HelperObject->TestUserCreate();
my $TicketID1 = $TicketObject->TicketCreate(
Title => 'A test for ticket unlocking',
Queue => 'Raw',
Lock => 'lock',
Priority => '3 normal',
State => 'pending reminder',
CustomerNo => '123465',
CustomerUser => 'customer@example.com',
OwnerID => $UserID1,
UserID => $UserID1,
);
my $ArticleID1 = $ArticleBackendObject->ArticleCreate(
TicketID => $TicketID1,
SenderType => 'agent',
IsVisibleForCustomer => 0,
From => 'Some Agent <email@example.com>',
To => 'Some Customer <customer-a@example.com>',
Subject => 'some short description',
Body => 'the message text',
ContentType => 'text/plain; charset=ISO-8859-15',
HistoryType => 'OwnerUpdate',
HistoryComment => 'Some free text!',
UserID => $UserID1,
NoAgentNotify => 1,
);
$Self->True(
$ArticleID1,
"ArticleCreate() - $ArticleID1",
);
my $Set = $ArticleObject->ArticleFlagSet(
TicketID => $TicketID1,
ArticleID => $ArticleID1,
Key => 'seen',
Value => 1,
UserID => $UserID1,
);
$Self->True(
$Set,
"ArticleFlagSet() article $ArticleID1",
);
# Set user as an invalid.
my %User = $UserObject->GetUserData( User => $UserName1 );
$Kernel::OM->Get('Kernel::System::User')->UserUpdate(
%User,
ValidID => 2,
ChangeUserID => 1,
);
my $Subscribe = $TicketObject->TicketWatchSubscribe(
TicketID => $TicketID1,
WatchUserID => $UserID1,
UserID => $UserID1,
);
$Self->True(
$Subscribe,
"TicketWatchSubscribe() User:$UserID1 to Ticket:$TicketID1",
);
# Set current time in order to check InvalidUserCleanup console command.
# Created test user will be invalid for more than a month.
$HelperObject->FixedTimeSet();
my ( $UserName2, $UserID2 ) = $HelperObject->TestUserCreate();
my $TicketID2 = $TicketObject->TicketCreate(
Title => 'A test for ticket unlocking',
Queue => 'Raw',
Lock => 'lock',
Priority => '3 normal',
State => 'pending reminder',
CustomerNo => '123465',
CustomerUser => 'customer@example.com',
OwnerID => $UserID2,
UserID => $UserID2,
);
my $ArticleID2 = $ArticleBackendObject->ArticleCreate(
TicketID => $TicketID1,
SenderType => 'agent',
IsVisibleForCustomer => 0,
From => 'Some Agent <email@example.com>',
To => 'Some Customer <customer-a@example.com>',
Subject => 'some short description',
Body => 'the message text',
ContentType => 'text/plain; charset=ISO-8859-15',
HistoryType => 'OwnerUpdate',
HistoryComment => 'Some free text!',
UserID => $UserID2,
NoAgentNotify => 1,
);
$Self->True(
$ArticleID2,
"ArticleCreate() - $ArticleID2"
);
$Subscribe = $TicketObject->TicketWatchSubscribe(
TicketID => $TicketID2,
WatchUserID => $UserID2,
UserID => $UserID2,
);
$Self->True(
$Subscribe,
"TicketWatchSubscribe() User:$UserID2 to Ticket:$TicketID2",
);
my $ExitCode = $CommandObject->Execute();
# Just check exit code.
$Self->Is(
$ExitCode,
0,
"Maint::Ticket::InvalidUserCleanup exit code",
);
my %Ticket = $TicketObject->TicketGet(
UserID => 1,
TicketID => $TicketID1,
);
$Self->Is(
$Ticket{Lock},
'unlock',
'Ticket from invalid owner was unlocked',
);
$Self->Is(
$Ticket{State},
'open',
'Ticket from invalid owner was set to "open"',
);
my @HistoryLines = $TicketObject->HistoryGet(
TicketID => $TicketID1,
UserID => 1,
);
$Self->True(
scalar( grep { $_->{HistoryType} eq 'Unsubscribe' } @HistoryLines ) // 0,
"'Unsubscribe' history entry of invalid user - found for UserID $UserID1, TicketID $TicketID1",
);
# Check if there is Unsubscribe history entry for ticket
# that is not subscribed with invalid ticket.
# See more information in bug#14987.
@HistoryLines = $TicketObject->HistoryGet(
TicketID => $TicketID2,
UserID => 1,
);
$Self->False(
scalar( grep { $_->{HistoryType} eq 'Unsubscribe' } @HistoryLines ) // 1,
"'Unsubscribe' history entry of invalid user - not found for UserID $UserID2, TicketID $TicketID2",
);
# Cleanup cache is done by RestoreDatabase.
1;
|