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);
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);
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'};
}
|| $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;
}
# 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;
}
# 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);
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"));
}
# 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;
$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;
# 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";
# 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;
}
}
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);
@fieldlist = $cgi->param("field");
}
-unless (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
+unless (Bugzilla->user->is_timetracker) {
@fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
}
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
#
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"});
# 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 {
</span>
</div>
- [% IF user.in_group(Param('timetrackinggroup')) &&
+ [% IF user.is_timetracker &&
(comment.work_time > 0 || comment.work_time < 0) %]
<br>
Additional hours worked:
<td> </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)
%]
<td colspan="3"> </td>
</tr>
-[% IF user.in_group(Param('timetrackinggroup')) %]
+[% IF user.is_timetracker %]
<tr>
<th>Estimated Hours:</th>
<td colspan="2">
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 %]
[% PROCESS dependencies name = "blocked" %]
[% END %]
- [% IF user.in_group(Param("timetrackinggroup")) %]
+ [% IF user.is_timetracker %]
<tr>
<th>Time tracking:</th>
<td colspan="3">
<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>
<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>
<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">
[% 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>: