This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
# --
# 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::Event::ToolBarMyWorkOrdersCacheDelete;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Cache',
'Kernel::System::Log',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for my $Argument (qw(Data Event Config UserID)) {
if ( !$Param{$Argument} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Argument!",
);
return;
}
}
# set the cache type prefix
my $CacheTypePrefix = 'ITSMChangeManagementToolBarMyWorkOrders';
# handle adding of a workorder
if ( $Param{Event} eq 'WorkOrderAddPost' ) {
# do nothing if the WorkOrderAgentID was not set
return 1 if !$Param{Data}->{WorkOrderAgentID};
# set the cache type
my $CacheType = $CacheTypePrefix . $Param{Data}->{WorkOrderAgentID};
# delete the cache
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => $CacheType,
);
return 1;
}
# handle update of a workorder
elsif ( $Param{Event} eq 'WorkOrderUpdatePost' ) {
# make sure the data is initialized
$Param{Data}->{WorkOrderAgentID} ||= '';
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID} ||= '';
# do nothing if the WorkOrderAgentID did not change
return 1
if $Param{Data}->{WorkOrderAgentID} eq
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
# set the cache type postfix
my @CacheTypePostfixes = (
$Param{Data}->{WorkOrderAgentID},
$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID},
);
# delete the cache for the old and the current workorder agent
CACHETYPEPOSTFIX:
for my $CacheTypePostfix (@CacheTypePostfixes) {
# do nothing if the WorkOrderAgentID was not set
next CACHETYPEPOSTFIX if !$CacheTypePostfix;
# set the cache type
my $CacheType = $CacheTypePrefix . $CacheTypePostfix;
# delete the cache
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => $CacheType,
);
}
return 1;
}
# handle deleting a workorder
elsif ( $Param{Event} eq 'WorkOrderDeletePost' ) {
# do nothing if the WorkOrderAgentID was not set
return 1 if !$Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
# set the cache type
my $CacheType = $CacheTypePrefix . $Param{Data}->{OldWorkOrderData}->{WorkOrderAgentID};
# delete the cache
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => $CacheType,
);
return 1;
}
return 1;
}
1;

View File

@@ -0,0 +1,165 @@
# --
# 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::Event::WorkOrderActualTimesSet;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::DateTime',
'Kernel::System::ITSMChange::ITSMStateMachine',
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for my $Needed (qw(Data Event Config UserID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
# handle WorkOrderUpdate event
if ( $Param{Event} eq 'WorkOrderUpdatePost' ) {
# get WorkOrder
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
WorkOrderID => $Param{Data}->{WorkOrderID},
UserID => $Param{UserID},
);
# check error
return if !$WorkOrder;
# get actual start time from workorder
my $ActualStartTime = $WorkOrder->{ActualStartTime};
# get configured workorder states when to set actual start time
my $ConfiguredWorkOrderStartStates
= $Kernel::OM->Get('Kernel::Config')->Get('ITSMWorkOrder::ActualStartTimeSet::States');
# convert into hash for easier lookup
my %ActualStartTimeSetStates = map { $_ => 1 } @{$ConfiguredWorkOrderStartStates};
# get current time stamp
my $CurrentTimeStamp = $Kernel::OM->Create('Kernel::System::DateTime')->ToString();
# check if ActualStartTime is empty,
# and WorkOrderState is in an ActualStartTimeSetState
if ( !$ActualStartTime && $ActualStartTimeSetStates{ $WorkOrder->{WorkOrderState} } ) {
# set the actual start time
my $Success = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
WorkOrderID => $Param{Data}->{WorkOrderID},
ActualStartTime => $CurrentTimeStamp,
UserID => $Param{UserID},
);
# check error
if ( !$Success ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message =>
"Could not set ActualStartTime for WorkOrderID '$Param{Data}->{WorkOrderID}'!",
);
return;
}
# remember the just set actual start time
$ActualStartTime = $CurrentTimeStamp;
}
# check if the ActualEndTime is empty
# and the current workorder state is an end state
if ( !$WorkOrder->{ActualEndTime} ) {
# get the possible next state ids
my $NextStateIDsRef = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMStateMachine')->StateTransitionGet(
StateID => $WorkOrder->{WorkOrderStateID},
Class => 'ITSM::ChangeManagement::WorkOrder::State',
) || [];
# if there is only one next state, which is also 0,
# which means that this is an end state
if ( ( scalar @{$NextStateIDsRef} == 1 ) && ( !$NextStateIDsRef->[0] ) ) {
# if no actual start time is set, use the current time
if ( !$ActualStartTime ) {
$ActualStartTime = $CurrentTimeStamp;
}
# increase the current time stamp by one second to avoid the case that
# actual start and end times are the same
my $ActualEndTime = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
String => $CurrentTimeStamp,
},
);
$ActualEndTime->Add(
Seconds => 1,
);
$ActualEndTime = $ActualEndTime->ToString();
# set the actual end time,
# and if the actual start time was not set, set it also
my $Success = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
WorkOrderID => $Param{Data}->{WorkOrderID},
ActualStartTime => $ActualStartTime,
ActualEndTime => $ActualEndTime,
UserID => $Param{UserID},
);
# check error
if ( !$Success ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message =>
"Could not set ActualStartTime for WorkOrderID '$Param{Data}->{WorkOrderID}'!",
);
return;
}
}
}
}
# error
else {
# an unknown event
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "$Param{Event} is an unknown event for this eventhandler!",
);
return;
}
return 1;
}
1;

View File

@@ -0,0 +1,168 @@
# --
# 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::Event::WorkOrderNumberCalc;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for my $Needed (qw(Data Event Config UserID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
# check if recalculation of workorder numbers is needed
return 1 if $Param{Data}->{NoNumberCalc};
# handle WorkOrderUpdate and WorkOrderDeletePost events
if ( $Param{Event} =~ m{ \A ( WorkOrderUpdatePost | WorkOrderDeletePost ) \z }xms ) {
# recalculate WorkOrder numbers
# the ChangeID is in the OldWorkOrderData so we do not need to make a WorkOrderGet() here
return if !$Self->_WorkOrderNumberCalc(
ChangeID => $Param{Data}->{OldWorkOrderData}->{ChangeID},
UserID => $Param{UserID},
);
}
# error
else {
# an unknown event
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "$Param{Event} is an unknown event for this eventhandler!",
);
return;
}
return 1;
}
=head1 PRIVATE INTERFACE
=head2 _WorkOrderNumberCalc()
This method actually recalculates the WorkOrderNumbers for the C<workorders> of
the given change.
It returns 1 on success, C<undef> otherwise.
my $Success = $EventObject->_WorkOrderNumberCalc(
ChangeID => 123,
UserID => 1,
);
=cut
sub _WorkOrderNumberCalc {
my ( $Self, %Param ) = @_;
# check for needed stuff - ChangeID and UserID
for my $Needed (qw(ChangeID UserID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
# define the order direction for each attribute
my %OrderDirection = (
PlannedStartTime => 'Up',
PlannedEndTime => 'Down',
WorkOrderID => 'Up',
);
# define the OrderBy array
my @OrderBy = (
'PlannedStartTime',
'PlannedEndTime',
'WorkOrderID',
);
# define the OrderByDirection array
my @OrderByDirection = map { $OrderDirection{$_} } @OrderBy;
# use WorkOrderSearch: Search for given IDs, ordered by:
# PlannedStartTime, PlannedEndTime, WorOrderID
my $SortedWorkOrderIDs = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderSearch(
ChangeIDs => [ $Param{ChangeID} ],
OrderBy => \@OrderBy,
OrderByDirection => \@OrderByDirection,
UserID => $Param{UserID},
) || [];
# counter - used as WorkOrderNumber
my $Counter = 0;
# to store the WorkOrderIDs and their new WorkOrderNumbers
my %NewWorkOrderNumber;
# set new WorkOrderNumber
WORKORDERID:
for my $WorkOrderID ( @{$SortedWorkOrderIDs} ) {
# increment Counter to get new WorkOrderNumber
$Counter++;
# get WorkOrder
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
WorkOrderID => $WorkOrderID,
UserID => $Param{UserID},
);
# update only when Number changed - to avoid infinit loops
next WORKORDERID if $Counter == $WorkOrder->{WorkOrderNumber};
# store the new WorkOrderNumber for this WorkOrderID
$NewWorkOrderNumber{$WorkOrderID} = $Counter;
}
# update the workorders that need a new WorkOrderNumber
for my $WorkOrderID ( sort keys %NewWorkOrderNumber ) {
# update each workorder, prevent recalculation of the WorkOrderNumber again
my $CouldUpdateWorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderUpdate(
WorkOrderID => $WorkOrderID,
WorkOrderNumber => $NewWorkOrderNumber{$WorkOrderID},
NoNumberCalc => 1,
UserID => $Param{UserID},
);
}
return 1;
}
1;

View File

@@ -0,0 +1,112 @@
# --
# 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::CABCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::ITSMChange',
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ITSMChange::ITSMWorkOrder::Permission::CABCheck - CAB 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::CABCheck');
=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. Access is allowed when type is C<ro> and the agent is a member
of the CAB of the change of the C<workorder>.
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'rw', # 'ro' or 'rw'
WorkOrderID => 4444,
);
=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;
}
}
# only 'ro' access might be granted by this module
return if $Param{Type} ne 'ro';
# there already is a workorder
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->{ChangeID};
# get the CAB of the change
my $CAB = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeCABGet(
UserID => $Param{UserID},
ChangeID => $WorkOrder->{ChangeID},
);
# look for a CAB member with the relevant UserID
my ($FoundCABMember) = grep { $_ == $Param{UserID} } @{ $CAB->{CABAgents} };
# allow access the the agent is a CAB member
return 1 if $FoundCABMember;
# deny access otherwise
return;
}
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;

View File

@@ -0,0 +1,129 @@
# --
# 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::ChangeBuilderCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Group',
'Kernel::System::ITSMChange',
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ITSMChange::ITSMWorkOrder::Permission::ChangeBuilderCheck - change builder 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::ChangeBuilderCheck');
=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<ro> and C<rw> access is granted
when the agent has the C<priv> in the 'itsm-change-builder' group and
when the agent is the change builder of the change.
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'rw', # 'ro' or 'rw'
WorkOrderID => 4444,
);
=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 change builder
my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup(
Group => 'itsm-change-builder',
);
# do not grant 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',
);
# do not grant access if the agent doesn't have the appropriate type in the appropriate group
return if !$Groups{$GroupID};
# there already is a workorder. e.g. AgentITSMWorkOrderEdit
my $WorkOrder = $Kernel::OM->Get('Kernel::System::ITSMChange::ITSMWorkOrder')->WorkOrderGet(
UserID => $Param{UserID},
WorkOrderID => $Param{WorkOrderID},
);
# do not grant access, when no workorder was found
return if !$WorkOrder || !%{$WorkOrder} || !$WorkOrder->{ChangeID};
# for checking the change builder, we need information on the change
my $Change = $Kernel::OM->Get('Kernel::System::ITSMChange')->ChangeGet(
UserID => $Param{UserID},
ChangeID => $WorkOrder->{ChangeID},
);
# do not grant access, when no change was found
return if !$Change || !%{$Change} || !$Change->{ChangeBuilderID};
# allow access, when the agent is the change builder of the change
return 1 if $Change->{ChangeBuilderID} == $Param{UserID};
# do not grant access otherwise
return;
}
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;

View File

@@ -0,0 +1,107 @@
# --
# 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::ChangeManagerCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Group',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ITSMChange::ITSMWorkOrder::Permission::ChangeManagerCheck - change manager 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::ChangeManagerCheck');
=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<ro> and C<rw> access is granted
when the agent has the C<priv> in the 'itsm-change-manager' group.
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'rw', # 'ro' or 'rw'
WorkOrderID => 4444,
);
=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 change manager
my $GroupID = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup(
Group => 'itsm-change-manager',
);
# 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',
);
# allow ro and rw access if the agent is a change manager
return 1 if $Groups{$GroupID};
# no need to check if the agent is the actual manager of the change of the workorder
# deny access otherwise
return;
}
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;

View File

@@ -0,0 +1,124 @@
# --
# 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::EmptyAgentCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Group',
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ITSMChange::ITSMWorkOrder::Permission::EmptyAgentCheck - grant permission when agent is empty
=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::EmptyAgentCheck');
=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<ro> access is granted when the agent is a C<ro> member
of the 'itsm-change' group. C<rw> access is granted when the C<workorder> has no agent.
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'rw', # 'ro' or 'rw'
WorkOrderID => 4444,
);
=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};
# allow access, when there is no workorder agent
return 1 if !$WorkOrder->{WorkOrderAgentID};
# deny access, when workorder agent is empty
return if !$WorkOrder->{WorkOrderAgentID};
# deny rw access otherwise
return;
}
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;

View File

@@ -0,0 +1,136 @@
# --
# 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::ListAgentCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Group',
'Kernel::System::ITSMChange::ITSMWorkOrder',
'Kernel::System::Log',
'Kernel::System::User',
);
=head1 NAME
Kernel::System::ITSMChange::ITSMWorkOrder::Permission::ListAgentCheck - grant permission when the agent is in a list
=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::ListAgentCheck');
=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<ro> access is granted when the agent is a C<ro> member
of the 'itsm-change' group. C<rw> access is granted when the current C<workorder> agent
is contained in the configured list.
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'rw', # 'ro' or 'rw'
WorkOrderID => 4444,
);
=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};
# deny access, when workorder agent is empty
return if !$WorkOrder->{WorkOrderAgentID};
my $WorkOrderAgent = $Kernel::OM->Get('Kernel::System::User')->UserLookup(
UserID => $WorkOrder->{WorkOrderAgentID},
);
# deny access, when the name can not be looked up
return if !$WorkOrderAgent;
# take list of special agents from the sysconfig
my $AgentList = $Kernel::OM->Get('Kernel::Config')->Get('ITSMWorkOrder::TakePermission::List');
# allow access, when the workorder agent is in the list
return 1 if $AgentList->{$WorkOrderAgent};
# deny rw access otherwise
return;
}
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;

View File

@@ -0,0 +1,122 @@
# --
# 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<ro> access is granted when the agent is a C<ro> member
of the 'itsm-change' group. C<rw> access is granted when the agent is the C<workorder> agent
of the C<workorder>.
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<https://otrs.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 L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
1;