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
9package Kernel::Output::HTML::TicketMenu::Lock;
10
11use parent 'Kernel::Output::HTML::Base';
12
13use strict;
14use warnings;
15
16use Kernel::Language qw(Translatable);
17
18our @ObjectDependencies = (
19    'Kernel::System::Log',
20    'Kernel::Config',
21    'Kernel::System::Ticket',
22    'Kernel::System::Group',
23);
24
25sub Run {
26    my ( $Self, %Param ) = @_;
27
28    # get log object
29    my $LogObject = $Kernel::OM->Get('Kernel::System::Log');
30
31    # check needed stuff
32    if ( !$Param{Ticket} ) {
33        $LogObject->Log(
34            Priority => 'error',
35            Message  => 'Need Ticket!'
36        );
37        return;
38    }
39
40    # check if frontend module registered, if not, do not show action
41    if ( $Param{Config}->{Action} ) {
42        my $Module = $Kernel::OM->Get('Kernel::Config')->Get('Frontend::Module')->{ $Param{Config}->{Action} };
43        return if !$Module;
44    }
45
46    # get ticket object
47    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
48
49    # check lock permission
50    my $AccessOk = $TicketObject->TicketPermission(
51        Type     => 'lock',
52        TicketID => $Param{Ticket}->{TicketID},
53        UserID   => $Self->{UserID},
54        LogNo    => 1,
55    );
56    return if !$AccessOk;
57
58    # check permission
59    if ( $TicketObject->TicketLockGet( TicketID => $Param{Ticket}->{TicketID} ) ) {
60        my $AccessOk = $TicketObject->OwnerCheck(
61            TicketID => $Param{Ticket}->{TicketID},
62            OwnerID  => $Self->{UserID},
63        );
64        return if !$AccessOk;
65    }
66
67    # group check
68    if ( $Param{Config}->{Group} ) {
69
70        my @Items = split /;/, $Param{Config}->{Group};
71
72        my $AccessOk;
73        ITEM:
74        for my $Item (@Items) {
75
76            my ( $Permission, $Name ) = split /:/, $Item;
77
78            if ( !$Permission || !$Name ) {
79                $LogObject->Log(
80                    Priority => 'error',
81                    Message  => "Invalid config for Key Group: '$Item'! "
82                        . "Need something like '\$Permission:\$Group;'",
83                );
84            }
85
86            my %Groups = $Kernel::OM->Get('Kernel::System::Group')->PermissionUserGet(
87                UserID => $Self->{UserID},
88                Type   => $Permission,
89            );
90
91            next ITEM if !%Groups;
92
93            my %GroupsReverse = reverse %Groups;
94
95            next ITEM if !$GroupsReverse{$Name};
96
97            $AccessOk = 1;
98
99            last ITEM;
100        }
101
102        return if !$AccessOk;
103    }
104
105    # check acl
106    my %ACLLookup = reverse( %{ $Param{ACL} || {} } );
107    return if ( !$ACLLookup{ $Param{Config}->{Action} } );
108
109    # if ticket is locked
110    if ( $Param{Ticket}->{Lock} eq 'lock' ) {
111
112        # if it is locked for somebody else
113        return if $Param{Ticket}->{OwnerID} ne $Self->{UserID};
114
115        # show unlock action
116        return {
117            %{ $Param{Config} },
118            %{ $Param{Ticket} },
119            %Param,
120            Name        => Translatable('Unlock'),
121            Description => Translatable('Unlock to give it back to the queue'),
122            Link =>
123                'Action=AgentTicketLock;Subaction=Unlock;TicketID=[% Data.TicketID | uri %];[% Env("ChallengeTokenParam") | html %]',
124        };
125    }
126
127    # if ticket is unlocked
128    return {
129        %{ $Param{Config} },
130        %{ $Param{Ticket} },
131        %Param,
132        Name        => Translatable('Lock'),
133        Description => Translatable('Lock it to work on it'),
134        Link =>
135            'Action=AgentTicketLock;Subaction=Lock;TicketID=[% Data.TicketID | uri %];[% Env("ChallengeTokenParam") | html %]',
136    };
137}
138
1391;
140