X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/9636227ee0ce9cb050db33573e523d68764ebde8..66c08b6472a2467444192dbfed35e9f30f7c910d:/SL/Controller/Admin.pm diff --git a/SL/Controller/Admin.pm b/SL/Controller/Admin.pm index 0eee2a0e6..c1b2ec1e8 100644 --- a/SL/Controller/Admin.pm +++ b/SL/Controller/Admin.pm @@ -5,19 +5,24 @@ use strict; use parent qw(SL::Controller::Base); use IO::File; +use List::Util qw(first); use SL::DB::AuthUser; use SL::DB::AuthGroup; +use SL::DB::Printer; use SL::Helper::Flash; use SL::Locale::String qw(t8); +use SL::System::InstallationLock; use SL::User; use Rose::Object::MakeMethods::Generic ( - '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 all_users) ], + 'scalar --get_set_init' => [ qw(client user group printer db_cfg is_locked + all_dateformats all_numberformats all_countrycodes all_stylesheets all_menustyles all_clients all_groups all_users all_rights all_printers) ], ); __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 { @@ -95,10 +100,7 @@ sub action_show { $self->render( "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 " . t8('Administration'), + title => "kivitendo " . t8('Administration'), ); } @@ -242,13 +244,120 @@ sub action_test_database_connectivity { error => $error); } +# +# actions: groups +# + +sub action_new_group { + my ($self) = @_; + + $self->group(SL::DB::AuthGroup->new); + $self->edit_group_form(title => t8('Create a new group')); +} + +sub action_edit_group { + my ($self) = @_; + $self->edit_group_form(title => t8('Edit User Group')); +} + +sub action_save_group { + my ($self) = @_; + + my $params = delete($::form->{group}) || { }; + my $is_new = !$params->{id}; + + $self->group($is_new ? SL::DB::AuthGroup->new : SL::DB::AuthGroup->new(id => $params->{id})->load)->assign_attributes(%{ $params }); + + my @errors = $self->group->validate; + + if (@errors) { + flash('error', @errors); + $self->edit_group_form(title => $is_new ? t8('Create a new user group') : t8('Edit User Group')); + return; + } + + $self->group->save; + + flash_later('info', $is_new ? t8('The user group has been created.') : t8('The user group has been saved.')); + $self->redirect_to(action => 'show'); +} + +sub action_delete_group { + my ($self) = @_; + + if (!$self->group->delete) { + flash('error', t8('The user group could not be deleted.')); + $self->edit_group_form(title => t8('Edit User Group')); + return; + } + + flash_later('info', t8('The user group has been deleted.')); + $self->redirect_to(action => 'show'); +} + +# +# actions: printers +# + +sub action_list_printers { + my ($self) = @_; + $self->render('admin/list_printers', title => t8('Printer management')); +} + +sub action_new_printer { + my ($self) = @_; + + $self->printer(SL::DB::Printer->new); + $self->edit_printer_form(title => t8('Create a new printer')); +} + +sub action_edit_printer { + my ($self) = @_; + $self->edit_printer_form(title => t8('Edit Printer')); +} + +sub action_save_printer { + my ($self) = @_; + my $params = delete($::form->{printer}) || { }; + my $is_new = !$params->{id}; + + $self->printer($is_new ? SL::DB::Printer->new : SL::DB::Printer->new(id => $params->{id})->load)->assign_attributes(%{ $params }); + + my @errors = $self->printer->validate; + + if (@errors) { + flash('error', @errors); + $self->edit_printer_form(title => $is_new ? t8('Create a new printer') : t8('Edit Printer')); + return; + } + + $self->printer->save; + + flash_later('info', $is_new ? t8('The printer has been created.') : t8('The printer has been saved.')); + $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id); +} + +sub action_delete_printer { + my ($self) = @_; + + if (!$self->printer->delete) { + flash('error', t8('The printer could not be deleted.')); + $self->edit_printer_form(title => t8('Edit Printer')); + return; + } + + flash_later('info', t8('The printer has been deleted.')); + $self->redirect_to(action => 'list_printers', 'client.id' => $self->client->id); +} + # # actions: locking, unlocking # sub action_unlock_system { my ($self) = @_; - unlink $self->nologin_file_name; + + SL::System::InstallationLock->unlock; flash_later('info', t8('Lockfile removed!')); $self->redirect_to(action => 'show'); } @@ -256,31 +365,28 @@ sub action_unlock_system { sub action_lock_system { my ($self) = @_; - my $fh = IO::File->new($self->nologin_file_name, "w"); - if (!$fh) { - $::form->error(t8('Cannot create Lock!')); - - } else { - $fh->close; - flash_later('info', t8('Lockfile created!')); - $self->redirect_to(action => 'show'); - } + SL::System::InstallationLock->unlock; + flash_later('info', t8('Lockfile created!')); + $self->redirect_to(action => 'show'); } # # 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->{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_users { SL::DB::Manager::AuthUser->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_db_cfg { $::lx_office_conf{'authentication/database'} } +sub init_is_locked { SL::System::InstallationLock->is_locked } +sub init_client { SL::DB::Manager::AuthClient->find_by(id => ($::form->{id} || ($::form->{client} || {})->{id})) } +sub init_user { SL::DB::AuthUser ->new(id => ($::form->{id} || ($::form->{user} || {})->{id}))->load } +sub init_group { SL::DB::AuthGroup ->new(id => ($::form->{id} || ($::form->{group} || {})->{id}))->load } +sub init_printer { SL::DB::Printer ->new(id => ($::form->{id} || ($::form->{printer} || {})->{id}))->load } +sub init_all_clients { SL::DB::Manager::AuthClient->get_all_sorted } +sub init_all_users { SL::DB::Manager::AuthUser ->get_all_sorted } +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 { [ 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)') }, @@ -289,6 +395,27 @@ sub init_all_menustyles { ]; } +sub init_all_rights { + my (@sections, $current_section); + + foreach my $entry ($::auth->all_rights_full) { + if ($entry->[0] =~ m/^--/) { + push @sections, { description => $entry->[1], rights => [] }; + + } elsif (@sections) { + push @{ $sections[-1]->{rights} }, { + name => $entry->[0], + description => $entry->[1], + }; + + } else { + die "Right without sections: " . join('::', @{ $entry }); + } + } + + return \@sections; +} + sub init_all_countrycodes { my %cc = User->country_codes; return [ map { id => $_, title => $cc{$_} }, sort { $cc{$a} cmp $cc{$b} } keys %cc ]; @@ -306,10 +433,25 @@ sub setup_layout { $::form->{favicon} = "favicon.ico"; } +sub setup_client { + my ($self) = @_; + + $self->client((first { $_->is_default } @{ $self->all_clients }) || $self->all_clients->[0]) if !$self->client; + $::auth->set_client($self->client->id); +} + + # # displaying forms # +sub use_multiselect_js { + my ($self) = @_; + + $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side); + return $self; +} + sub login_form { my ($self, %params) = @_; $::request->layout->focus('#admin_password'); @@ -318,16 +460,22 @@ sub login_form { sub edit_user_form { my ($self, %params) = @_; - - $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side); - $self->render('admin/edit_user', %params); + $self->use_multiselect_js->render('admin/edit_user', %params); } sub edit_client_form { my ($self, %params) = @_; + $self->use_multiselect_js->render('admin/edit_client', %params); +} - $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side); - $self->render('admin/edit_client', %params); +sub edit_group_form { + my ($self, %params) = @_; + $self->use_multiselect_js->render('admin/edit_group', %params); +} + +sub edit_printer_form { + my ($self, %params) = @_; + $self->render('admin/edit_printer', %params); } # @@ -351,7 +499,7 @@ sub check_auth_db_and_tables { } sub apply_dbupgrade_scripts { - return SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(1); + return SL::DBUpgrade2->new(form => $::form, auth => 1)->apply_admin_dbupgrade_scripts(1); } sub authenticate_root { @@ -362,7 +510,7 @@ sub authenticate_root { $::auth->punish_wrong_login; $::auth->delete_session_value('admin_password'); - $self->login_form(error => t8('Incorrect Password!')); + $self->login_form(error => t8('Incorrect password!')); return undef; }