X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4a3959958abe815dc130e2e4e554c26e331475bd..d8be5cc409de5b3bc34439599b1481201a5a1c2e:/SL/Controller/Admin.pm diff --git a/SL/Controller/Admin.pm b/SL/Controller/Admin.pm index 5323632a5..082b94ff8 100644 --- a/SL/Controller/Admin.pm +++ b/SL/Controller/Admin.pm @@ -31,7 +31,7 @@ __PACKAGE__->run_before(\&setup_layout); __PACKAGE__->run_before(\&setup_client, only => [ qw(list_printers new_printer edit_printer save_printer delete_printer) ]); sub get_auth_level { "admin" }; -sub keep_auth_vars { +sub keep_auth_vars_in_form { my ($class, %params) = @_; return $params{action} eq 'login'; } @@ -84,10 +84,9 @@ sub action_create_auth_tables { $::auth->set_session_value('admin_password', $::lx_office_conf{authentication}->{admin_password}); $::auth->create_or_refresh_session; - return if $self->apply_dbupgrade_scripts; + my $scripts_applied = $self->apply_dbupgrade_scripts; - my $group = (SL::DB::Manager::AuthGroup->get_all(limit => 1))[0]; - if (!$group) { + if (! SL::DB::Manager::AuthGroup->get_all_count) { SL::DB::AuthGroup->new( name => t8('Full Access'), description => t8('Full access to all functions'), @@ -95,7 +94,7 @@ sub action_create_auth_tables { )->save; } - $self->action_login; + $self->action_login unless $scripts_applied; } # @@ -120,7 +119,7 @@ sub action_new_user { countrycode => $defaults->language('de'), numberformat => $defaults->numberformat('1.000,00'), dateformat => $defaults->dateformat('dd.mm.yy'), - stylesheet => "kivitendo.css", + stylesheet => "design40.css", menustyle => "neu", }, )); @@ -138,6 +137,8 @@ sub action_save_user { my $params = delete($::form->{user}) || { }; my $props = delete($params->{config_values}) || { }; my $is_new = !$params->{id}; + my $check_previously_used = delete($::form->{check_previously_used}) || 0; + my $assign_documents = delete($::form->{assign_documents}) || 0; # Assign empty arrays if the browser doesn't send those controls. $params->{clients} ||= []; @@ -150,9 +151,29 @@ sub action_save_user { my @errors = $self->user->validate; if (@errors) { - flash('error', @errors); - $self->edit_user_form(title => $is_new ? t8('Create a new user') : t8('Edit User')); - return; + $self->js->flash('error', $_) foreach @errors; + return $self->js->render(); + } + + # check if given login name was previously used and show a dialog if so + if ($is_new && $check_previously_used && $self->check_loginname_previously_used()) { + $self->js->run('show_loginname_previously_used_dialog'); + return $self->js->render(); + } + + # rename previous usernames in employee table, if not set to assign + if ($is_new && !$assign_documents) { + my $clients = SL::DB::Manager::AuthClient->get_all_sorted; + for my $client (@$clients) { + my $now = DateTime->now_local; + my $timestamp = $now->format_cldr('yyyyMMddHHmmss'); + + my $dbh = $client->dbconnect(AutoCommit => 1); + next if !$dbh; + $dbh->do(qq|UPDATE employee SET login = ? WHERE login = ?;|,undef, + $params->{'login'} . $timestamp, $params->{'login'}); + $dbh->disconnect; + } } $self->user->save; @@ -506,7 +527,7 @@ sub init_all_groups { SL::DB::Manager::AuthGroup ->get_all_sorted sub init_all_printers { SL::DB::Manager::Printer ->get_all_sorted } sub init_all_dateformats { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ] } sub init_all_numberformats { [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ] } -sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ] } +sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css design40.css) ] } sub init_all_dbsources { [ sort User->dbsources($::form) ] } sub init_all_used_dbsources { { map { (join(':', $_->dbhost || 'localhost', $_->dbport || 5432, $_->dbname) => $_->name) } @{ $_[0]->all_clients } } } sub init_all_accounting_methods { [ { id => 'accrual', name => t8('Accrual accounting') }, { id => 'cash', name => t8('Cash accounting') } ] } @@ -597,7 +618,7 @@ sub login_form { my ($self, %params) = @_; $::request->layout(SL::Layout::AdminLogin->new); my $version = SL::Version->get_version; - $self->render('admin/adminlogin', title => t8('kivitendo v#1 administration', $version), %params, version => $version, logo_url => $::form->read_logo ); + $self->render('admin/adminlogin', title => t8('kivitendo v#1 administration', $version), %params, version => $version ); } sub edit_user_form { @@ -756,4 +777,22 @@ sub check_database_superuser_privileges { return (%result, error => $::locale->text('The database user \'#1\' does not have superuser privileges.', $result{username})); } +sub check_loginname_previously_used() { + my ($self) = @_; + + my $clients = SL::DB::Manager::AuthClient->get_all_sorted; + for my $client (@$clients) { + my $dbh = $client->dbconnect(); + next if !$dbh; + my ($result) = $dbh->selectrow_array(qq|SELECT login FROM employee WHERE login = ?;|,undef, + $self->user->{'login'}); + $dbh->disconnect; + + if ($result) { + return 1; + } + } + return 0; +} + 1;