Skip to content

Commit

Permalink
Issue #2385: add the option --add-user
Browse files Browse the repository at this point in the history
Add sample user 'toni' with full privileges for the group 'users'.
  • Loading branch information
bschmalhofer committed Jul 8, 2023
1 parent 5fcc45d commit 8c7f10a
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion bin/docker/quick_setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ =head1 SYNOPSIS
It might be convenient the call this script via an alias.
alias otobo_docker_quick_setup='docker exec -t otobo_web_1 bash -c "date ; hostname ; rm -f Kernel/Config/Files/ZZZAAuto.pm ; bin/docker/quick_setup.pl --db-password otobo_root --http-port 81 --activate-elasticsearch --add-admin-user --add-customer-user --add-calendar"'
alias otobo_docker_quick_setup='docker exec -t otobo_web_1 bash -c "date ; hostname ; rm -f Kernel/Config/Files/ZZZAAuto.pm ; bin/docker/quick_setup.pl --db-password otobo_root --http-port 81 --activate-elasticsearch --add-user --add-admin-user --add-customer-user --add-calendar"'
=head1 DESCRIPTION
Expand Down Expand Up @@ -118,6 +118,7 @@ sub Main {
my $DBPassword; # required
my $HTTPPort = 80; # only used for success message
my $ActivateElasticsearch = 0; # must be explicitly enabled
my $AddUser = 0; # must be explicitly enabled
my $AddAdminUser = 0; # must be explicitly enabled
my $AddCustomerUser = 0; # must be explicitly enabled
my $AddCalendar = 0; # must be explicitly enabled
Expand All @@ -127,6 +128,7 @@ sub Main {
'db-password=s' => \$DBPassword,
'http-port=i' => \$HTTPPort,
'activate-elasticsearch' => \$ActivateElasticsearch,
'add-user' => \$AddUser,
'add-admin-user' => \$AddAdminUser,
'add-customer-user' => \$AddCustomerUser,
'add-calendar' => \$AddCalendar,
Expand Down Expand Up @@ -265,6 +267,16 @@ sub Main {
return 0 unless $Success;
}

if ($AddUser) {
my ( $Success, $Message ) = AddUser(
HTTPPort => $HTTPPort
);

say $Message if defined $Message;

return 0 unless $Success;
}

if ($AddAdminUser) {
my ( $Success, $Message ) = AddAdminUser(
HTTPPort => $HTTPPort
Expand Down Expand Up @@ -698,6 +710,70 @@ sub ActivateElasticsearch {
return $SetupSuccess;
}

sub AddUser {
my %Param = @_;

# check the params
for my $Key ( grep { !$Param{$_} } qw(HTTPPort) ) {
my $SubName = subname(__SUB__);

return 0, "$SubName: the parameter '$Key' is required";
}

# Disable email checks to create new user.
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
local $ConfigObject->{CheckEmailAddresses} = 0;

# create an user
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
my $Login = 'toni';
my $UserID = $UserObject->UserAdd(
UserFirstname => 'Toni',
UserLastname => 'Tester',
UserLogin => $Login,
UserPw => $Login,
UserEmail => '[email protected]',
UserComment => 'sample user created by quick_setup.pl',
UserLanguage => 'en',
UserTimeZone => 'Europe/Berlin',
UserMobile => '1①๑໑༡༪၁',
ValidID => 1,
ChangeUserID => 1,
);

return 0, "Could not create the user '$Login'" unless $UserID;

# do we have an admin group ?
my $GroupObject = $Kernel::OM->Get('Kernel::System::Group');
for my $Group (qw(users)) {
my $GroupID = $GroupObject->GroupLookup(
Group => $Group,
);

return 0, "Could not find the group '$Group'" unless $GroupID;

# now set the permissions
my $Success = $GroupObject->PermissionGroupUserAdd(
GID => $GroupID,
UID => $UserID,
Permission => {
ro => 1,
move_into => 1,
create => 1,
owner => 1,
priority => 1,
rw => 1,
},
UserID => 1,
);

return 0, "Could not give $Group privileges to the user '$Login'" unless $Success;
}

# looks good
return 1, "Sample user: http://localhost:$Param{HTTPPort}/otobo/index.pl user: $Login pw: $Login";
}

sub AddAdminUser {
my %Param = @_;

Expand Down

0 comments on commit 8c7f10a

Please sign in to comment.