]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 505039: Use $user->is_timetracker instead of $user->in_group(Bugzilla->params...
authorlpsolit%gmail.com <>
Tue, 10 Nov 2009 16:31:47 +0000 (16:31 +0000)
committerlpsolit%gmail.com <>
Tue, 10 Nov 2009 16:31:47 +0000 (16:31 +0000)
17 files changed:
Bugzilla/Bug.pm
buglist.cgi
colchange.cgi
config.cgi
importxml.pl
process_bug.cgi
query.cgi
show_bug.cgi
summarize_time.cgi
template/en/default/bug/comments.html.tmpl
template/en/default/bug/create/create.html.tmpl
template/en/default/bug/edit.html.tmpl
template/en/default/bug/show-multiple.html.tmpl
template/en/default/bug/show.xml.tmpl
template/en/default/list/edit-multiple.html.tmpl
template/en/default/list/list.html.tmpl
template/en/default/search/form.html.tmpl

index 726316808ad0019ca81db5dbbb24f241c2d27e78..1c8b8b9652753e2e7e048798e922fe0c079ead42 100644 (file)
@@ -1221,10 +1221,9 @@ sub _check_deadline {
     my ($invocant, $date) = @_;
     
     # Check time-tracking permissions.
-    my $tt_group = Bugzilla->params->{"timetrackinggroup"};
     # deadline() returns '' instead of undef if no deadline is set.
     my $current = ref $invocant ? ($invocant->deadline || undef) : undef;
-    return $current unless $tt_group && Bugzilla->user->in_group($tt_group);
+    return $current unless Bugzilla->user->is_timetracker;
     
     # Validate entered deadline
     $date = trim($date);
@@ -1672,8 +1671,7 @@ sub _check_time {
     if (ref $invocant && $field ne 'work_time') {
         $current = $invocant->$field;
     }
-    my $tt_group = Bugzilla->params->{"timetrackinggroup"};
-    return $current unless $tt_group && Bugzilla->user->in_group($tt_group);
+    return $current unless Bugzilla->user->is_timetracker;
     
     $time = trim($time) || 0;
     ValidateTime($time, $field);
@@ -2478,8 +2476,7 @@ sub actual_time {
     my ($self) = @_;
     return $self->{'actual_time'} if exists $self->{'actual_time'};
 
-    if ( $self->{'error'} || 
-         !Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"}) ) {
+    if ( $self->{'error'} || !Bugzilla->user->is_timetracker ) {
         $self->{'actual_time'} = undef;
         return $self->{'actual_time'};
     }
@@ -3125,8 +3122,7 @@ sub GetBugActivity {
             || $fieldname eq 'work_time'
             || $fieldname eq 'deadline')
         {
-            $activity_visible = 
-                Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'}) ? 1 : 0;
+            $activity_visible = Bugzilla->user->is_timetracker;
         } else {
             $activity_visible = 1;
         }
@@ -3414,8 +3410,7 @@ sub check_can_change_field {
     
     # Only users in the time-tracking group can change time-tracking fields.
     if ( grep($_ eq $field, qw(deadline estimated_time remaining_time)) ) {
-        my $tt_group = Bugzilla->params->{timetrackinggroup};
-        if (!$tt_group || !$user->in_group($tt_group)) {
+        if (!$user->is_timetracker) {
             $$PrivilegesRequired = 3;
             return 0;
         }
index a8103a1e0f95aa841dae03b1b021f50974c523b6..6b03b123d71708df2fb98919d5e2743de4a2ef11 100755 (executable)
@@ -667,7 +667,7 @@ if (trim($votes) && !grep($_ eq 'votes', @displaycolumns)) {
 
 # Remove the timetracking columns if they are not a part of the group
 # (happens if a user had access to time tracking and it was revoked/disabled)
-if (!Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
+if (!Bugzilla->user->is_timetracker) {
    @displaycolumns = grep($_ ne 'estimated_time', @displaycolumns);
    @displaycolumns = grep($_ ne 'remaining_time', @displaycolumns);
    @displaycolumns = grep($_ ne 'actual_time', @displaycolumns);
index e28bccf0437ef420d6e5007531382a4bc3d89f93..6c2fa8090b772d6df1d61aba3674063d75fb3e62 100755 (executable)
@@ -77,7 +77,7 @@ if (Bugzilla::Keyword->any_exist) {
 if (Bugzilla->has_flags) {
     push(@masterlist, "flagtypes.name");
 }
-if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
+if (Bugzilla->user->is_timetracker) {
     push(@masterlist, ("estimated_time", "remaining_time", "actual_time",
                        "percentage_complete", "deadline")); 
 }
index 2d8c2d92cee18bae532c2b5528bdfeb285f54b0b..22e1dc78a7fd9ab39eabf5c425b5bcaf88727e21 100755 (executable)
@@ -93,7 +93,7 @@ $vars->{'closed_status'} = \@closed_status;
 # Generate a list of fields that can be queried.
 my @fields = @{Bugzilla::Field->match({obsolete => 0})};
 # Exclude fields the user cannot query.
-if (!Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'})) {
+if (!Bugzilla->user->is_timetracker) {
     @fields = grep { $_->name !~ /^(estimated_time|remaining_time|work_time|percentage_complete|deadline)$/ } @fields;
 }
 $vars->{'field'} = \@fields;
index f5385d178337e1d37fea620d15930a8127cba05e..c08f5c8b2dae89f5e8cd1832f4a4f863b3d48cf5 100755 (executable)
@@ -1198,7 +1198,7 @@ sub process_bug {
             $err .= "No attachment ID specified, dropping attachment\n";
             next;
         }
-        if (!$exporter->is_insider) && $att->{'isprivate'}){
+        if (!$exporter->is_insider && $att->{'isprivate'}) {
             $err .= "Exporter not in insidergroup and attachment marked private.\n";
             $err .= "   Marking attachment public\n";
             $att->{'isprivate'} = 0;
@@ -1251,7 +1251,7 @@ sub process_bug {
 
     # Insert longdesc and append any errors
     my $worktime = $bug_fields{'actual_time'} || 0.0;
-    $worktime = 0.0 if (!$exporter->in_group($params->{'timetrackinggroup'}));
+    $worktime = 0.0 if (!$exporter->is_timetracker);
     $long_description .= "\n" . $comments;
     if ($err) {
         $long_description .= "\n$err\n";
index 504fcacc31d8e3e0c015e62f4cb5f5a78f322cdd..a4547ad6b84cb1c5bd7ddd64705ec9c561f2168f 100755 (executable)
@@ -552,7 +552,7 @@ foreach my $bug (@bug_objects) {
         # status, so we should inform the user about that.
         if (!is_open_state($new_status) && $changes->{'remaining_time'}) {
             $vars->{'message'} = "remaining_time_zeroed"
-              if Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'});
+              if Bugzilla->user->is_timetracker;
         }
     }
 
index fd18bab67a08ea1a2968f0a88cc95418ceac642a..ba8979adc3c5092496fe98868e319eba9156959b 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -247,7 +247,7 @@ foreach my $val (editable_bug_fields()) {
     push @chfields, $val;
 }
 
-if (Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'})) {
+if (Bugzilla->user->is_timetracker) {
     push @chfields, "work_time";
 } else {
     @chfields = grep($_ ne "estimated_time", @chfields);
index ddb41ffec341742cbb9a2cb32ffe7ff9f81b03db..64d2e875fb3e66c033535c1ab6a770cd39008518 100755 (executable)
@@ -109,7 +109,7 @@ if ($cgi->param("field")) {
     @fieldlist = $cgi->param("field");
 }
 
-unless (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
+unless (Bugzilla->user->is_timetracker) {
     @fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
 }
 
index 0330f9dcff17a590ed98800e89d23755e3c0135d..6f9580ac29edc94dcf06e24478ee8eec89d53f65 100755 (executable)
@@ -232,6 +232,20 @@ sub get_inactive_bugs {
     return $bugs;
 }
 
+# Return 1st day of the month of the earliest activity date for a given list of bugs.
+sub get_earliest_activity_date {
+    my ($bugids) = @_;
+    my $dbh = Bugzilla->dbh;
+
+    my ($date) = $dbh->selectrow_array(
+        'SELECT ' . $dbh->sql_date_format('MIN(bug_when)', '%Y-%m-01')
+       . ' FROM longdescs
+          WHERE ' . $dbh->sql_in('bug_id', $bugids)
+                  . ' AND work_time > 0');
+
+    return $date;
+}
+
 #
 # Template code starts here
 #
@@ -245,7 +259,7 @@ my $vars = {};
 
 Bugzilla->switch_to_shadow_db();
 
-$user->in_group(Bugzilla->params->{"timetrackinggroup"})
+$user->is_timetracker
     || ThrowUserError("auth_failure", {group  => "time-tracking",
                                        action => "access",
                                        object => "timetracking_summaries"});
@@ -301,16 +315,14 @@ if ($do_report) {
     # Break dates apart into months if necessary; if not, we use the
     # same @parts list to allow us to use a common codepath.
     if ($monthly) {
-        # unfortunately it's not too easy to guess a start date, since
-        # it depends on what bugs we're looking at. We risk bothering
-        # the user here. XXX: perhaps run a query to see what the
-        # earliest activity in longdescs for all bugs and use that as a
-        # start date.
-        $start_date || ThrowUserError("illegal_date", {'date' => $start_date});
-        # we can, however, provide a default end date. Note that this
-        # differs in semantics from the open-ended queries we use when
-        # start/end_date aren't provided -- and clock skews will make
-        # this evident!
+        # Calculate the earliest activity date if the user doesn't
+        # specify a start date.
+        if (!$start_date) {
+            $start_date = get_earliest_activity_date(\@bugs);
+        }
+        # Provide a default end date. Note that this differs in semantics
+        # from the open-ended queries we use when start/end_date aren't
+        # provided -- and clock skews will make this evident!
         @parts = split_by_month($start_date, 
                                 $end_date || format_time(scalar localtime(time()), '%Y-%m-%d'));
     } else {
index 41436f9b2afdbbc9fc6a8c4413006c8dd0505962..9a04b71470a47a4fd7c84ac455d935c641a54b1f 100644 (file)
         </span>
       </div>
 
-      [% IF user.in_group(Param('timetrackinggroup')) &&
+      [% IF user.is_timetracker &&
             (comment.work_time > 0 || comment.work_time < 0) %]
          <br>
          Additional hours worked: 
index 1d31605636846b55a9f897a761ebee226e8abfb9..3572ec372414167a7255c66065494bc472ab540d 100644 (file)
@@ -345,7 +345,7 @@ TUI_hide_default('expert_fields');
     <td>&nbsp;</td>
     [%# Calculate the number of rows we can use for flags %]
     [% num_rows = 6 + (Param("useqacontact") ? 1 : 0) +
-                      (user.in_group(Param('timetrackinggroup')) ? 3 : 0) +
+                      (user.is_timetracker ? 3 : 0) +
                       (Param("usebugaliases") ? 1 : 0)
     %]
 
@@ -427,7 +427,7 @@ TUI_hide_default('expert_fields');
     <td colspan="3">&nbsp;</td>
   </tr>
 
-[% IF user.in_group(Param('timetrackinggroup')) %]
+[% IF user.is_timetracker %]
   <tr>
     <th>Estimated Hours:</th>
     <td colspan="2">
index 853ad72874861715118e1e8b6717eafaeb61fe85..813e80cb2c3a47275aa52a0b32dc678d4237d970 100644 (file)
       return text;
   }
 
-[% IF user.in_group(Param('timetrackinggroup')) %]
+[% IF user.is_timetracker %]
   var fRemainingTime = [% bug.remaining_time %]; // holds the original value
   function adjustRemainingTime() {
       // subtracts time spent from remaining time
 
   
   [% PROCESS section_restrict_visibility %]
-  [% IF user.in_group(Param('timetrackinggroup')) %]
+  [% IF user.is_timetracker %]
     <br>
     [% PROCESS section_timetracking %]
   [% END %]
index 903d9d62278b7951d792d3b6f6fc969782c471ad..b6507b964ae59f380b66338484683ed22c4362fe 100644 (file)
       [% PROCESS dependencies name = "blocked"  %]
     [% END %]
 
-    [% IF user.in_group(Param("timetrackinggroup")) %]
+    [% IF user.is_timetracker %]
       <tr>
         <th>Time tracking:</th>
         <td colspan="3">
index f4ad0ceda2f9bb14dc292ea7303d89778b9a6805..31e56d299dd4369cec7b15496f14983e161099b1 100644 (file)
@@ -71,7 +71,7 @@
             <commentid>[% c.id FILTER xml %]</commentid>
             <who name="[% c.author.name FILTER xml %]">[% c.author.email FILTER email FILTER xml %]</who>
             <bug_when>[% c.creation_ts FILTER time("%Y-%m-%d %T %z") FILTER xml %]</bug_when>
-            [% IF user.in_group(Param('timetrackinggroup')) && (c.work_time - 0 != 0) %]
+            [% IF user.is_timetracker && (c.work_time - 0 != 0) %]
               <work_time>[% PROCESS formattimeunit time_unit = c.work_time FILTER xml %]</work_time>
             [% END %]
             <thetext>[% c.body_full FILTER xml %]</thetext>
index 05d534976a278ab4a0982588ec985bb609a3e48a..528d1bd68ef6a7dc7229631467cece1ab6476df0 100644 (file)
     <th><label for="bug_status">Status:</label></th>
     <td colspan="3">[% PROCESS status_section %]</td>
   </tr>
-  [% IF user.in_group(Param("timetrackinggroup")) %]
+  [% IF user.is_timetracker %]
     <tr>
       <th><label for="estimated_time">Estimated Hours:</label></th>
       <td>
index a3e3a767adf0acd86fa8c9b57fd65afbe3605295..6d7f805855a2fce29f6a049effded382a878f79d 100644 (file)
             <input type="submit" value="XML" id="xml">
         </form>
 
-        [% IF user.in_group(Param('timetrackinggroup')) %]
+        [% IF user.is_timetracker %]
           <form method="post" action="summarize_time.cgi">
             <input type="hidden" name="id" value="[% buglist_joined FILTER html %]">
             <input type="submit" id="timesummary" value="Time Summary">
index a237fd347968e0ab147928d703eb7ed3fc2e683a..c52f5dcc56a0848fac25141f430782e78370ab4f 100644 (file)
@@ -305,7 +305,7 @@ function doOnSelectProduct(selectmode) {
   [% END %]
 
   [%# Deadline %]
-  [% IF user.in_group(Param("timetrackinggroup")) %]
+  [% IF user.is_timetracker %]
     <tr>
       <th align="right">
         <label for="deadlinefrom" accesskey="l">Dead<u>l</u>ine</label>: