line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CallBackery::GuiPlugin::Users; |
2
|
1
|
|
|
1
|
|
598
|
use Mojo::Base 'CallBackery::GuiPlugin::AbstractTable'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
94
|
use CallBackery::Translate qw(trm); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
77
|
|
4
|
1
|
|
|
1
|
|
10
|
use CallBackery::Exception qw(mkerror); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
64
|
|
5
|
1
|
|
|
1
|
|
6
|
use Mojo::JSON qw(true false); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1475
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
CallBackery::GuiPlugin::Users - User Plugin |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use CallBackery::GuiPlugin::Users; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
The User Plugin. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 PROPERTIES |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
All the methods of L plus: |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 tableCfg |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has tableCfg => sub { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $admin = ( not $self->user or $self->user->may('admin')); |
36
|
|
|
|
|
|
|
return [ |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
label => trm('UserId'), |
39
|
|
|
|
|
|
|
type => 'number', |
40
|
|
|
|
|
|
|
width => '1*', |
41
|
|
|
|
|
|
|
key => 'cbuser_id', |
42
|
|
|
|
|
|
|
sortable => true, |
43
|
|
|
|
|
|
|
primary => true, |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
label => trm('Username'), |
47
|
|
|
|
|
|
|
type => 'string', |
48
|
|
|
|
|
|
|
width => '3*', |
49
|
|
|
|
|
|
|
key => 'cbuser_login', |
50
|
|
|
|
|
|
|
sortable => true, |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
label => trm('Given Name'), |
54
|
|
|
|
|
|
|
type => 'string', |
55
|
|
|
|
|
|
|
width => '4*', |
56
|
|
|
|
|
|
|
key => 'cbuser_given', |
57
|
|
|
|
|
|
|
sortable => true, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
label => trm('Family Name'), |
61
|
|
|
|
|
|
|
type => 'string', |
62
|
|
|
|
|
|
|
width => '4*', |
63
|
|
|
|
|
|
|
key => 'cbuser_family', |
64
|
|
|
|
|
|
|
sortable => true, |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
label => trm('Rights'), |
68
|
|
|
|
|
|
|
type => 'string', |
69
|
|
|
|
|
|
|
sortable => false, |
70
|
|
|
|
|
|
|
width => '8*', |
71
|
|
|
|
|
|
|
key => 'cbuser_cbrights', |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
$admin ? ({ |
74
|
|
|
|
|
|
|
label => trm('Note'), |
75
|
|
|
|
|
|
|
type => 'string', |
76
|
|
|
|
|
|
|
width => '8*', |
77
|
|
|
|
|
|
|
key => 'cbuser_note', |
78
|
|
|
|
|
|
|
}):(), |
79
|
|
|
|
|
|
|
] |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 actionCfg |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has actionCfg => sub { |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
# we must be in admin mode if no user property is set to have be able to prototype all forms variants |
89
|
|
|
|
|
|
|
my $admin = ( not $self->user or $self->user->may('admin')); |
90
|
|
|
|
|
|
|
return [ |
91
|
|
|
|
|
|
|
$admin ? ({ |
92
|
|
|
|
|
|
|
label => trm('Add User'), |
93
|
|
|
|
|
|
|
action => 'popup', |
94
|
|
|
|
|
|
|
addToContextMenu => true, |
95
|
|
|
|
|
|
|
key => 'add', |
96
|
|
|
|
|
|
|
popupTitle => trm('New User'), |
97
|
|
|
|
|
|
|
backend => { |
98
|
|
|
|
|
|
|
plugin => 'UserForm', |
99
|
|
|
|
|
|
|
config => { |
100
|
|
|
|
|
|
|
type => 'add' |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
}) : (), |
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
label => trm('Edit User'), |
106
|
|
|
|
|
|
|
action => 'popup', |
107
|
|
|
|
|
|
|
addToContextMenu => true, |
108
|
|
|
|
|
|
|
defaultAction => true, |
109
|
|
|
|
|
|
|
key => 'edit', |
110
|
|
|
|
|
|
|
popupTitle => trm('Edit User'), |
111
|
|
|
|
|
|
|
actionHandler => sub { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
my $args = shift; |
114
|
|
|
|
|
|
|
my $id = $args->{selection}{cbuser_id}; |
115
|
|
|
|
|
|
|
die mkerror(393,trm('You have to select a user first')) |
116
|
|
|
|
|
|
|
if not $id; |
117
|
|
|
|
|
|
|
}, |
118
|
|
|
|
|
|
|
set => { |
119
|
|
|
|
|
|
|
height => 340, |
120
|
|
|
|
|
|
|
width => 500 |
121
|
|
|
|
|
|
|
}, |
122
|
|
|
|
|
|
|
backend => { |
123
|
|
|
|
|
|
|
plugin => 'UserForm', |
124
|
|
|
|
|
|
|
config => { |
125
|
|
|
|
|
|
|
type => 'edit' |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
$admin ? ({ |
130
|
|
|
|
|
|
|
label => trm('Delete User'), |
131
|
|
|
|
|
|
|
action => 'submitVerify', |
132
|
|
|
|
|
|
|
addToContextMenu => true, |
133
|
|
|
|
|
|
|
question => trm('Do you really want to delete the selected user ?'), |
134
|
|
|
|
|
|
|
key => 'delete', |
135
|
|
|
|
|
|
|
actionHandler => sub { |
136
|
|
|
|
|
|
|
my $self = shift; |
137
|
|
|
|
|
|
|
my $args = shift; |
138
|
|
|
|
|
|
|
my $id = $args->{selection}{cbuser_id}; |
139
|
|
|
|
|
|
|
die mkerror(4992,trm("You have to select a user first")) |
140
|
|
|
|
|
|
|
if not $id; |
141
|
|
|
|
|
|
|
die mkerror(4993,trm("You can not delete the user you are logged in with")) |
142
|
|
|
|
|
|
|
if $id == $self->user->userId; |
143
|
|
|
|
|
|
|
my $db = $self->user->db; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
if ($db->deleteData('cbuser',$id) == 1){ |
146
|
|
|
|
|
|
|
return { |
147
|
|
|
|
|
|
|
action => 'reload', |
148
|
|
|
|
|
|
|
}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
die mkerror(4993,trm("Faild to remove user %1",$id)); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
}) : (), |
153
|
|
|
|
|
|
|
]; |
154
|
|
|
|
|
|
|
}; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 METHODS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
All the methods of L plus: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub currentUserFilter { |
164
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
165
|
0
|
0
|
|
|
|
|
if (not $self->user->may('admin')){ |
166
|
0
|
|
|
|
|
|
return 'WHERE cbuser_id = ' . $self->user->mojoSqlDb->dbh->quote($self->user->userId); |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
return ''; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub getTableRowCount { |
172
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
173
|
0
|
|
|
|
|
|
my $args = shift; |
174
|
0
|
|
|
|
|
|
my $db = $self->user->mojoSqlDb; |
175
|
0
|
0
|
|
|
|
|
if ($self->user->may('admin')){ |
176
|
0
|
|
|
|
|
|
return [$db->dbh->selectrow_array('SELECT count(cbuser_id) FROM ' |
177
|
|
|
|
|
|
|
. $db->dbh->quote_identifier('cbuser'))]->[0]; |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
return 1; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub getTableData { |
183
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
184
|
0
|
|
|
|
|
|
my $args = shift; |
185
|
0
|
|
|
|
|
|
my $db = $self->user->mojoSqlDb; |
186
|
0
|
|
|
|
|
|
my $SORT =''; |
187
|
0
|
0
|
|
|
|
|
if ($args->{sortColumn}){ |
188
|
0
|
|
|
|
|
|
$SORT = 'ORDER BY '.$db->dbh->quote_identifier($args->{sortColumn}); |
189
|
0
|
0
|
|
|
|
|
$SORT .= $args->{sortDesc} ? ' DESC' : ' ASC'; |
190
|
|
|
|
|
|
|
} |
191
|
0
|
|
|
|
|
|
my $WHERE = ''; |
192
|
0
|
0
|
|
|
|
|
if (not $self->user->may('admin')){ |
193
|
0
|
|
|
|
|
|
$WHERE = 'WHERE cbuser_id = ' . $db->dbh->quote($self->user->userId); |
194
|
|
|
|
|
|
|
} |
195
|
0
|
|
|
|
|
|
my $userTbl = $db->dbh->quote_identifier('cbuser'); |
196
|
0
|
|
|
|
|
|
my $rightTbl = $db->dbh->quote_identifier('cbright'); |
197
|
0
|
|
|
|
|
|
my $data = $db->dbh->selectall_arrayref(<<"SQL",{Slice => {}}, $args->{lastRow}-$args->{firstRow}+1,$args->{firstRow}); |
198
|
|
|
|
|
|
|
SELECT cbuser_id,cbuser_login, cbuser_given, cbuser_family, cbuser_note |
199
|
|
|
|
|
|
|
FROM $userTbl |
200
|
|
|
|
|
|
|
$WHERE |
201
|
|
|
|
|
|
|
$SORT |
202
|
|
|
|
|
|
|
LIMIT ? OFFSET ? |
203
|
|
|
|
|
|
|
SQL |
204
|
0
|
|
|
|
|
|
my @keys = map { $_->{cbuser_id} } @$data; |
|
0
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
my $keyPh = join ',', map { '?' } @keys; |
|
0
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $rightList = $db->dbh->selectall_arrayref(<<"SQL",{Slice => {}}, @keys ); |
207
|
|
|
|
|
|
|
SELECT cbuserright_cbuser,cbright_label FROM cbuserright JOIN $rightTbl ON cbuserright_cbright = cbright_id WHERE cbuserright_cbuser IN ($keyPh) |
208
|
|
|
|
|
|
|
SQL |
209
|
0
|
|
|
|
|
|
my %rights; |
210
|
0
|
|
|
|
|
|
for (@$rightList){ |
211
|
0
|
|
|
|
|
|
push @{$rights{$_->{cbuserright_cbuser}}}, $_->{cbright_label}; |
|
0
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
} |
213
|
0
|
|
|
|
|
|
for (@$data){ |
214
|
0
|
0
|
|
|
|
|
$_->{cbuser_cbrights} = join ', ', sort @{$rights{$_->{cbuser_id}}} if ref $rights{$_->{cbuser_id}} eq 'ARRAY'; |
|
0
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
} |
216
|
0
|
|
|
|
|
|
return $data; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
__END__ |