From 6f398b352e3b28af6b00852da08193727f803aee Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 13 Jun 2013 16:05:22 +0200 Subject: [PATCH] =?utf8?q?Mandantennamen=20in=20allen=20Men=C3=BC-Headern?= =?utf8?q?=20anzeigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AM.pm | 35 +++++++++---------------- SL/DB/AuthUser.pm | 3 +++ SL/User.pm | 67 ----------------------------------------------- bin/mozilla/am.pl | 6 +---- 4 files changed, 16 insertions(+), 95 deletions(-) diff --git a/SL/AM.pm b/SL/AM.pm index 5a9f2365b..1805dac15 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -42,6 +42,8 @@ use Data::Dumper; use Encode; use List::MoreUtils qw(any); use SL::DBUtils; +use SL::DB::AuthUser; +use SL::DB::Employee; use strict; @@ -1120,37 +1122,24 @@ sub save_defaults { $main::lxdebug->leave_sub(); } - sub save_preferences { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form) = @_; - - my $dbh = $form->get_standard_dbh($myconfig); - - my ($businessnumber) = selectrow_query($form, $dbh, qq|SELECT businessnumber FROM defaults|); - - # update name - my $query = qq|UPDATE employee SET name = ? WHERE login = ?|; - do_query($form, $dbh, $query, $form->{name}, $form->{login}); - - my $rc = $dbh->commit(); + my ($self, $form) = @_; - $form->{businessnumber} = $businessnumber; + my $employee = SL::DB::Manager::Employee->find_by(login => $form->{login}); + $employee->update_attributes(name => $form->{name}); - $myconfig = User->new(login => $form->{login}); - - foreach my $item (keys %$form) { - $myconfig->{$item} = $form->{$item}; - } - - $myconfig->save_member; - - my $auth = $main::auth; + my $user = SL::DB::Manager::AuthUser->find_by(login => $form->{login}); + $user->update_attributes( + config_values => { + map({ ($_ => $form->{$_}) } SL::DB::AuthUser::CONFIG_VARS()), + map({ ($_ => do { my $v = $form->{$_}; $v =~ s/\r//g; $v }) } qw(address signature)), + }); $main::lxdebug->leave_sub(); - return $rc; + return 1; } sub get_defaults { diff --git a/SL/DB/AuthUser.pm b/SL/DB/AuthUser.pm index 0b1942118..43d72f94e 100644 --- a/SL/DB/AuthUser.pm +++ b/SL/DB/AuthUser.pm @@ -10,6 +10,9 @@ use SL::DB::AuthClient; use SL::DB::AuthUserGroup; use SL::DB::Helper::Util; +use constant CONFIG_VARS => qw(copies countrycode dateformat default_media default_printer_id email favorites fax hide_cvar_search_options mandatory_departments menustyle name + numberformat show_form_details signature stylesheet taxincluded_checked tel template_format vclimit); + __PACKAGE__->meta->add_relationship( groups => { type => 'many to many', diff --git a/SL/User.pm b/SL/User.pm index 2159d9243..7f4ec1a56 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -105,8 +105,6 @@ sub login { # we got a connection, check the version my ($dbversion) = $dbh->selectrow_array(qq|SELECT version FROM defaults|); - $self->create_employee_entry($form, $dbh, \%myconfig); - $self->create_schema_info_table($form, $dbh); # Auth DB upgrades available? @@ -571,71 +569,6 @@ sub dbupdate2 { return $rc; } -sub save_member { - $main::lxdebug->enter_sub(); - - my ($self) = @_; - - # format dbconnect and dboptions string - dbconnect_vars($self, $self->{dbname}); - - map { $self->{$_} =~ s/\r//g; } qw(address signature); - - $main::auth->save_user($self->{login}, map { $_, $self->{$_} } config_vars()); - - my $dbh = SL::DBConnect->connect($self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd}, SL::DBConnect->get_options); - if ($dbh) { - $self->create_employee_entry($::form, $dbh, $self, 1); - $dbh->disconnect(); - } - - $main::lxdebug->leave_sub(); -} - -sub create_employee_entry { - $main::lxdebug->enter_sub(); - - my $self = shift; - my $form = shift; - my $dbh = shift; - my $myconfig = shift; - my $update_existing = shift; - - if (!does_table_exist($dbh, 'employee')) { - $main::lxdebug->leave_sub(); - return; - } - - # add login to employee table if it does not exist - # no error check for employee table, ignore if it does not exist - my ($id) = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $self->{login}); - my ($good_db) = selectrow_query($form, $dbh, qq|select * from pg_tables where tablename = ? and schemaname = ?|, 'schema_info', 'public'); - my $can_delete; - ($can_delete) = selectrow_query($form, $dbh, qq|SELECT tag FROM schema_info WHERE tag = ?|, 'employee_deleted') if $good_db; - - if (!$id) { - my $query = qq|INSERT INTO employee (login, name, workphone) VALUES (?, ?, ?)|; - do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel})); - - } elsif ($update_existing && $can_delete) { - my $query = qq|UPDATE employee SET name = ?, workphone = ?, deleted = 'f' WHERE id = ?|; - do_query($form, $dbh, $query, $myconfig->{name}, $myconfig->{tel}, $id); - } - - $main::lxdebug->leave_sub(); -} - -sub config_vars { - $main::lxdebug->enter_sub(); - - my @conf = qw(copies countrycode dateformat default_media default_printer_id email favorites fax hide_cvar_search_options mandatory_departments menustyle name - numberformat show_form_details signature stylesheet taxincluded_checked tel template_format vclimit); - - $main::lxdebug->leave_sub(); - - return @conf; -} - sub data { +{ %{ $_[0] } } } diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index e5be21ecc..567764494 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -1104,7 +1104,7 @@ sub save_preferences { TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } }); - if (AM->save_preferences(\%myconfig, $form)) { + if (AM->save_preferences($form)) { if ($::auth->can_change_password() && defined $form->{new_password} && ($form->{new_password} ne '********')) { @@ -1116,10 +1116,6 @@ sub save_preferences { } $::auth->change_password($form->{login}, $form->{new_password}); - - $form->{password} = $form->{new_password}; - $::auth->set_session_value('password', $form->{password}); - $::auth->create_or_refresh_session(); } $form->redirect($locale->text('Preferences saved!')); -- 2.20.1