Revision 49be66cd
Von Jan Büren vor fast 11 Jahren hinzugefügt
SL/Controller/Admin.pm | ||
---|---|---|
172 | 172 |
|
173 | 173 |
my @clients = @{ $self->user->clients || [] }; |
174 | 174 |
|
175 |
# backup user metadata (email, name, etc) |
|
176 |
my $user_config_values_ref = $self->user->config_values(); |
|
177 |
my $login =$self->user->login; |
|
178 |
|
|
175 | 179 |
if (!$self->user->delete) { |
176 | 180 |
flash('error', t8('The user could not be deleted.')); |
177 | 181 |
$self->edit_user_form(title => t8('Edit User')); |
... | ... | |
179 | 183 |
} |
180 | 184 |
|
181 | 185 |
# Flag corresponding entries in 'employee' as deleted. |
186 |
# and restore the most important user data in employee |
|
187 |
# TODO try and catch the whole transaction {user->delete; update employee} {exception} |
|
182 | 188 |
foreach my $client (@clients) { |
183 | 189 |
my $dbh = $client->dbconnect(AutoCommit => 1) || next; |
184 |
$dbh->do(qq|UPDATE employee SET deleted = TRUE WHERE login = ?|, undef, $self->user->login); |
|
190 |
$dbh->do(qq|UPDATE employee SET deleted = TRUE, name = ?, deleted_email = ?, |
|
191 |
deleted_tel = ?, deleted_fax = ?, deleted_signature = ? WHERE login = ?|,undef, |
|
192 |
$user_config_values_ref->{name}, $user_config_values_ref->{email}, |
|
193 |
$user_config_values_ref->{tel}, $user_config_values_ref->{fax}, |
|
194 |
$user_config_values_ref->{signature}, $self->user->login); |
|
185 | 195 |
$dbh->disconnect; |
186 | 196 |
} |
187 | 197 |
|
SL/DB/Manager/Employee.pm | ||
---|---|---|
26 | 26 |
|
27 | 27 |
$employee->update_attributes( |
28 | 28 |
name => $user_config->{name}, |
29 |
workphone => $user_config->{tel}, |
|
30 | 29 |
deleted => 0, |
31 | 30 |
); |
32 | 31 |
} |
SL/DB/MetaSetup/Employee.pm | ||
---|---|---|
9 | 9 |
__PACKAGE__->meta->table('employee'); |
10 | 10 |
|
11 | 11 |
__PACKAGE__->meta->columns( |
12 |
addr1 => { type => 'text' }, |
|
13 |
addr2 => { type => 'text' }, |
|
14 |
addr3 => { type => 'text' }, |
|
15 |
addr4 => { type => 'text' }, |
|
16 |
deleted => { type => 'boolean', default => 'false' }, |
|
17 |
enddate => { type => 'date' }, |
|
18 |
homephone => { type => 'text' }, |
|
19 |
id => { type => 'integer', not_null => 1, sequence => 'id' }, |
|
20 |
itime => { type => 'timestamp', default => 'now()' }, |
|
21 |
login => { type => 'text' }, |
|
22 |
mtime => { type => 'timestamp' }, |
|
23 |
name => { type => 'text' }, |
|
24 |
notes => { type => 'text' }, |
|
25 |
sales => { type => 'boolean', default => 'true' }, |
|
26 |
startdate => { type => 'date', default => 'now' }, |
|
27 |
workphone => { type => 'text' }, |
|
12 |
deleted => { type => 'boolean', default => 'false' }, |
|
13 |
deleted_email => { type => 'text' }, |
|
14 |
deleted_fax => { type => 'text' }, |
|
15 |
deleted_signature => { type => 'text' }, |
|
16 |
deleted_tel => { type => 'text' }, |
|
17 |
enddate => { type => 'date' }, |
|
18 |
id => { type => 'integer', not_null => 1, sequence => 'id' }, |
|
19 |
itime => { type => 'timestamp', default => 'now()' }, |
|
20 |
login => { type => 'text' }, |
|
21 |
mtime => { type => 'timestamp' }, |
|
22 |
name => { type => 'text' }, |
|
23 |
sales => { type => 'boolean', default => 'true' }, |
|
24 |
startdate => { type => 'date', default => 'now' }, |
|
28 | 25 |
); |
29 | 26 |
|
30 | 27 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
SL/Form.pm | ||
---|---|---|
1926 | 1926 |
my $myconfig = \%main::myconfig; |
1927 | 1927 |
my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig); |
1928 | 1928 |
|
1929 |
my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
|
|
1929 |
my ($login, $deleted) = selectrow_query($self, $dbh, qq|SELECT login,deleted FROM employee WHERE id = ?|, conv_i($params{id}));
|
|
1930 | 1930 |
|
1931 | 1931 |
if ($login) { |
1932 |
my $user = User->new(login => $login); |
|
1933 |
$self->{$params{prefix} . "_${_}"} = $user->{$_} for qw(email fax name signature tel); |
|
1934 |
$self->{$params{prefix} . "_${_}"} = $defaults->$_ for qw(address businessnumber co_ustid company duns taxnumber); |
|
1935 |
|
|
1932 |
# login already fetched and still the same client (mandant) | same for both cases (delete|!delete) |
|
1936 | 1933 |
$self->{$params{prefix} . '_login'} = $login; |
1937 |
$self->{$params{prefix} . '_name'} ||= $login; |
|
1938 |
} |
|
1934 |
$self->{$params{prefix} . "_${_}"} = $defaults->$_ for qw(address businessnumber co_ustid company duns taxnumber); |
|
1939 | 1935 |
|
1936 |
if (!$deleted) { |
|
1937 |
# get employee data from auth.user_config |
|
1938 |
my $user = User->new(login => $login); |
|
1939 |
$self->{$params{prefix} . "_${_}"} = $user->{$_} for qw(email fax name signature tel); |
|
1940 |
} else { |
|
1941 |
# get saved employee data from employee |
|
1942 |
my $employee = SL::DB::Manager::Employee->find_by(id => conv_i($params{id})); |
|
1943 |
$self->{$params{prefix} . "_${_}"} = $employee->{"deleted_$_"} for qw(email fax signature tel); |
|
1944 |
$self->{$params{prefix} . "_name"} = $employee->name; |
|
1945 |
} |
|
1946 |
} |
|
1940 | 1947 |
$main::lxdebug->leave_sub(); |
1941 | 1948 |
} |
1942 | 1949 |
|
sql/Pg-upgrade2/employee_drop_columns.sql | ||
---|---|---|
1 |
-- @tag: employee_drop_columns |
|
2 |
-- @description: Obsolete Felder in employee entfernt und Datenfelder zum Speichern für die Historie der Mitarbeiter (nach Löschen eines Benutzer) hinzugefügt. Aktuell alle Felder die der Benutzer unter persönliche Einstellungen ändern kann |
|
3 |
-- @depends: release_3_0_0 |
|
4 |
-- @ignore: 0 |
|
5 |
-- @charset: utf-8 |
|
6 |
ALTER TABLE employee DROP COLUMN addr1; |
|
7 |
ALTER TABLE employee DROP COLUMN addr2; |
|
8 |
ALTER TABLE employee DROP COLUMN addr3; |
|
9 |
ALTER TABLE employee DROP COLUMN addr4; |
|
10 |
ALTER TABLE employee DROP COLUMN homephone; |
|
11 |
ALTER TABLE employee DROP COLUMN workphone; |
|
12 |
ALTER TABLE employee DROP COLUMN notes; |
|
13 |
ALTER TABLE employee ADD COLUMN deleted_email text; |
|
14 |
ALTER TABLE employee ADD COLUMN deleted_signature text; |
|
15 |
ALTER TABLE employee ADD COLUMN deleted_tel text; |
|
16 |
ALTER TABLE employee ADD COLUMN deleted_fax text; |
Auch abrufbar als: Unified diff
Bugfix für 2275 Verkäuferinformationen im Druck kommen aus der Authdatenbank
closes #2275
Hat leider einen kleinen "Rattenschwanz":
a) Beim Löschen des Benutzer wird nur deleted auf true gesetzt, jetzt werden auch
alle weiteren benutzereditierbaren Metadaten gespeichert, dafür ->
b) muss die Tabelle employee geändert werden, dabei ->
c) ist aufgefallen, dass einige Felder in employee überhaupt keinen Sinn mehr haben (addr1), aber dann ...
d) braucht man auch nicht mehr workphone mit tel aus der auth.user_config
zu d) -> SL/DB/Manager/Employee.pm
zu b) und c) -> sql/Pg-upgrade2/employee_drop_columns.sql und SL/DB/MetaSetup/Employee.pm
zu a) SL/Controller/Admin.pm
Jetzt können beim Drucken entweder die Daten des Benutzers genommen werden oder die Daten kommen aus employee (Form.pm)