Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 288111da

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 288111da982510d86d73db5cef54c52e07a84f5a
  • Vorgänger 32b79fa8
  • Nachfolger 0038d2a7

Admin: Anlegen, Bearbeiten und Löschen von Usern im Admin-Controller

Dazu auch "ON DELETE CASCADE" für alle foreign keys in auth.*

Fixt #2279, #2280.

Unterschiede anzeigen:

SL/Controller/Admin.pm
10 10
use SL::DB::AuthGroup;
11 11
use SL::Helper::Flash;
12 12
use SL::Locale::String qw(t8);
13
use SL::User;
13 14

  
14 15
use Rose::Object::MakeMethods::Generic
15 16
(
16
  'scalar --get_set_init' => [ qw(client user nologin_file_name db_cfg) ],
17
  '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) ],
17 18
);
18 19

  
19 20
__PACKAGE__->run_before(\&setup_layout);
......
25 26
}
26 27

  
27 28
#
28
# actions
29
# actions: login, logout
29 30
#
30 31

  
31 32
sub action_login {
......
35 36
  return                   if !$self->authenticate_root;
36 37
  return                   if !$self->check_auth_db_and_tables;
37 38
  return                   if  $self->apply_dbupgrade_scripts;
38
  $self->redirect_to(action => 'list_clients_and_users');
39
  $self->redirect_to(action => 'show');
39 40
}
40 41

  
41 42
sub action_logout {
......
44 45
  $self->redirect_to(action => 'login');
45 46
}
46 47

  
48
#
49
# actions: creating the authentication database & tables, applying database ugprades
50
#
51

  
47 52
sub action_apply_dbupgrade_scripts {
48 53
  my ($self) = @_;
49 54

  
50 55
  return if $self->apply_dbupgrade_scripts;
51
  $self->action_list_clients_and_users;
56
  $self->action_show;
52 57
}
53 58

  
54 59
sub action_create_auth_db {
......
81 86
  }
82 87
}
83 88

  
84
sub action_list_clients_and_users {
89
#
90
# actions: users
91
#
92

  
93
sub action_show {
85 94
  my ($self) = @_;
86 95

  
87 96
  $self->render(
88
    "admin/list_users",
97
    "admin/show",
89 98
    CLIENTS => SL::DB::Manager::AuthClient->get_all_sorted,
90 99
    USERS   => SL::DB::Manager::AuthUser->get_all_sorted,
91 100
    LOCKED  => (-e $self->nologin_file_name),
92
    title   => "kivitendo " . $::locale->text('Administration'),
101
    title   => "kivitendo " . t8('Administration'),
93 102
  );
94 103
}
95 104

  
105
sub action_new_user {
106
  my ($self) = @_;
107

  
108
  $self->user(SL::DB::AuthUser->new(
109
    config_values => {
110
      vclimit      => 200,
111
      countrycode  => "de",
112
      numberformat => "1.000,00",
113
      dateformat   => "dd.mm.yy",
114
      stylesheet   => "kivitendo.css",
115
      menustyle    => "neu",
116
    },
117
  ));
118

  
119
  $self->edit_user_form(title => t8('Create a new user'));
120
}
121

  
122
sub action_edit_user {
123
  my ($self) = @_;
124
  $self->edit_user_form(title => t8('Edit User'));
125
}
126

  
127
sub action_save_user {
128
  my ($self) = @_;
129
  my $params = delete($::form->{user})          || { };
130
  my $props  = delete($params->{config_values}) || { };
131
  my $is_new = !$params->{id};
132

  
133
  $self->user($is_new ? SL::DB::AuthUser->new : SL::DB::AuthUser->new(id => $params->{id})->load)
134
    ->assign_attributes(%{ $params })
135
    ->config_values({ %{ $self->user->config_values }, %{ $props } });
136

  
137
  my @errors = $self->user->validate;
138

  
139
  if (@errors) {
140
    flash('error', @errors);
141
    $self->edit_user_form(title => $is_new ? t8('Create a new user') : t8('Edit User'));
142
    return;
143
  }
144

  
145
  $self->user->save;
146

  
147
  if ($::auth->can_change_password && $::form->{new_password}) {
148
    $::auth->change_password($self->user->login, $::form->{new_password});
149
  }
150

  
151
  flash_later('info', $is_new ? t8('The user has been created.') : t8('The user has been saved.'));
152
  $self->redirect_to(action => 'show');
153
}
154

  
155
sub action_delete_user {
156
  my ($self) = @_;
157

  
158
  if (!$self->user->delete) {
159
    flash('error', t8('The user could not be deleted.'));
160
    $self->edit_user_form(title => t8('Edit User'));
161
    return;
162
  }
163

  
164
  flash_later('info', t8('The user has been deleted.'));
165
  $self->redirect_to(action => 'show');
166
}
167

  
168
#
169
# actions: locking, unlocking
170
#
171

  
96 172
sub action_unlock_system {
97 173
  my ($self) = @_;
98 174
  unlink $self->nologin_file_name;
99 175
  flash_later('info', t8('Lockfile removed!'));
100
  $self->redirect_to(action => 'list_clients_and_users');
176
  $self->redirect_to(action => 'show');
101 177
}
102 178

  
103 179
sub action_lock_system {
......
110 186
  } else {
111 187
    $fh->close;
112 188
    flash_later('info', t8('Lockfile created!'));
113
    $self->redirect_to(action => 'list_clients_and_users');
189
    $self->redirect_to(action => 'show');
114 190
  }
115 191
}
116 192

  
......
118 194
# initializers
119 195
#
120 196

  
121
sub init_db_cfg            { $::lx_office_conf{'authentication/database'}               }
122
sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin';        }
123
sub init_client            { SL::DB::AuthClient->new(id => $::form->{client_id})->load; }
124
sub init_user              { SL::DB::AuthUser  ->new(id => $::form->{user_id}  )->load; }
197
sub init_db_cfg            { $::lx_office_conf{'authentication/database'}                                            }
198
sub init_nologin_file_name { $::lx_office_conf{paths}->{userspath} . '/nologin';                                     }
199
sub init_client            { SL::DB::AuthClient->new(id => ($::form->{id} || ($::form->{client} || {})->{id}))->load }
200
sub init_user              { SL::DB::AuthUser  ->new(id => ($::form->{id} || ($::form->{user}   || {})->{id}))->load }
201
sub init_all_clients       { SL::DB::Manager::AuthClient->get_all_sorted                                             }
202
sub init_all_groups        { SL::DB::Manager::AuthGroup->get_all_sorted                                              }
203
sub init_all_dateformats   { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd)      ]                                      }
204
sub init_all_numberformats { [ qw(1,000.00 1000.00 1.000,00 1000,00)          ]                                      }
205
sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ]                                      }
206
sub init_all_menustyles    {
207
  return [
208
    { id => 'old', title => $::locale->text('Old (on the side)') },
209
    { id => 'v3',  title => $::locale->text('Top (CSS)') },
210
    { id => 'neu', title => $::locale->text('Top (Javascript)') },
211
  ];
212
}
213

  
214
sub init_all_countrycodes {
215
  my %cc = User->country_codes;
216
  return [ map { id => $_, title => $cc{$_} }, sort { $cc{$a} cmp $cc{$b} } keys %cc ];
217
}
125 218

  
126 219
#
127 220
# filters
......
136 229
}
137 230

  
138 231
#
139
# helpers
232
# displaying forms
140 233
#
141 234

  
142 235
sub login_form {
......
145 238
  $self->render('admin/adminlogin', title => t8('kivitendo v#1 administration', $::form->{version}), %params);
146 239
}
147 240

  
241
sub edit_user_form {
242
  my ($self, %params) = @_;
243

  
244
  $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side);
245
  $self->render('admin/edit_user', %params);
246
}
247

  
248
#
249
# helpers
250
#
251

  
148 252
sub check_auth_db_and_tables {
149 253
  my ($self) = @_;
150 254

  

Auch abrufbar als: Unified diff