init III
This commit is contained in:
65
Perl OTRS/Kernel/Output/HTML/FAQMenu/Delete.pm
Normal file
65
Perl OTRS/Kernel/Output/HTML/FAQMenu/Delete.pm
Normal file
@@ -0,0 +1,65 @@
|
||||
# --
|
||||
# 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::Output::HTML::FAQMenu::Delete;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Prevent used only once warning
|
||||
use Kernel::System::ObjectManager;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Output::HTML::Layout',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# Get UserID param.
|
||||
$Self->{UserID} = $Param{UserID} || die "Got no UserID!";
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Run Kernel::Output::HTML::FAQMenu::Generic.
|
||||
my $GenericObject = Kernel::Output::HTML::FAQMenu::Generic->new( UserID => $Self->{UserID} );
|
||||
$GenericObject->Run(
|
||||
%Param,
|
||||
);
|
||||
|
||||
# Create structure for JS.
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
my %JSData;
|
||||
$JSData{ $Param{MenuID} } = {
|
||||
ElementID => $Param{MenuID},
|
||||
ElementSelector => '#' . $Param{MenuID},
|
||||
DialogContentQueryString => 'Action=AgentFAQDelete;ItemID=' . $Param{FAQItem}->{ItemID},
|
||||
ConfirmedActionQueryString => 'Action=AgentFAQDelete;Subaction=Delete;ItemID=' . $Param{FAQItem}->{ItemID},
|
||||
DialogTitle => $LayoutObject->{LanguageObject}->Translate('Delete'),
|
||||
};
|
||||
|
||||
# Send data to JS.
|
||||
$LayoutObject->AddJSData(
|
||||
Key => 'FAQData',
|
||||
Value => \%JSData,
|
||||
);
|
||||
|
||||
$Param{Counter}++;
|
||||
|
||||
return $Param{Counter};
|
||||
}
|
||||
|
||||
1;
|
||||
126
Perl OTRS/Kernel/Output/HTML/FAQMenu/Generic.pm
Normal file
126
Perl OTRS/Kernel/Output/HTML/FAQMenu/Generic.pm
Normal file
@@ -0,0 +1,126 @@
|
||||
# --
|
||||
# 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::Output::HTML::FAQMenu::Generic;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Group',
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
# get UserID param
|
||||
$Self->{UserID} = $Param{UserID} || die "Got no UserID!";
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !$Param{FAQItem} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => 'Need FAQItem!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
# grant access by default
|
||||
my $Access = 1;
|
||||
|
||||
# get groups
|
||||
my $Action = $Param{Config}->{Action};
|
||||
if ( $Action eq 'AgentLinkObject' ) {
|
||||
|
||||
# The Link-link is a special case, as it is not specific to FAQ.
|
||||
# As a workaround we hardcore that AgentLinkObject is treated like AgentFAQEdit
|
||||
$Action = 'AgentFAQEdit';
|
||||
}
|
||||
|
||||
# get configuration settings for the specified action
|
||||
my $Config = $Kernel::OM->Get('Kernel::Config')->Get('Frontend::Module')->{$Action};
|
||||
|
||||
my $GroupsRo = $Config->{GroupRo} || [];
|
||||
my $GroupsRw = $Config->{Group} || [];
|
||||
|
||||
# check permission
|
||||
if ( $Action && ( @{$GroupsRo} || @{$GroupsRw} ) ) {
|
||||
|
||||
# deny access by default, when there are groups to check
|
||||
$Access = 0;
|
||||
my $HasPermission;
|
||||
|
||||
# check read only groups
|
||||
ROGROUP:
|
||||
for my $RoGroup ( @{$GroupsRo} ) {
|
||||
|
||||
$HasPermission = $Kernel::OM->Get('Kernel::System::Group')->PermissionCheck(
|
||||
UserID => $Self->{UserID},
|
||||
GroupName => $RoGroup,
|
||||
Type => 'ro',
|
||||
);
|
||||
|
||||
next ROGROUP if !$HasPermission;
|
||||
next ROGROUP if $HasPermission != 1;
|
||||
|
||||
# set access
|
||||
$Access = 1;
|
||||
last ROGROUP;
|
||||
}
|
||||
|
||||
# check read write groups
|
||||
RWGROUP:
|
||||
for my $RwGroup ( @{$GroupsRw} ) {
|
||||
|
||||
$HasPermission = $Kernel::OM->Get('Kernel::System::Group')->PermissionCheck(
|
||||
UserID => $Self->{UserID},
|
||||
GroupName => $RwGroup,
|
||||
Type => 'rw',
|
||||
);
|
||||
|
||||
next RWGROUP if !$HasPermission;
|
||||
next RWGROUP if $HasPermission != 1;
|
||||
|
||||
# set access
|
||||
$Access = 1;
|
||||
last RWGROUP;
|
||||
}
|
||||
}
|
||||
|
||||
return $Param{Counter} if !$Access;
|
||||
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
# output menu item
|
||||
$LayoutObject->Block(
|
||||
Name => 'MenuItem',
|
||||
Data => {
|
||||
%Param,
|
||||
%{ $Param{FAQItem} },
|
||||
%{ $Param{Config} },
|
||||
},
|
||||
);
|
||||
|
||||
$Param{Counter}++;
|
||||
|
||||
return $Param{Counter};
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user