Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2385 quick setup #2386

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 81 additions & 16 deletions 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 All @@ -721,27 +797,16 @@ sub AddAdminUser {
UserLogin => $Login,
UserPw => $Login,
UserEmail => '[email protected]',
UserComment => 'created by quick_setup.pl',
UserComment => 'admin user created by quick_setup.pl',
UserLanguage => 'en',
UserTimeZone => 'Europe/Berlin',
UserMobile => '2②२২৵੨૨',
ValidID => 1,
ChangeUserID => 1,
);

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

# Set user language to English, don't bother to check success
$UserObject->SetPreferences(
UserID => $UserID,
Key => 'UserLanguage',
Value => 'en',
);

# Set user time zone, don't bother to check success
$UserObject->SetPreferences(
UserID => $UserID,
Key => 'UserTimeZone',
Value => 'Europe/Berlin', # or to 'Antarctica/Rothera' ???
);

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