summaryrefslogtreecommitdiffstats
path: root/summarize_time.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'summarize_time.cgi')
-rwxr-xr-xsummarize_time.cgi34
1 files changed, 23 insertions, 11 deletions
diff --git a/summarize_time.cgi b/summarize_time.cgi
index 0330f9dcf..6f9580ac2 100755
--- a/summarize_time.cgi
+++ b/summarize_time.cgi
@@ -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 {