X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/32b79fa8495846e993a7130fc9271ca39e2e6c44..288111da982510d86d73db5cef54c52e07a84f5a:/SL/Controller/Admin.pm diff --git a/SL/Controller/Admin.pm b/SL/Controller/Admin.pm index 04d9c759b..d6e753a28 100644 --- a/SL/Controller/Admin.pm +++ b/SL/Controller/Admin.pm @@ -10,10 +10,11 @@ use SL::DB::AuthUser; use SL::DB::AuthGroup; use SL::Helper::Flash; use SL::Locale::String qw(t8); +use SL::User; use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(client user nologin_file_name db_cfg) ], + 'scalar --get_set_init' => [ qw(client user nologin_file_name db_cfg all_dateformats all_numberformats all_countrycodes all_stylesheets all_menustyles all_clients all_groups) ], ); __PACKAGE__->run_before(\&setup_layout); @@ -25,7 +26,7 @@ sub keep_auth_vars { } # -# actions +# actions: login, logout # sub action_login { @@ -35,7 +36,7 @@ sub action_login { return if !$self->authenticate_root; return if !$self->check_auth_db_and_tables; return if $self->apply_dbupgrade_scripts; - $self->redirect_to(action => 'list_clients_and_users'); + $self->redirect_to(action => 'show'); } sub action_logout { @@ -44,11 +45,15 @@ sub action_logout { $self->redirect_to(action => 'login'); } +# +# actions: creating the authentication database & tables, applying database ugprades +# + sub action_apply_dbupgrade_scripts { my ($self) = @_; return if $self->apply_dbupgrade_scripts; - $self->action_list_clients_and_users; + $self->action_show; } sub action_create_auth_db { @@ -81,23 +86,94 @@ sub action_create_auth_tables { } } -sub action_list_clients_and_users { +# +# actions: users +# + +sub action_show { my ($self) = @_; $self->render( - "admin/list_users", + "admin/show", CLIENTS => SL::DB::Manager::AuthClient->get_all_sorted, USERS => SL::DB::Manager::AuthUser->get_all_sorted, LOCKED => (-e $self->nologin_file_name), - title => "kivitendo " . $::locale->text('Administration'), + title => "kivitendo " . t8('Administration'), ); } +sub action_new_user { + my ($self) = @_; + + $self->user(SL::DB::AuthUser->new( + config_values => { + vclimit => 200, + countrycode => "de", + numberformat => "1.000,00", + dateformat => "dd.mm.yy", + stylesheet => "kivitendo.css", + menustyle => "neu", + }, + )); + + $self->edit_user_form(title => t8('Create a new user')); +} + +sub action_edit_user { + my ($self) = @_; + $self->edit_user_form(title => t8('Edit User')); +} + +sub action_save_user { + my ($self) = @_; + my $params = delete($::form->{user}) || { }; + my $props = delete($params->{config_values}) || { }; + my $is_new = !$params->{id}; + + $self->user($is_new ? SL::DB::AuthUser->new : SL::DB::AuthUser->new(id => $params->{id})->load) + ->assign_attributes(%{ $params }) + ->config_values({ %{ $self->user->config_values }, %{ $props } }); + + 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->user->save; + + if ($::auth->can_change_password && $::form->{new_password}) { + $::auth->change_password($self->user->login, $::form->{new_password}); + } + + flash_later('info', $is_new ? t8('The user has been created.') : t8('The user has been saved.')); + $self->redirect_to(action => 'show'); +} + +sub action_delete_user { + my ($self) = @_; + + if (!$self->user->delete) { + flash('error', t8('The user could not be deleted.')); + $self->edit_user_form(title => t8('Edit User')); + return; + } + + flash_later('info', t8('The user has been deleted.')); + $self->redirect_to(action => 'show'); +} + +# +# actions: locking, unlocking +# + sub action_unlock_system { my ($self) = @_; unlink $self->nologin_file_name; flash_later('info', t8('Lockfile removed!')); - $self->redirect_to(action => 'list_clients_and_users'); + $self->redirect_to(action => 'show'); } sub action_lock_system { @@ -110,7 +186,7 @@ sub action_lock_system { } else { $fh->close; flash_later('info', t8('Lockfile created!')); - $self->redirect_to(action => 'list_clients_and_users'); + $self->redirect_to(action => 'show'); } } @@ -118,10 +194,27 @@ sub action_lock_system { # initializers # -sub init_db_cfg { $::lx_office_conf{'authentication/database'} } -sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin'; } -sub init_client { SL::DB::AuthClient->new(id => $::form->{client_id})->load; } -sub init_user { SL::DB::AuthUser ->new(id => $::form->{user_id} )->load; } +sub init_db_cfg { $::lx_office_conf{'authentication/database'} } +sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin'; } +sub init_client { SL::DB::AuthClient->new(id => ($::form->{id} || ($::form->{client} || {})->{id}))->load } +sub init_user { SL::DB::AuthUser ->new(id => ($::form->{id} || ($::form->{user} || {})->{id}))->load } +sub init_all_clients { SL::DB::Manager::AuthClient->get_all_sorted } +sub init_all_groups { SL::DB::Manager::AuthGroup->get_all_sorted } +sub init_all_dateformats { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ] } +sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00) ] } +sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ] } +sub init_all_menustyles { + return [ + { id => 'old', title => $::locale->text('Old (on the side)') }, + { id => 'v3', title => $::locale->text('Top (CSS)') }, + { id => 'neu', title => $::locale->text('Top (Javascript)') }, + ]; +} + +sub init_all_countrycodes { + my %cc = User->country_codes; + return [ map { id => $_, title => $cc{$_} }, sort { $cc{$a} cmp $cc{$b} } keys %cc ]; +} # # filters @@ -136,7 +229,7 @@ sub setup_layout { } # -# helpers +# displaying forms # sub login_form { @@ -145,6 +238,17 @@ sub login_form { $self->render('admin/adminlogin', title => t8('kivitendo v#1 administration', $::form->{version}), %params); } +sub edit_user_form { + my ($self, %params) = @_; + + $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side); + $self->render('admin/edit_user', %params); +} + +# +# helpers +# + sub check_auth_db_and_tables { my ($self) = @_;