-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2385: add the option --add-user
Add sample user 'toni' with full privileges for the group 'users'.
- Loading branch information
1 parent
5fcc45d
commit 8c7f10a
Showing
1 changed file
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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, | ||
|
@@ -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 | ||
|
@@ -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 = @_; | ||
|
||
|