# -- # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/ # -- # 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. # -- package Kernel::System::ITSMChange::ITSMWorkOrder::Permission::WorkOrderAgentCheck; use strict; use warnings; our @ObjectDependencies = ( 'Kernel::System::Group', 'Kernel::System::ITSMChange::ITSMWorkOrder', 'Kernel::System::Log', ); =head1 NAME Kernel::System::ITSMChange::ITSMWorkOrder::Permission::WorkOrderAgentCheck - workorder agent based permission check =head1 PUBLIC INTERFACE =head2 new() Create an object. use Kernel::System::ObjectManager; local $Kernel::OM = Kernel::System::ObjectManager->new(); my $CheckObject = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder::Permission::WorkOrderAgentCheck'); =cut sub new { my ( $Type, %Param ) = @_; # allocate new hash for object my $Self = {}; bless( $Self, $Type ); return $Self; } =head2 Run() This method does the check. C access is granted when the agent is a C member of the 'itsm-change' group. C access is granted when the agent is the C agent of the C. my $HasAccess = $CheckObject->Run( UserID => 123, Type => 'rw', # 'ro' or 'rw' WorkOrderID => 4444, # optional for WorkOrderAdd ); =cut sub Run { my ( $Self, %Param ) = @_; # check needed stuff for my $Argument (qw(UserID Type WorkOrderID)) { if ( !$Param{$Argument} ) { $Kernel::OM->Get('Kernel::System::Log')->Log( Priority => 'error', Message => "Need $Argument!", ); return; } } # the check is based upon the workorder agent my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => 'itsm-change', ); # deny access, when the group is not found return if !$GroupID; # get user groups, where the user has the appropriate privilege my %Groups = $Kernel::OM->Get('Kernel::System::Group')->GroupMemberList( UserID => $Param{UserID}, Type => $Param{Type}, Result => 'HASH', ); # deny access if the agent doesn't have the appropriate type in the appropriate group return if !$Groups{$GroupID}; # workorder agents are granted ro access return 1 if $Param{Type} eq 'ro'; # there already is a workorder. e.g. AgentITSMWorkOrderEdit my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet( UserID => $Param{UserID}, WorkOrderID => $Param{WorkOrderID}, ); # deny access, when no workorder was found return if !$WorkOrder || !%{$WorkOrder} || !$WorkOrder->{WorkOrderAgentID}; # allow access, when the agent is the workorder agent of the workorder return 1 if $WorkOrder->{WorkOrderAgentID} == $Param{UserID}; # deny rw access otherwise return; } =head1 TERMS AND CONDITIONS This software is part of the OTRS project (L). 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 L. =cut 1;