# --
# 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::ITSMConfigItem::Permission::ItemClassGroupCheck;
use strict;
use warnings;
## nofilter(TidyAll::Plugin::OTRS::Migrations::OTRS6::SysConfig)
our @ObjectDependencies = (
'Kernel::System::GeneralCatalog',
'Kernel::System::Group',
'Kernel::System::ITSMConfigItem',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ITSMConfigItem::Permission::ItemClassGroupCheck - check if a user can access an item
=head1 DESCRIPTION
All config item functions.
=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::ITSMConfigItem::Permission::ItemClassGroupCheck');
=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 if the user can access an item
my $HasAccess = $CheckObject->Run(
UserID => 123,
Type => 'ro',
ItemID => 345,
);
=cut
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for my $Needed (qw(UserID Type ItemID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
# get config item data
my $ConfigItem = $Kernel::OM->Get('Kernel::System::ITSMConfigItem')->ConfigItemGet(
ConfigItemID => $Param{ItemID},
);
# get Class data
my $ClassItem = $Kernel::OM->Get('Kernel::System::GeneralCatalog')->ItemGet(
ItemID => $ConfigItem->{ClassID},
);
# get user groups
my @GroupIDs = $Kernel::OM->Get('Kernel::System::Group')->GroupMemberList(
UserID => $Param{UserID},
Type => $Param{Type},
Result => 'ID',
Cached => 1,
);
# looking for group id, return access if user is in group
for my $GroupID (@GroupIDs) {
return 1 if $ClassItem->{Permission} && $GroupID eq $ClassItem->{Permission};
}
# return no access
return;
}
1;
=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