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::Process; 10 11use parent 'Kernel::Output::HTML::Base'; 12 13use strict; 14use warnings; 15 16our @ObjectDependencies = ( 17 'Kernel::Output::HTML::NavBar::AgentTicketProcess', 18 'Kernel::System::Log', 19 'Kernel::Config', 20 'Kernel::System::Ticket', 21 'Kernel::System::Group', 22); 23 24sub Run { 25 my ( $Self, %Param ) = @_; 26 27 # get log object 28 my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); 29 30 # check needed stuff 31 if ( !$Param{Ticket} ) { 32 $LogObject->Log( 33 Priority => 'error', 34 Message => 'Need Ticket!' 35 ); 36 return; 37 } 38 39 # get config object 40 my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); 41 42 # check if ticket is already enrolled into a process 43 my $ProcessEntityID = $Param{Ticket}->{ 44 'DynamicField_' 45 . $ConfigObject->Get('Process::DynamicFieldProcessManagementProcessID') 46 } || ''; 47 return if $ProcessEntityID; 48 49 # check if frontend module registered, if not, do not show action 50 if ( $Param{Config}->{Action} ) { 51 my $Module = $ConfigObject->Get('Frontend::Module')->{ $Param{Config}->{Action} }; 52 return if !$Module; 53 } 54 55 # check permission 56 my $Config = $ConfigObject->Get("Ticket::Frontend::$Param{Config}->{Action}"); 57 if ($Config) { 58 59 # get ticket object 60 my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket'); 61 62 if ( $Config->{Permission} ) { 63 my $AccessOk = $TicketObject->TicketPermission( 64 Type => $Config->{Permission}, 65 TicketID => $Param{Ticket}->{TicketID}, 66 UserID => $Self->{UserID}, 67 LogNo => 1, 68 ); 69 return if !$AccessOk; 70 } 71 if ( $Config->{RequiredLock} ) { 72 if ( 73 $TicketObject->TicketLockGet( TicketID => $Param{Ticket}->{TicketID} ) 74 ) 75 { 76 my $AccessOk = $TicketObject->OwnerCheck( 77 TicketID => $Param{Ticket}->{TicketID}, 78 OwnerID => $Self->{UserID}, 79 ); 80 return if !$AccessOk; 81 } 82 } 83 } 84 85 # group check 86 if ( $Param{Config}->{Group} ) { 87 88 my @Items = split /;/, $Param{Config}->{Group}; 89 90 my $AccessOk; 91 ITEM: 92 for my $Item (@Items) { 93 94 my ( $Permission, $Name ) = split /:/, $Item; 95 96 if ( !$Permission || !$Name ) { 97 $LogObject->Log( 98 Priority => 'error', 99 Message => "Invalid config for Key Group: '$Item'! " 100 . "Need something like '\$Permission:\$Group;'", 101 ); 102 } 103 104 my %Groups = $Kernel::OM->Get('Kernel::System::Group')->PermissionUserGet( 105 UserID => $Self->{UserID}, 106 Type => $Permission, 107 ); 108 109 next ITEM if !%Groups; 110 111 my %GroupsReverse = reverse %Groups; 112 113 next ITEM if !$GroupsReverse{$Name}; 114 115 $AccessOk = 1; 116 117 last ITEM; 118 } 119 120 return if !$AccessOk; 121 } 122 123 # check ACL 124 if ( $Param{Config}->{Action} ) { 125 my %ACLLookup = reverse( %{ $Param{ACL} || {} } ); 126 return if ( !$ACLLookup{ $Param{Config}->{Action} } ); 127 } 128 129 # use the nav bar module to check for process ACLs to prevent code duplication 130 $Kernel::OM->ObjectParamAdd( 131 'Kernel::Output::HTML::NavBar::AgentTicketProcess' => { 132 UserID => $Self->{UserID}, 133 }, 134 ); 135 my $NavBarModule = $Kernel::OM->Get('Kernel::Output::HTML::NavBar::AgentTicketProcess'); 136 137 # check process ACLs with the nav bar module (if returns something hide the menu item) 138 return if $NavBarModule->Run(); 139 140 # return item 141 return { %{ $Param{Config} }, %{ $Param{Ticket} }, %Param }; 142} 143 1441; 145