Revision f5093da0
Von Moritz Bunkus vor etwa 11 Jahren hinzugefügt
SL/Controller/LoginScreen.pm | ||
---|---|---|
111 | 111 |
sub _redirect_to_main_script { |
112 | 112 |
my ($self) = @_; |
113 | 113 |
|
114 |
$self->_ensure_employees_for_authorized_users_exist; |
|
115 |
|
|
116 | 114 |
return $self->redirect_to($::form->{callback}) if $::form->{callback}; |
117 | 115 |
|
118 | 116 |
$self->redirect_to(controller => "login.pl", action => 'company_logo'); |
... | ... | |
153 | 151 |
return 1; |
154 | 152 |
} |
155 | 153 |
|
156 |
sub _ensure_employees_for_authorized_users_exist { |
|
157 |
my ($self) = @_; |
|
158 |
|
|
159 |
my %employees_by_login = map { ($_->login => $_) } @{ SL::DB::Manager::Employee->get_all }; |
|
160 |
|
|
161 |
foreach my $user (@{ SL::DB::AuthClient->new(id => $::auth->client->{id})->load->users || [] }) { |
|
162 |
my $user_config = $user->config_values; |
|
163 |
my $employee = $employees_by_login{$user->login} || SL::DB::Employee->new(login => $user->login); |
|
164 |
|
|
165 |
$employee->update_attributes( |
|
166 |
name => $user_config->{name}, |
|
167 |
workphone => $user_config->{tel}, |
|
168 |
deleted => 0, |
|
169 |
); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 | 154 |
sub error_state { |
174 | 155 |
my %states = ( |
175 | 156 |
session => { warning => t8('The session has expired. Please log in again.') }, |
SL/DB/Manager/Employee.pm | ||
---|---|---|
14 | 14 |
return shift->find_by(login => $::form->{login}); |
15 | 15 |
} |
16 | 16 |
|
17 |
sub update_entries_for_authorized_users { |
|
18 |
my ($class) = @_; |
|
19 |
|
|
20 |
my %employees_by_login = map { ($_->login => $_) } @{ $class->get_all }; |
|
21 |
|
|
22 |
require SL::DB::AuthClient; |
|
23 |
foreach my $user (@{ SL::DB::AuthClient->new(id => $::auth->client->{id})->load->users || [] }) { |
|
24 |
my $user_config = $user->config_values; |
|
25 |
my $employee = $employees_by_login{$user->login} || SL::DB::Employee->new(login => $user->login); |
|
26 |
|
|
27 |
$employee->update_attributes( |
|
28 |
name => $user_config->{name}, |
|
29 |
workphone => $user_config->{tel}, |
|
30 |
deleted => 0, |
|
31 |
); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
17 | 35 |
1; |
36 |
__END__ |
|
37 |
|
|
38 |
=pod |
|
39 |
|
|
40 |
=encoding utf8 |
|
41 |
|
|
42 |
=head1 NAME |
|
43 |
|
|
44 |
SL::DB::Manager::Employee - RDBO manager for the C<employee> table |
|
45 |
|
|
46 |
=head1 SYNOPSIS |
|
47 |
|
|
48 |
my $logged_in_employee = SL::DB::Manager::Employee->current; |
|
49 |
|
|
50 |
=head1 FUNCTIONS |
|
51 |
|
|
52 |
=over 4 |
|
53 |
|
|
54 |
=item C<current> |
|
55 |
|
|
56 |
Returns an RDBO instance corresponding to the currently logged-in user. |
|
57 |
|
|
58 |
=item C<update_entries_for_authorized_users> |
|
59 |
|
|
60 |
For each user created by the administrator in the admin section an |
|
61 |
entry only exists in the authentication table, but not in the employee |
|
62 |
table. This is where this function comes in: It iterates over all |
|
63 |
authentication users that have access to the current client and ensure |
|
64 |
than an entry for them exists in the table C<employee>. The matching |
|
65 |
is done via the login name which must be the same in both tables. |
|
66 |
|
|
67 |
The only other properties that will be copied from the authentication |
|
68 |
table into the C<employee> row are C<name> and C<workphone>. In |
|
69 |
addition C<deleted> is always set to 0. |
|
70 |
|
|
71 |
The intention is that this function is called automatically during the |
|
72 |
login process. |
|
73 |
|
|
74 |
=back |
|
75 |
|
|
76 |
=head1 BUGS |
|
77 |
|
|
78 |
Nothing here yet. |
|
79 |
|
|
80 |
=head1 AUTHOR |
|
81 |
|
|
82 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt> |
|
83 |
|
|
84 |
=cut |
SL/User.pm | ||
---|---|---|
39 | 39 |
|
40 | 40 |
#use SL::Auth; |
41 | 41 |
use SL::DB::AuthClient; |
42 |
use SL::DB::Employee; |
|
42 | 43 |
use SL::DBConnect; |
43 | 44 |
use SL::DBUpgrade2; |
44 | 45 |
use SL::DBUtils; |
... | ... | |
126 | 127 |
my $update_available = $dbupdater->update2_available($dbh); |
127 | 128 |
$dbh->disconnect; |
128 | 129 |
|
129 |
return LOGIN_OK() if !$update_available; |
|
130 |
if (!$update_available) { |
|
131 |
SL::DB::Manager::Employee->update_entries_for_authorized_users; |
|
132 |
return LOGIN_OK(); |
|
133 |
} |
|
130 | 134 |
|
131 | 135 |
$form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd); |
132 | 136 |
$form->{$_} = $myconfig{$_} for qw(datestyle); |
... | ... | |
151 | 155 |
|
152 | 156 |
$self->dbupdate2(form => $form, updater => $dbupdater, database => $::auth->client->{dbname}); |
153 | 157 |
|
158 |
# If $self->dbupdate2 returns than this means all upgrade scripts |
|
159 |
# have been applied successfully, none required user |
|
160 |
# interaction. Otherwise the deeper layers would have called |
|
161 |
# ::end_of_request() already, and return would not have returned to |
|
162 |
# us. Therefore we can now use RDBO instances because their supposed |
|
163 |
# table structures do match the actual structures. So let's ensure |
|
164 |
# that the "employee" table contains the appropriate entries for all |
|
165 |
# users authorized for the current client. |
|
166 |
SL::DB::Manager::Employee->update_entries_for_authorized_users; |
|
167 |
|
|
154 | 168 |
SL::System::InstallationLock->unlock; |
155 | 169 |
|
156 | 170 |
print $form->parse_html_template("dbupgrade/footer"); |
Auch abrufbar als: Unified diff
Einträge in employee aus User->login heraus aktualisieren
Vor der Mandanteneinführung war User->login bereits hierfür
verantwortlich. Dann wurde diese Funktionalität in den
Login-Controller verschoben. Allerdings kehrt die Ausführung in exakt
einem Fall nicht zum Logincontroller zurück: wenn noch
Datenbankupgrades eingespielt werden müssen.
In dem Fall werden die Updates eingespielt, dem User wird die
"Weiter"-Seite angezeigt, und von hier aus geht es direkt zum
company_logo.
User->login weiß daher als einzige Instanz, wann alle DB-Upgrades
User->installiert sind, und damit, wann RDBO-Instanzen sicher genutzt
User->werden können.
Daher die Funktionalität in die Employee-Manager-Klasse verschoben und
das Triggern der Funktion aus dem Login-Controller wieder zurück nach
User->login verschoben.
Fixt #2361.