diff --git a/lib/LedgerSMB/Entity/User.pm b/lib/LedgerSMB/Entity/User.pm index 75a9a9ecdf..3790933304 100644 --- a/lib/LedgerSMB/Entity/User.pm +++ b/lib/LedgerSMB/Entity/User.pm @@ -121,14 +121,14 @@ sub reset_password { return; } -=item create +=item create( $password, [ \%prefs ] ) Creates the new user. =cut sub create { - my ($self, $password) = @_; + my ($self, $password, $prefs) = @_; my ($ref) = $self->call_dbmethod( funcname => 'admin__save_user', args => { password => $password }); @@ -138,6 +138,18 @@ sub create { funcname => 'admin__add_user_to_role', args => [ $self->username, $role ]); } + $prefs //= {}; + my $query = <<~'SQL'; + insert into + user_preference (user_id, name, value) + values ($1, $2, $3) + SQL + my $sth = $self->dbh->prepare($query) + or die $self->dbh->errstr; + for my $pref (keys $prefs->%*) { + $sth->execute($self->id, $pref, $prefs->{$pref}) + or die $sth->errstr; + } return; } diff --git a/xt/lib/Pherkin/Extension/LedgerSMB.pm b/xt/lib/Pherkin/Extension/LedgerSMB.pm index 3645b82d62..e672526bd6 100644 --- a/xt/lib/Pherkin/Extension/LedgerSMB.pm +++ b/xt/lib/Pherkin/Extension/LedgerSMB.pm @@ -237,7 +237,7 @@ sub create_user { username => $username, _dbh => $dbh, ); - $user->create($args{password} // 'password'); + $user->create($args{password} // 'password', { language => 'en' }); my $ident_username=$dbh->quote_identifier($username); $dbh->do(qq(ALTER USER $ident_username VALID UNTIL 'infinity')); @@ -311,7 +311,7 @@ INSERT INTO business_unit (class_id, control_code, description) my $emp = $self->create_employee(dbh => $dbh); my $user = $self->create_user(dbh => $dbh, - entity_id => $emp->entity_id, + entity_id => $emp->entity_id, username => $admin); my $roles;