[bugzilla-gnome-org-extensions] describe user: Fix miscellaneous issues



commit 11dbd70eaf897ba978d1a195e4613cb756da3790
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Sun Nov 9 23:04:27 2014 +0100

    describe user: Fix miscellaneous issues
    
    Use warnings pragma, whitespace fixes, update config, set version,
    style fixes, code shuffling.

 DescribeUser/Config.pm                             |    8 ++
 DescribeUser/Extension.pm                          |   19 ++---
 DescribeUser/lib/Util.pm                           |   69 ++++++++++----------
 .../en/default/pages/describeuser.html.tmpl        |   20 +++---
 4 files changed, 61 insertions(+), 55 deletions(-)
---
diff --git a/DescribeUser/Config.pm b/DescribeUser/Config.pm
index 5f8a44b..efff743 100644
--- a/DescribeUser/Config.pm
+++ b/DescribeUser/Config.pm
@@ -1,5 +1,13 @@
 package Bugzilla::Extension::DescribeUser;
 use strict;
+use warnings;
+
 use constant NAME => 'DescribeUser';
 
+use constant REQUIRED_MODULES => [
+];
+
+use constant OPTIONAL_MODULES => [
+];
+
 __PACKAGE__->NAME;
diff --git a/DescribeUser/Extension.pm b/DescribeUser/Extension.pm
index 7ec8b5b..40e8644 100644
--- a/DescribeUser/Extension.pm
+++ b/DescribeUser/Extension.pm
@@ -1,29 +1,26 @@
 package Bugzilla::Extension::DescribeUser;
 use strict;
+use warnings;
 use base qw(Bugzilla::Extension);
 
 use Bugzilla::Extension::DescribeUser::Util qw(page);
 
-our $VERSION = '';
+our $VERSION = '0.01';
 
 sub page_before_template {
     my ($self, $args) = @_;
-    
-    Bugzilla::Extension::DescribeUser::Util::page(%{ $args });
-    
+
+    page($args);
 }
 
 sub config_modify_panels {
     my ($self, $args) = @_;
-
-    my $panels = $args->{panels};
-
+    my $panels = $args->{'panels'};
     # Point default of mybugstemplate towards this extension
-    my $query_params = $panels->{'query'}->{params};
-
-    my ($mybugstemplate)   = grep($_->{name} eq 'mybugstemplate', @$query_params);
+    my $query_params = $panels->{'query'}->{'params'};
+    my ($mybugstemplate) = grep {$_->{'name'} eq 'mybugstemplate'} @{$query_params};
 
-    $mybugstemplate->{default} = 'page.cgi?id=describeuser.html&login=%userid%'
+    $mybugstemplate->{'default'} = 'page.cgi?id=describeuser.html&login=%userid%';
 }
 
 __PACKAGE__->NAME;
diff --git a/DescribeUser/lib/Util.pm b/DescribeUser/lib/Util.pm
index b605b2c..1c47e06 100644
--- a/DescribeUser/lib/Util.pm
+++ b/DescribeUser/lib/Util.pm
@@ -20,6 +20,7 @@
 package Bugzilla::Extension::DescribeUser::Util;
 
 use strict;
+use warnings;
 use base qw(Exporter);
 
 use Bugzilla;
@@ -32,32 +33,40 @@ our @EXPORT = qw(
     page
 );
 
-sub page {
-    my %params = @_;
-    my ($vars, $page) = @params{qw(vars page_id)};
-    if ($page =~ /^describeuser\./) {
-        _page_describeuser($vars);
+sub _developed_products {
+    my $self = shift;
+
+    return [] unless $self->id;
+
+    # Get the list of products
+    my $groups = $self->{'groups'};
+    my @group_membership = ();
+    foreach my $group (@{$groups}) {
+         push (@group_membership,
+               substr($group->name, 0, index($group->name, '_developers')))
+               if $group->name =~ /_developers$/;
     }
+
+    # return it
+    return \ group_membership;
 }
 
 sub _page_describeuser {
     my $vars = shift;
-
     my $cgi = Bugzilla->cgi;
     my $dbh = Bugzilla->dbh;
     my $user = Bugzilla->user;
-
     my $userid = $user->id;
-
     my $r_userid;
     my $r_user;
     my $displayname;
     my $to_be_conjugation;
+    my $login = $cgi->param('login');
 
-    if (defined $cgi->param('login') && (!Bugzilla->user->id || (trim($cgi->param('login')) != 
Bugzilla->user->login))) {
-        $r_userid = login_to_id(trim($cgi->param('login')));
+    if (defined($login) && (!Bugzilla->user->id || (trim($login) != Bugzilla->user->login))) {
+        $r_userid = login_to_id(trim($login));
         if ($r_userid == 0) {
-                ThrowUserError('invalid_username', { name => $cgi->param('login') });
+            ThrowUserError('invalid_username', { 'name' => $login });
         }
         $r_user = Bugzilla::User->new($r_userid);
         $displayname = $r_user->name || $r_user->login;
@@ -126,13 +135,13 @@ sub _page_describeuser {
            "SELECT COUNT(DISTINCT bug_id)
               FROM bugs
              WHERE bugs.reporter = ?
-               AND NOT (bugs.bug_status = 'RESOLVED' AND 
+               AND NOT (bugs.bug_status = 'RESOLVED' AND
                         bugs.resolution IN ('DUPLICATE','INVALID','NOTABUG',
                                             'NOTGNOME','INCOMPLETE'))",
            undef, $r_userid);
     $vars->{'bugs_reported'} = $bugs_reported;
 
-    $vars->{'developed_products'} = developed_products($r_user);
+    $vars->{'developed_products'} = _developed_products($r_user);
 
     my $sth;
     my @patches;
@@ -257,8 +266,8 @@ sub _page_describeuser {
 
     my @recentlyclosed;
     $sth = $dbh->prepare("
-            SELECT bugs.bug_id, products.name AS product, bugs.bug_status, 
-                   bugs.resolution, bugs.bug_severity, bugs.short_desc 
+            SELECT bugs.bug_id, products.name AS product, bugs.bug_status,
+                   bugs.resolution, bugs.bug_severity, bugs.short_desc
               FROM bugs
                    $sec_join
         INNER JOIN products
@@ -267,7 +276,7 @@ sub _page_describeuser {
                 ON bugs.bug_id = bugs_activity.bug_id
              WHERE bugs.reporter = ?
                AND bugs_activity.added='RESOLVED'
-               AND (bugs.bug_status='RESOLVED' OR bugs.bug_status = 'VERIFIED' 
+               AND (bugs.bug_status='RESOLVED' OR bugs.bug_status = 'VERIFIED'
                     OR bugs.bug_status='CLOSED')
                AND bugs_activity.bug_when >= " . $dbh->sql_date_math('LOCALTIMESTAMP(0)', '-', 7, 'DAY')
                  . $sec_where);
@@ -284,9 +293,9 @@ sub _page_describeuser {
             undef, $r_userid);
 
         my @watchers;
-        foreach my $watcher_id (@$watcher_ids) {
-            my $watcher = new Bugzilla::User($watcher_id);
-            push (@watchers, Bugzilla::User::identity($watcher));
+        foreach my $watcher_id (@{$watcher_ids}) {
+            my $watcher = Bugzilla::User->new($watcher_id);
+            push (@watchers, $watcher->identity());
         }
 
         @watchers = sort { lc($a) cmp lc($b) } @watchers;
@@ -296,27 +305,19 @@ sub _page_describeuser {
     # XXX: this is just a temporary measure until points get back in a table, it
     # can be done here at not cost as numbers are already collected.
     my $points = log(1 + $comments) / log(10) +
-                 log(1 + $bugs_closed) / log(2) + 
+                 log(1 + $bugs_closed) / log(2) +
                  log(1 + $bugs_reported) / log(2);
     $vars->{'points'} = int($points + 0.5);
 }
 
-sub developed_products {
-    my $self = shift;
-
-    return [] unless $self->id;
+sub page {
+    my ($params) = @_;
+    my $vars = $params->{'vars'};
+    my $page = $params->{'page_id'};
 
-    # Get the list of products
-    my $groups = $self->{groups};
-    my $group_membership;
-    foreach my $group (@$groups) {
-         push (@$group_membership,
-               substr($group->name, 0, index($group->name, '_developers')))
-               if $group->name =~ /_developers$/;
+    if ($page =~ /^describeuser\./) {
+        _page_describeuser($vars);
     }
-
-    # return it
-    return $group_membership;
 }
 
 1;
diff --git a/DescribeUser/template/en/default/pages/describeuser.html.tmpl 
b/DescribeUser/template/en/default/pages/describeuser.html.tmpl
index d94da0c..0229006 100644
--- a/DescribeUser/template/en/default/pages/describeuser.html.tmpl
+++ b/DescribeUser/template/en/default/pages/describeuser.html.tmpl
@@ -39,7 +39,7 @@
   #   bug_id:      bug where patch is filed against
   #   product:     name of product in which the bug is filed against
   #   description: patch description
-  # 
+  #
   # assignedbugs:
   # needinfoassignedbugs:
   # needinforeporterbugs:
@@ -66,9 +66,9 @@
     [% END %]
 
     [% IF showuser != '' %]
-      for 
+      for
       [% IF user.in_group('editusers') || user.can_bless %]
-        <a href="editusers.cgi?action=edit&userid=[% userinfo.id 
+        <a href="editusers.cgi?action=edit&userid=[% userinfo.id
                 FILTER uri %]">
       [% END %]
       [% showuser FILTER html %]
@@ -120,7 +120,7 @@
 
     <ul>
     [% FOREACH product = developed_products %]
-      <li><a href="browse.cgi?product=[% product.name FILTER uri %]">[% product 
+      <li><a href="browse.cgi?product=[% product.name FILTER uri %]">[% product
           FILTER html %]</a></li>
     [% END %]
     </ul>
@@ -139,7 +139,7 @@
 
   [% IF watchers && watchers.size > 0 %]
     <h3>Watchers</h3>
-    
+
     <ul>
     [% FOREACH watcher = watchers %]
       <li>[% watcher FILTER html %]</li>
@@ -163,13 +163,13 @@
 
 [%### Bugs ###%]
   <p>
-    <h3><span>Open Issues: 
+    <h3><span>Open Issues:
       <a href="
         [% "buglist.cgi?bug_status=UNCONFIRMED&amp;bug_status=NEW" %]
         [% "&amp;bug_status=REOPENED&amp;bug_status=ASSIGNED" %]
         [% "&amp;emailassigned_to1=1&amp;emailtype1=exact&amp;email1=" %]
         [% userinfo.email FILTER uri %]">
-        <b>Assigned to [% displayname FILTER html %]</b></a> 
+        <b>Assigned to [% displayname FILTER html %]</b></a>
       [% "(the issue has been assigned to" %]
       [%+ displayname FILTER html %]
       [%+ "and it is not resolved or closed yet)" %]
@@ -207,7 +207,7 @@
         [% "buglist.cgi?bug_status=NEEDINFO&amp;emailreporter1=1&amp;emailtype1=" %]
         [% "exact&amp;email1=" %] [% userinfo.email FILTER uri %]">
         <b>Needinfo</b></a>
-      ([% displayname FILTER html %] 
+      ([% displayname FILTER html %]
       [%+ "reported this issue, it requires more information and you should " %]
       [% "provide it) " %]
     </span></h3>
@@ -236,13 +236,13 @@
   </p>
 
   <p>
-    <h3><span>Open Issues: 
+    <h3><span>Open Issues:
       <a href="
         [% "buglist.cgi?bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;" %]
         [% "bug_status=REOPENED&amp;emailreporter1=1&amp;emailtype1=exact" %]
         [% "&amp;email1=" %] [% userinfo.email FILTER uri %]">
         <b>New</b></a>
-      ([% displayname FILTER html %] 
+      ([% displayname FILTER html %]
       [%+ "reported it but nobody has accepted it yet)" %]
      </span></h3>
     <table border="0" cellpadding="3" cellspacing="0">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]