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,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::System::Console::Command::Admin::Group::Add;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Group'
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Create a new group.');
$Self->AddOption(
Name => 'name',
Description => "Name of the new group.",
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'comment',
Description => "Comment for the new group.",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Creating a new group...</yellow>\n");
my $Success = $Kernel::OM->Get('Kernel::System::Group')->GroupAdd(
UserID => 1,
ValidID => 1,
Comment => $Self->GetOption('comment'),
Name => $Self->GetOption('name'),
);
# error handling
if ( !$Success ) {
$Self->PrintError("Can't create group.\n");
return $Self->ExitCodeError();
}
$Self->Print("<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
1;

View File

@@ -0,0 +1,105 @@
# --
# 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::Console::Command::Admin::Group::CustomerLink;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::CustomerGroup',
'Kernel::System::CustomerUser',
'Kernel::System::Group',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Connect a customer user to a group.');
$Self->AddOption(
Name => 'customer-user-login',
Description => 'Login name of the customer who should be linked to the given group.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'group-name',
Description => 'Group name of the group the given customer should be linked to.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'permission',
Description => 'Permission (ro|rw) the customer user should have for the group he is going to be linked to.',
Required => 1,
HasValue => 1,
ValueRegex => qr/(ro|rw)/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
$Self->{CustomerLogin} = $Self->GetOption('customer-user-login');
$Self->{GroupName} = $Self->GetOption('group-name');
# check role
my $CustomerName = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerName(
UserLogin => $Self->{CustomerLogin},
);
if ( !$CustomerName ) {
die "Customer $Self->{CustomerLogin} does not exist.\n";
}
# check group
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
if ( !$Self->{GroupID} ) {
die "Group $Self->{GroupName} does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Trying to link customer $Self->{CustomerLogin} to group $Self->{GroupName}...</yellow>\n");
my %Permissions;
for my $Permission (qw(ro rw)) {
$Permissions{$Permission} = ( $Self->GetOption('permission') eq $Permission ) ? 1 : 0;
}
# add user 2 group
if (
!$Kernel::OM->Get('Kernel::System::CustomerGroup')->GroupMemberAdd(
UID => $Self->{CustomerLogin},
GID => $Self->{GroupID},
UserID => 1,
ValidID => 1,
Permission => {
%Permissions,
},
)
)
{
$Self->PrintError("Can't add user to group.");
return $Self->ExitCodeError();
}
$Self->Print("<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
1;

View File

@@ -0,0 +1,102 @@
# --
# 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::Console::Command::Admin::Group::RoleLink;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Group',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Connect a role to a group.');
$Self->AddOption(
Name => 'role-name',
Description => 'Name of the role which should be linked to the given group.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'group-name',
Description => 'Group name of the group the given role should be linked to.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'permission',
Description =>
'Permissions (ro|move_into|create|note|owner|priority|rw) the role should have for the group which it is going to be linked to.',
Required => 1,
HasValue => 1,
Multiple => 1,
ValueRegex => qr/(ro|move_into|create|note|owner|priority|rw)/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
$Self->{RoleName} = $Self->GetOption('role-name');
$Self->{GroupName} = $Self->GetOption('group-name');
# check role
$Self->{RoleID} = $Kernel::OM->Get('Kernel::System::Group')->RoleLookup( Role => $Self->{RoleName} );
if ( !$Self->{RoleID} ) {
die "Role $Self->{RoleName} does not exist.\n";
}
# check group
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
if ( !$Self->{GroupID} ) {
die "Group $Self->{GroupName} does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Trying to link role $Self->{RoleName} to group $Self->{GroupName}...</yellow>\n");
my %Permissions;
for my $Permission (qw(ro move_into create note owner priority rw)) {
$Permissions{$Permission} = ( grep { $_ eq $Permission } @{ $Self->GetOption('permission') // [] } ) ? 1 : 0;
}
# add user 2 group
if (
!$Kernel::OM->Get('Kernel::System::Group')->PermissionGroupRoleAdd(
RID => $Self->{RoleID},
GID => $Self->{GroupID},
UserID => 1,
Permission => {
%Permissions,
},
)
)
{
$Self->PrintError("Can't add role to group.");
return $Self->ExitCodeError();
}
$Self->Print("<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
1;

View File

@@ -0,0 +1,103 @@
# --
# 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::Console::Command::Admin::Group::UserLink;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Group',
'Kernel::System::User',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Connect a user to a group.');
$Self->AddOption(
Name => 'user-name',
Description => 'Name of the user who should be linked to the given group.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'group-name',
Description => 'Name of the group the given user should be linked to.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddOption(
Name => 'permission',
Description =>
'Permissions (ro|move_into|create|owner|priority|rw) the given user should have for the group he is going to be linked to.',
Required => 1,
HasValue => 1,
ValueRegex => qr/(ro|move_into|create|owner|priority|rw)/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
$Self->{UserName} = $Self->GetOption('user-name');
$Self->{GroupName} = $Self->GetOption('group-name');
# check user
$Self->{UserID} = $Kernel::OM->Get('Kernel::System::User')->UserLookup( UserLogin => $Self->{UserName} );
if ( !$Self->{UserID} ) {
die "User $Self->{UserName} does not exist.\n";
}
# check group
$Self->{GroupID} = $Kernel::OM->Get('Kernel::System::Group')->GroupLookup( Group => $Self->{GroupName} );
if ( !$Self->{GroupID} ) {
die "Group $Self->{GroupName} does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Trying to link user $Self->{UserName} to group $Self->{GroupName}...</yellow>\n");
my %Permissions;
for my $Permission (qw(ro move_into create owner priority rw)) {
$Permissions{$Permission} = ( $Self->GetOption('permission') eq $Permission ) ? 1 : 0;
}
# add user 2 group
if (
!$Kernel::OM->Get('Kernel::System::Group')->PermissionGroupUserAdd(
UID => $Self->{UserID},
GID => $Self->{GroupID},
Active => 1,
UserID => 1,
Permission => {
%Permissions,
},
)
)
{
$Self->PrintError("Can't add user to group.");
return $Self->ExitCodeError();
}
$Self->Print("<green>Done</green>.\n");
return $Self->ExitCodeOk();
}
1;