Labyrinth/Plugin/CPAN/Author.pm

filter: Statementstmt 22.2% 64 / 288 Branchbran 1.0% 1 / 100 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 51.4% 18 / 35 Podpod 100% 16 / 16 totaltotal 20.2% 99 / 490 CC 71 SCAR 39.7
CC
71
Cov
15%
Tester
156.0
Reports
90.0
Marked
90.0
CRAP 52.9
« Labyrinth/Plugin/CPAN/Tester.pm ↑ Summary Labyrinth/Plugin/CPAN/Admin.pm »
1 package Labyrinth::Plugin::CPAN::Author;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $VERSION = '0.15';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::CPAN::Author - Author Plugin for CPAN Testers Admin website.
12  
13 =cut
14  
15 #----------------------------------------------------------------------------
16 # Libraries
17  
18 2 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Labyrinth::Mailer;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 ▶use Labyrinth::Plugin::CPAN;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use Net::SSLeay qw(get_https make_headers);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Sort::Versions;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 #----------------------------------------------------------------------------
38 # Variables
39  
40 2 my ($backpan,$oncpan);
41  
42 # The following distributions are considered exceptions from the norm and
43 # are to be added on a case by case basis.
44 2 my $EXCEPTIONS = 'Test.php|Net-ITE.pm|CGI.pm';
45  
46 2 my %date_fields = (
47 y => { type => 1, html => 1 },
48 m => { type => 1, html => 1 },
49 d => { type => 1, html => 1 },
50 );
51  
52 2 my (@date_man,@date_all);
53 2 for(keys %date_fields) {
54 6 ▶ push @date_man, $_ if($date_fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $date_fields{$_}{"type"} 6 0 6
55 6 push @date_all, $_;
56 }
57  
58 2 my %months = (
59 1 => 'January',
60 2 => 'February',
61 3 => 'March',
62 4 => 'April',
63 5 => 'May',
64 6 => 'June',
65 7 => 'July',
66 8 => 'August',
67 9 => 'September',
68 10 => 'October',
69 11 => 'November',
70 12 => 'December',
71 );
72  
73 #----------------------------------------------------------------------------
74 # Public Interface Functions
75  
76 =head1 METHODS
77  
78 =head2 Public Interface Methods
79  
80 =over 4
81  
82 =item Login
83  
84 Author Login mechanism. Uses the PAUSE authentication system.
85  
86 =item Logged
87  
88 Ensure correct user is logged in.
89  
90 =item Browse
91  
92 List authors dists which have reports.
93  
94 =item Distro
95  
96 List distributions released by the author.
97  
98 =item Dist
99  
100 List reports for the given distribution released by the author.
101  
102 =item Browser
103  
104 List dates for which author's distribution releases which have reports.
105  
106 =item Reports
107  
108 List reports for the given author's distribution releases.
109  
110 =item Testers
111  
112 List testers who have submitted reports for the author distributions.
113  
114 =item Tester
115  
116 List reports submitted by the given tester for the author distributions.
117  
118 =item Find
119  
120 Find a report by ID.
121  
122 =item Mark
123  
124 Request report removal
125  
126 =item Unmark
127  
128 Remove request report removal
129  
130 =item Marked
131  
132 List those reports the author has marked for removal.
133  
134 =back
135  
136 =cut
137  
138 0 ▶sub Login {
Subroutine Login: not called CC=3 SCAR=24.8
Pod documented
139 0 my $result = LWP::UserAgent->new->get("https://pause.perl.org/pause/authenquery",
140 Authorization =>
141 'Basic ' . MIME::Base64::encode("$cgiparams{pause}:$cgiparams{eject}",'')
142 );
143  
144 0 ▶ if($result->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code == 200) { } 0 0 0
145 0 my @rows = $dbi->GetQuery('hash','CheckUser','PAUSE','PAUSE');
146  
147 # add entry to session table
148 0 my $session;
149 ( $session,
150 $tvars{user}{name},
151 $tvars{'loginid'},
152 $tvars{realm},
153 $tvars{langcode}
154 0 ) = Labyrinth::Session::_save_session(uc $cgiparams{pause},$rows[0]->{userid},$rows[0]->{realm},$rows[0]->{langcode});
155  
156 # set template variables
157 0 $tvars{'loggedin'} = 1;
158 0 $tvars{user}{folder} = 1;
159 0 $tvars{user}{option} = 0;
160 0 $tvars{user}{userid} = $tvars{'loginid'};
161 0 $tvars{user}{access} = VerifyUser($tvars{'loginid'});
162 0 ▶ $tvars{realm} ||= 'public';
Condition0%0/2
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} ||= "public"
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} ||= "public"
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"}
Truth table0%0/2
A
A= $Labyrinth::Plugin::CPAN::Author::tvars{"realm"}
Aresult
11
00
163  
164 } else {
165 0 $tvars{errmess} = 'That username/password failed to be authenticated by PAUSE';
166 0 $tvars{errcode} = 'ERROR';
167 }
168 }
169  
170 0 ▶sub Logged {
Subroutine Logged: not called CC=2 SCAR=17.9
Pod documented
171 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
172 }
173  
174 0 ▶sub Browse {
Subroutine Browse: not called CC=7 SCAR=40.3
Pod documented
175 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
176  
177 0 my $author = $tvars{user}{name};
178 0 $author =~ s/^imposter://;
179  
180 # What distributions have been released by this author?
181 0 my $cpan = Labyrinth::Plugin::CPAN->new();
182 0 my $dbx = $cpan->DBX('cpanstats');
183 0 my @rows = $dbx->GetQuery('array','GetAuthorDists',$author);
184 0 my @dists = map {$_->[0]} @rows;
185  
186 0 my %dists;
187 0 for my $dist (@dists ) {
188 0 ▶ next unless($dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/
Branch: 1 branch
BranchTrueFalseTotal
unless $dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/ 0 0 0
Condition0%0/3
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/
l!l&&r!l&&!r
000
MC/DC0%0/2
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ or $dist =~ /$EXCEPTIONS/
$dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/ $dist =~ /$EXCEPTIONS/
Truth table0%0/3
A or B
A= $dist =~ /^[A-Za-z0-9][A-Za-z0-9\-_]*$/B= $dist =~ /$EXCEPTIONS/
ABresult
1X1
011
000
189 || $dist =~ /$EXCEPTIONS/);
190 0 ▶ next if(defined $dists{$dist});
Branch: 1 branch
BranchTrueFalseTotal
if defined $dists{$dist} 0 0 0
191 #print "... dist $dist\n";
192  
193 0 $dists{$dist} = 1;
194 }
195  
196 0 ▶ if(keys %dists) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %dists) 0 0 0
197 0 my @distros = sort keys %dists;
198 0 $tvars{data}{dists} = \@distros;
199 0 $tvars{hash}{dists} = \%dists;
200 }
201 }
202  
203 0 ▶sub Distro {
Subroutine Distro: not called CC=3 SCAR=24.8
Pod documented
204 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
205  
206 0 my $author = $tvars{user}{name};
207 0 $author =~ s/^imposter://;
208  
209 0 my $cpan = Labyrinth::Plugin::CPAN->new();
210 0 my $dbx = $cpan->DBX('cpanstats');
211 0 my @rows = $dbx->GetQuery('hash','GetAuthorDists',$author);
212  
213 0 ▶ $tvars{data}{distros} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
214 }
215  
216 0 ▶sub Dist {
Subroutine Dist: not called CC=6 SCAR=37.4
Pod documented
217 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
218  
219 0 my $dist = $cgiparams{dist};
220 0 my $version = $cgiparams{version};
221 0 my $author = $tvars{user}{name};
222 0 $author =~ s/^imposter://;
223  
224 0 my $cpan = Labyrinth::Plugin::CPAN->new();
225 0 my $dbx = $cpan->DBX('cpanstats');
226 0 my @rows = $dbx->GetQuery('array','GetAuthorDistVersions',$author,$dist);
227 0 my @versions = map {$_->[0]} @rows;
228  
229 0 my %versions = map {$_ => 1} @versions;
230 0 @versions = sort {versioncmp($b,$a)} keys %versions;
231 0 ▶ $version ||= $versions[0];
Condition0%0/3
$version ||= $versions[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $versions[0]
$version $versions[0]
Truth table0%0/3
A ||= B
A= $versionB= $versions[0]
ABresult
1X1
011
000
232  
233 0 $tvars{data}{distribution} = $dist;
234 0 $tvars{data}{version} = $version;
235 0 $tvars{data}{ddversions} = DropDownList($version,'version',@versions);
236  
237 0 @rows = $dbx->GetQuery('hash','GetAuthorReports',$dist,$version);
238 0 for my $row (@rows) {
239 0 ▶ next unless($row->{fulldate});
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"fulldate"} 0 0 0
240 0 $row->{fulldate} = _parse_date($row->{fulldate});
241 0 $row->{profile} = $cpan->GetTesterProfile($row->{guid},$row->{tester});
242 }
243 0 ▶ $tvars{data}{reports} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
244 }
245  
246 0 ▶sub Browser {
Subroutine Browser: not called CC=6 SCAR=37.4
Pod documented
247 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
248  
249 # get list of distributions for this author
250 0 Browse();
251 0 my $dists = "'" . join("','",@{$tvars{data}{dists}}) . "'";
252  
253 0 my %dates;
254 0 my $cpan = Labyrinth::Plugin::CPAN->new();
255 0 my $dbx = $cpan->DBX('cpanstats');
256 #my @dates = $dbx->GetQuery('hash','GetAuthorReportDates',{dists => $dists});
257 #for(@dates) {
258
259 0 my $next = $dbx->Iterator('hash','GetAuthorReportDates',{dists => $dists});
260 0 ▶ while(my $row = $next->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 0 0 0
261 0 my ($y,$m,$d) = $row->{fulldate} =~ /(\d{4,4})(\d{2,2})(\d{2,2})/;
262 #$m = int($m);
263 0 $dates{$y}{year} = $y;
264 0 $dates{$y}{months}->{$m}{month} = $months{int($m)};
265 0 $dates{$y}{months}->{$m}{days}->{$d}{day} = int($d);
266 }
267  
268 #$tvars{data}{dates} = \%dates if(keys %dates);
269  
270 0 my @y;
271 0 for my $y (sort {$b <=> $a } keys %dates) {
272 0 my @m;
273 0 for my $m (sort {$b <=> $a } keys %{$dates{$y}{months}}) {
274 0 my @d = sort {$a <=> $b } keys %{$dates{$y}{months}{$m}{days}};
275 0 push @m, {days => \@d, month => $months{int($m)}, mon => $m};
276 }
277 0 push @y, {months => \@m, year => $y};
278 }
279  
280 0 ▶ $tvars{data}{dates} = \@y if(@y);
Branch: 1 branch
BranchTrueFalseTotal
if @y 0 0 0
281 }
282  
283 0 ▶sub Reports {
Subroutine Reports: not called CC=9 SCAR=45.0
Pod documented
284 0 ▶ return unless RealmCheck('tester','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("tester", "admin") 0 0 0
285  
286 0 for(keys %date_fields) {
287 0 ▶ if($date_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}); }
Branch: 2 branches
BranchTrueFalseTotal
if ($date_fields{$_}{'html'} == 1) { } 0 0 0
elsif ($date_fields{$_}{'html'} == 2) { } 0 0 0
288 0 elsif($date_fields{$_}->{html} == 2) { $cgiparams{$_} = SafeHTML($cgiparams{$_}); }
289 }
290  
291 0 ▶ return if FieldCheck(\@date_all,\@date_man);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@date_all, \@date_man) 0 0 0
292  
293 # get list of distributions for this author
294 0 Browse();
295 0 my $dists = "'" . join("','",@{$tvars{data}{dists}}) . "'";
296  
297 0 my $cpan = Labyrinth::Plugin::CPAN->new();
298 0 my $dbx = $cpan->DBX('cpanstats');
299 0 my $date = sprintf "%04d%02d%02d\%", $tvars{data}{y},$tvars{data}{m},$tvars{data}{d};
300 0 my @rows = $dbx->GetQuery('hash','GetAuthorReportList',{dists => $dists},$date);
301 0 for my $row (@rows) {
302 0 ▶ next unless($row->{fulldate});
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"fulldate"} 0 0 0
303 0 $row->{fulldate} = _parse_date($row->{fulldate});
304 0 $row->{profile} = $cpan->GetTesterProfile($row->{guid},$row->{tester});
305 0 LogDebug("profile=".Dumper($row->{profile}));
306 }
307 0 ▶ $tvars{data}{reports} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
308  
309 0 $date = timelocal(0,0,12,$tvars{data}{d},$tvars{data}{m}-1,$tvars{data}{y});
310 0 $tvars{data}{date} = formatDate(10,$date);
311 }
312  
313 0 ▶sub Testers {
Subroutine Testers: not called CC=5 SCAR=34.0
Pod documented
314 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
315  
316 0 ▶ my $letter = $cgiparams{letter} || 'A';
Condition0%0/2
$Labyrinth::Plugin::CPAN::Author::cgiparams{'letter'} || 'A'
l!l
00
MC/DC0%0/1
$Labyrinth::Plugin::CPAN::Author::cgiparams{'letter'} || 'A'
$Labyrinth::Plugin::CPAN::Author::cgiparams{'letter'}
Truth table0%0/2
A
A= $Labyrinth::Plugin::CPAN::Author::cgiparams{'letter'}
Aresult
11
00
317  
318 0 my $cpan = Labyrinth::Plugin::CPAN->new();
319 0 my $dbx = $cpan->DBX('cpanstats');
320  
321 0 my @rows;
322 0 ▶ if($letter eq '9') {
Branch: 1 branch
BranchTrueFalseTotal
if ($letter eq '9') { } 0 0 0
323 0 @rows = $dbx->GetQuery('hash','ListTesters9');
324 } else {
325 0 @rows = $dbx->GetQuery('hash','ListTesters',{letter => $letter});
326 }
327  
328 0 ▶ $tvars{data}{testers} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
329 }
330  
331 0 ▶sub Tester {
Subroutine Tester: not called CC=12 SCAR=50.5
Pod documented
332 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
333  
334 0 my $cpan = Labyrinth::Plugin::CPAN->new();
335 0 my $dbx = $cpan->DBX('cpanstats');
336  
337 0 my @tester = $dbx->GetQuery('hash','GetTesterByID',$cgiparams{testerid});
338 0 ▶ if(@tester) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tester) 0 0 0
339 0 $tvars{data}{tester} = $tester[0];
340 0 $tvars{data}{letter} = uc substr($tester[0]->{name},0,1);
341 }
342  
343 0 my ($prev,$next,$order) = ('','','DESC');
344 0 ▶ if($cgiparams{'prev'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Labyrinth::Plugin::CPAN::Author::cgiparams{'prev'}) { } 0 0 0
elsif ($Labyrinth::Plugin::CPAN::Author::cgiparams{'next'}) { } 0 0 0
345 0 $prev = "AND x.guid > '$cgiparams{prev}'";
346 0 $order = 'ASC';
347 } elsif($cgiparams{'next'}) {
348 0 $next = "AND x.guid < '$cgiparams{next}'";
349 0 $order = 'DESC';
350 }
351  
352 0 my @rows = $dbx->GetQuery('hash','ListReports',{'prev'=>$prev,'next'=>$next,'order'=>$order},$tvars{user}{author},$cgiparams{testerid});
353 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) 0 0 0
354 0 for(@rows) {
355 0 my ($y,$m,$d) = $_->{fulldate} =~ /^(\d{4})(\d{2})(\d{2})/;
356 0 $_->{showdate} = sprintf "%04d-%02d-%02d", $y, $m, $d;
357 }
358 0 ▶ if($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 0 0 0
359 0 my @revs = reverse @rows;
360 0 @rows = @revs;
361 }
362 0 $tvars{data}{reports} = \@rows;
363  
364 0 my @prev = $dbx->GetQuery('hash','CountReports',{'prev'=>"AND x.guid > '$rows[0]->{guid}'"},$cgiparams{testerid});
365 0 my @next = $dbx->GetQuery('hash','CountReports',{'next'=>"AND x.guid < '$rows[-1]->{guid}'"},$cgiparams{testerid});
366  
367 0 ▶ $tvars{pager}{prev} = $rows[0]->{guid} if(@prev && $prev[0]->{count} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @prev and $prev[0]{"count"} > 0 0 0 0
Condition0%0/3
@prev and $prev[0]{"count"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
@prev and $prev[0]{"count"} > 0
@prev $prev[0]{"count"} > 0
Truth table0%0/3
A and B
A= @prevB= $prev[0]{"count"} > 0
ABresult
0X0
100
111
368 0 ▶ $tvars{pager}{next} = $rows[-1]->{guid} if(@next && $next[-1]->{count} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @next and $next[-1]{"count"} > 0 0 0 0
Condition0%0/3
@next and $next[-1]{"count"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
@next and $next[-1]{"count"} > 0
@next $next[-1]{"count"} > 0
Truth table0%0/3
A and B
A= @nextB= $next[-1]{"count"} > 0
ABresult
0X0
100
111
369 }
370 }
371  
372 0 ▶sub Find {
Subroutine Find: not called CC=3 SCAR=24.8
Pod documented
373 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
374 0 $tvars{searched} = 1;
375  
376 0 my $cpan = Labyrinth::Plugin::CPAN->new();
377 0 my $dbx = $cpan->DBX('cpanstats');
378 0 my @rows = $dbx->GetQuery('hash','FindReport',$cgiparams{guid});
379 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) 0 0 0
380 0 $tvars{data}{reports} = \@rows;
381 0 SetCommand('author-report');
382 }
383 }
384  
385 0 ▶sub Mark {
Subroutine Mark: not called CC=8 SCAR=42.8
Pod documented
386 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
387  
388 0 $tvars{body}{success} = 0;
389 0 $tvars{body}{result} = 'failed';
390  
391 0 my $cpan = Labyrinth::Plugin::CPAN->new();
392 0 my $dbx = $cpan->DBX('cpanstats');
393 0 my @rows = $dbx->GetQuery('hash','GetReports',{ids => join(',',CGIArray('DELETE'))});
394  
395 # get list of distributions for this author
396 0 Browse();
397  
398 0 my $author = $tvars{user}{author};
399  
400 0 my (%done,@data);
401 0 for my $row (@rows) {
402 0 ▶ next unless($tvars{hash}{dists}{$row->{dist}});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::CPAN::Author::tvars{"hash"}{"dists"}{$row->{"dist"}} 0 0 0
403  
404 0 my ($email,$name,$userid,$addressid) = $cpan->FindTester($row->{tester});
405 0 LogDebug("$author marks the report '$row->{id}' tested by '$row->{tester}', mapping to '$email' / '$name' / '$userid' / '$addressid'");
406  
407 # mark the report
408 0 $dbi->DoQuery('MarkReport',$row->{id},$addressid,$email,$author,time());
409 0 push @data, $row->{id};
410  
411 # now email the tester to let them know
412 0 ▶ next if($done{mail}{$email});
Branch: 1 branch
BranchTrueFalseTotal
if $done{"mail"}{$email} 0 0 0
413 0 ▶ next if($done{user}{$userid});
Branch: 1 branch
BranchTrueFalseTotal
if $done{"user"}{$userid} 0 0 0
414 0 $done{mail}{$email} = 1;
415  
416 0 ▶ if($userid > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($userid > 0) 0 0 0
417 0 $done{user}{$userid} = 1;
418  
419 # send mail to tester
420 0 MailSend( template => 'mailer/marked.eml',
421 name => $name,
422 recipient_email => $email
423 );
424  
425 0 ▶ if(!MailSent()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (MailSent()) 0 0 0
426 0 $tvars{body}{errcode} = 'BADMAIL';
427 }
428 }
429 }
430  
431 0 $tvars{body}{success} = 1;
432 0 $tvars{body}{result} = 'marked';
433 0 $tvars{body}{data} = join(',',@data);
434 0 $tvars{realm} = 'json';
435  
436 0 LogDebug("body=".Dumper($tvars{body}));
437  
438 }
439  
440 0 ▶sub Unmark {
Subroutine Unmark: not called CC=2 SCAR=17.9
Pod documented
441 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
442  
443 0 $tvars{body}{success} = 0;
444 0 $tvars{body}{result} = 'failed';
445  
446 0 my $cpan = Labyrinth::Plugin::CPAN->new();
447 0 my $dbx = $cpan->DBX('cpanstats');
448 0 my @rows = $dbx->GetQuery('hash','GetReports',{ids => join(',',CGIArray('DELETE'))});
449 0 my @data = map {$_->{id}} @rows;
450  
451 0 my $author = $tvars{user}{author};
452  
453 # unmark the reports
454 0 $dbi->DoQuery('UnmarkAuthorReports',{ids => join(',',@data)},$author);
455  
456 0 $tvars{body}{success} = 1;
457 0 $tvars{body}{result} = 'unmarked';
458 0 $tvars{body}{data} = join(',',@data);
459 0 $tvars{realm} = 'json';
460  
461 # LogDebug("body=".Dumper($tvars{body}));
462 }
463  
464 0 ▶sub Marked {
Subroutine Marked: not called CC=9 SCAR=45.0
Pod documented
465 0 ▶ return unless RealmCheck('pause','admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("pause", "admin") 0 0 0
466 0 my $cpan = Labyrinth::Plugin::CPAN->new();
467 0 my $dbx = $cpan->DBX('cpanstats');
468 0 my @rows;
469  
470 0 ▶ if($tvars{realm} eq 'admin' && !$tvars{user}{author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::CPAN::Author::tvars{'realm'} eq 'admin' and not $Labyrinth::Plugin::CPAN::Author::tvars{'user'}{'author'}) { } 0 0 0
Condition0%0/3
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" and not $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" and not $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" not $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
Truth table0%0/3
A and not(B)
A= $Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin"B= not $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
ABresult
0X0
100
111
471 0 @rows = $dbi->GetQuery('hash','ListAllMarkedReports');
472 } else {
473 0 my $userid = $tvars{'loginid'};
474 0 ▶ $userid = $tvars{user}{author} if($tvars{realm} eq 'admin' && $tvars{user}{author});
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" and $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"} 0 0 0
Condition0%0/3
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" and $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" and $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
$Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin" $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
Truth table0%0/3
A and B
A= $Labyrinth::Plugin::CPAN::Author::tvars{"realm"} eq "admin"B= $Labyrinth::Plugin::CPAN::Author::tvars{"user"}{"author"}
ABresult
0X0
100
111
475 0 @rows = $dbi->GetQuery('hash','ListMarkedAuthorReports',$userid);
476 }
477  
478 0 for my $row (@rows) {
479 0 ▶ next unless($row->{fulldate});
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"fulldate"} 0 0 0
480 0 $row->{fulldate} = _parse_date($row->{fulldate});
481 0 $row->{profile} = $cpan->GetTesterProfile($row->{guid},$row->{tester});
482 }
483  
484 0 ▶ $tvars{data}{reports} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
485 }
486  
487 =head2 Admin Interface Methods
488  
489 =over 4
490  
491 =item Admin
492  
493 Prepare Admin login as author.
494  
495 =item Imposter
496  
497 Clear Imposter status and return to Admin.
498  
499 =item Clear
500  
501 Return admin to normal admin state.
502  
503 =back
504  
505 =cut
506  
507 0 ▶sub Admin {
Subroutine Admin: not called CC=2 SCAR=17.9
Pod documented
508 0 ▶ return unless RealmCheck('admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
509 0 $tvars{where} = "AND u.realm='author' AND u.userid > 3";
510 }
511  
512 0 ▶sub Imposter {
Subroutine Imposter: not called CC=2 SCAR=17.9
Pod documented
513 0 ▶ return unless RealmCheck('admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
514 0 UpdateSession('name' => 'imposter:' . $cgiparams{pause});
515 0 $tvars{user}{author} = $cgiparams{pause};
516 }
517  
518 0 ▶sub Clear {
Subroutine Clear: not called CC=2 SCAR=17.9
Pod documented
519 0 ▶ return unless RealmCheck('admin');
Branch: 1 branch
BranchTrueFalseTotal
unless RealmCheck("admin") 0 0 0
520 0 UpdateSession('name' => 'Admin');
521 0 $tvars{user}{name} = 'Admin';
522 0 delete $tvars{user}{author};
523 0 delete $tvars{user}{fakename};
524 }
525  
526 0 ▶sub _parse_date {
Subroutine _parse_date: not called CC=6 SCAR=37.4
527 0 my $date = shift;
528 0 my ($Y,$M,$D,$h,$m) = ($date =~ /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/);
529 0 ▶ return $date unless($Y && $M && $D);
Branch: 1 branch
BranchTrueFalseTotal
unless $Y and $M and $D 0 0 0
Condition0%0/6
$Y and $M and $D
!ll&&!rl&&r
000
$Y and $M
!ll&&!rl&&r
000
MC/DC0%0/3
$Y and $M and $D
$Y $M $D
Truth table0%0/4
A and B and C
A= $YB= $MC= $D
ABCresult
0XX0
10X0
1100
1111
530  
531 0 ▶ $h ||= 0;
Condition0%0/2
$h ||= 0
l!l
00
MC/DC0%0/1
$h ||= 0
$h
Truth table0%0/2
A
A= $h
Aresult
11
00
532 0 ▶ $m ||= 0;
Condition0%0/2
$m ||= 0
l!l
00
MC/DC0%0/1
$m ||= 0
$m
Truth table0%0/2
A
A= $m
Aresult
11
00
533  
534 0 return sprintf "%02d/%02d/%04d %02d:%02d", $D,$M,$Y, $h,$m;
535 }
536  
537 2 1;
538  
539 __END__
« Labyrinth/Plugin/CPAN/Tester.pm ↑ Summary Labyrinth/Plugin/CPAN/Admin.pm »