lib/CallBackery/GuiPlugin/Users.pm

filter: Statementstmt 26.0% 18 / 69 Branchbran 8.3% 2 / 24 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod 66.6% 2 / 3 totaltotal 25.0% 28 / 112 CC 16 SCAR 30.8
CC
16
Cov
22%
getTableData
56.0
__ANON__
20.0
__ANON__
12.4
CRAP 21.7
« lib/CallBackery/GuiPlugin/Abstract.pm ↑ Summary lib/CallBackery/GuiPlugin/AbstractForm.pm »
1 package CallBackery::GuiPlugin::Users;
2 1 ▶use Mojo::Base 'CallBackery::GuiPlugin::AbstractTable';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use CallBackery::Translate qw(trm);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use CallBackery::Exception qw(mkerror);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::JSON qw(true false);
Subroutine BEGIN: called CC=1 SCAR=0.0
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<CallBackery::GuiPlugin::AbstractTable> plus:
25  
26 =cut
27  
28 =head2 tableCfg
29  
30  
31 =cut
32  
33 0 ▶has tableCfg => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 my $self = shift;
35 return [
36 {
37 0 label => trm('UserId'),
38 type => 'number',
39 width => '1*',
40 key => 'cbuser_id',
41 sortable => true,
42 primary => true,
43 },
44 {
45 label => trm('Username'),
46 type => 'string',
47 width => '3*',
48 key => 'cbuser_login',
49 sortable => true,
50 },
51 {
52 label => trm('Given Name'),
53 type => 'string',
54 width => '4*',
55 key => 'cbuser_given',
56 sortable => true,
57 },
58 {
59 label => trm('Family Name'),
60 type => 'string',
61 width => '4*',
62 key => 'cbuser_family',
63 sortable => true,
64 },
65 {
66 label => trm('Rights'),
67 type => 'string',
68 sortable => false,
69 width => '8*',
70 key => 'cbuser_cbrights',
71 },
72 {
73 label => trm('Note'),
74 type => 'string',
75 width => '8*',
76 key => 'cbuser_note',
77 },
78 ]
79 1 };
80  
81 =head2 actionCfg
82  
83 =cut
84  
85 1 ▶has actionCfg => sub {
Subroutine __ANON__: called CC=4 SCAR=25.2
86 1 my $self = shift;
87 # we must be in admin mode if no user property is set to have be able to prototype all forms variants
88 1 ▶ my $admin = ( not $self->user or $self->user->may('admin'));
Condition33%1/3
!$self->user || $self->user->may('admin')
l!l&&r!l&&!r
100
MC/DC0%0/2
!$self->user || $self->user->may('admin')
!$self->user $self->user->may('admin')
Truth table33%1/3
not(A) || B
A= !$self->userB= $self->user->may('admin')
ABresult
1X1
011
000
89 return [
90 $admin ? ({
91 label => trm('Add User'),
92 action => 'popup',
93 addToContextMenu => true,
94 name => 'userFormAdd',
95 popupTitle => trm('New User'),
96 backend => {
97 plugin => 'UserForm',
98 config => {
99 type => 'add'
100 }
101 }
102 }) : (),
103 {
104 label => trm('Edit User'),
105 action => 'popup',
106 addToContextMenu => true,
107 defaultAction => true,
108 name => 'userFormEdit',
109 popupTitle => trm('Edit User'),
110 0 ▶ actionHandler => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
111 0 my $self = shift;
112 0 my $args = shift;
113 0 my $id = $args->{selection}{cbuser_id};
114 0 ▶ die mkerror(393,"You have to select a user first")
Branch: 1 branch
BranchTrueFalseTotal
if not $id 0 0 0
115 if not $id;
116 },
117 backend => {
118 plugin => 'UserForm',
119 config => {
120 type => 'edit'
121 }
122 }
123 },
124 $admin ? ({
125 label => trm('Delete User'),
126 action => 'submitVerify',
127 addToContextMenu => true,
128 question => trm('Do you really want to delete the selected user ?'),
129 key => 'delete',
130 0 ▶ actionHandler => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
131 0 my $self = shift;
132 0 my $args = shift;
133 0 my $id = $args->{selection}{cbuser_id};
134 0 ▶ die mkerror(4992,"You have to select a user first")
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
135 if not $id;
136 0 ▶ die mkerror(4993,"You can not delete the user you are logged in with")
Branch: 1 branch
BranchTrueFalseTotal
if $id == $self->user->userId 0 0 0
137 if $id == $self->user->userId;
138 0 my $db = $self->user->db;
139  
140 0 ▶ if ($db->deleteData('cbuser',$id) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($db->deleteData("cbuser", $id) == 1) 0 0 0
141 return {
142 0 action => 'reload',
143 };
144 }
145 0 die mkerror(4993,"Faild to remove user $id");
146 }
147 1 ▶ }) : (),
Branch: 2 branches
BranchTrueFalseTotal
$admin ? : 1 0 1
$admin ? : 1 0 1
148 ];
149 1 };
150  
151 =head1 METHODS
152  
153 All the methods of L<CallBackery::GuiPlugin::AbstractForm> plus:
154  
155 =cut
156  
157  
158 0 ▶sub currentUserFilter {
Subroutine currentUserFilter: not called CC=2 SCAR=17.9
Pod undocumented
159 0 my $self = shift;
160 0 ▶ if (not $self->user->may('admin')){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->user->may("admin")) 0 0 0
161 0 return 'WHERE cbuser_id = ' . $self->user->mojoSqlDb->dbh->quote($self->user->userId);
162 }
163 0 return '';
164 }
165  
166 0 ▶sub getTableRowCount {
Subroutine getTableRowCount: not called CC=2 SCAR=17.9
Pod documented
167 0 my $self = shift;
168 0 my $args = shift;
169 0 my $db = $self->user->mojoSqlDb;
170 0 ▶ if ($self->user->may('admin')){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->user->may("admin")) 0 0 0
171 0 return [$db->dbh->selectrow_array('SELECT count(cbuser_id) FROM '
172 . $db->dbh->quote_identifier('cbuser'))]->[0];
173 }
174 0 return 1;
175 }
176  
177 0 ▶sub getTableData {
Subroutine getTableData: not called CC=7 SCAR=40.3
Pod documented
178 0 my $self = shift;
179 0 my $args = shift;
180 0 my $db = $self->user->mojoSqlDb;
181 0 my $SORT ='';
182 0 ▶ if ($args->{sortColumn}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"sortColumn"}) 0 0 0
183 0 $SORT = 'ORDER BY '.$db->dbh->quote_identifier($args->{sortColumn});
184 0 ▶ $SORT .= $args->{sortDesc} ? ' DESC' : ' ASC';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'sortDesc'} ? : 0 0 0
185 }
186 0 my $WHERE = '';
187 0 ▶ if (not $self->user->may('admin')){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->user->may("admin")) 0 0 0
188 0 $WHERE = 'WHERE cbuser_id = ' . $db->dbh->quote($self->user->userId);
189 }
190 0 my $userTbl = $db->dbh->quote_identifier('cbuser');
191 0 my $rightTbl = $db->dbh->quote_identifier('cbright');
192 0 my $data = $db->dbh->selectall_arrayref(<<"SQL",{Slice => {}}, $args->{lastRow}-$args->{firstRow},$args->{firstRow});
193 SELECT cbuser_id,cbuser_login, cbuser_given, cbuser_family, cbuser_note
194 FROM $userTbl
195 $WHERE
196 $SORT
197 LIMIT ? OFFSET ?
198 SQL
199 0 my @keys = map { $_->{cbuser_id} } @$data;
200 0 my $keyPh = join ',', map { '?' } @keys;
201 0 my $rightList = $db->dbh->selectall_arrayref(<<"SQL",{Slice => {}}, @keys );
202 SELECT cbuserright_cbuser,cbright_label FROM cbuserright JOIN $rightTbl ON cbuserright_cbright = cbright_id WHERE cbuserright_cbuser IN ($keyPh)
203 SQL
204 0 my %rights;
205 0 for (@$rightList){
206 0 push @{$rights{$_->{cbuserright_cbuser}}}, $_->{cbright_label};
207 }
208 0 for (@$data){
209 0 ▶ $_->{cbuser_cbrights} = join ', ', sort @{$rights{$_->{cbuser_id}}} if ref $rights{$_->{cbuser_id}} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rights{$_->{"cbuser_id"}} eq "ARRAY" 0 0 0
210 }
211 0 return $data;
212 }
213  
214  
215 1 1;
216 __END__
« lib/CallBackery/GuiPlugin/Abstract.pm ↑ Summary lib/CallBackery/GuiPlugin/AbstractForm.pm »