Commit 2f804027 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 505039: Use $user->is_timetracker instead of…

Bug 505039: Use $user->is_timetracker instead of $user->in_group(Bugzilla->params->{'timetrackinggroup'}) - Patch by XqueZme <xquezme@gmail.com> r/a=LpSolit
parent f7b1e5c5
...@@ -1221,10 +1221,9 @@ sub _check_deadline { ...@@ -1221,10 +1221,9 @@ sub _check_deadline {
my ($invocant, $date) = @_; my ($invocant, $date) = @_;
# Check time-tracking permissions. # Check time-tracking permissions.
my $tt_group = Bugzilla->params->{"timetrackinggroup"};
# deadline() returns '' instead of undef if no deadline is set. # deadline() returns '' instead of undef if no deadline is set.
my $current = ref $invocant ? ($invocant->deadline || undef) : undef; 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 # Validate entered deadline
$date = trim($date); $date = trim($date);
...@@ -1672,8 +1671,7 @@ sub _check_time { ...@@ -1672,8 +1671,7 @@ sub _check_time {
if (ref $invocant && $field ne 'work_time') { if (ref $invocant && $field ne 'work_time') {
$current = $invocant->$field; $current = $invocant->$field;
} }
my $tt_group = Bugzilla->params->{"timetrackinggroup"}; return $current unless Bugzilla->user->is_timetracker;
return $current unless $tt_group && Bugzilla->user->in_group($tt_group);
$time = trim($time) || 0; $time = trim($time) || 0;
ValidateTime($time, $field); ValidateTime($time, $field);
...@@ -2478,8 +2476,7 @@ sub actual_time { ...@@ -2478,8 +2476,7 @@ sub actual_time {
my ($self) = @_; my ($self) = @_;
return $self->{'actual_time'} if exists $self->{'actual_time'}; return $self->{'actual_time'} if exists $self->{'actual_time'};
if ( $self->{'error'} || if ( $self->{'error'} || !Bugzilla->user->is_timetracker ) {
!Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"}) ) {
$self->{'actual_time'} = undef; $self->{'actual_time'} = undef;
return $self->{'actual_time'}; return $self->{'actual_time'};
} }
...@@ -3125,8 +3122,7 @@ sub GetBugActivity { ...@@ -3125,8 +3122,7 @@ sub GetBugActivity {
|| $fieldname eq 'work_time' || $fieldname eq 'work_time'
|| $fieldname eq 'deadline') || $fieldname eq 'deadline')
{ {
$activity_visible = $activity_visible = Bugzilla->user->is_timetracker;
Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'}) ? 1 : 0;
} else { } else {
$activity_visible = 1; $activity_visible = 1;
} }
...@@ -3414,8 +3410,7 @@ sub check_can_change_field { ...@@ -3414,8 +3410,7 @@ sub check_can_change_field {
# Only users in the time-tracking group can change time-tracking fields. # Only users in the time-tracking group can change time-tracking fields.
if ( grep($_ eq $field, qw(deadline estimated_time remaining_time)) ) { if ( grep($_ eq $field, qw(deadline estimated_time remaining_time)) ) {
my $tt_group = Bugzilla->params->{timetrackinggroup}; if (!$user->is_timetracker) {
if (!$tt_group || !$user->in_group($tt_group)) {
$$PrivilegesRequired = 3; $$PrivilegesRequired = 3;
return 0; return 0;
} }
......
...@@ -667,7 +667,7 @@ if (trim($votes) && !grep($_ eq 'votes', @displaycolumns)) { ...@@ -667,7 +667,7 @@ if (trim($votes) && !grep($_ eq 'votes', @displaycolumns)) {
# Remove the timetracking columns if they are not a part of the group # 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) # (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 'estimated_time', @displaycolumns);
@displaycolumns = grep($_ ne 'remaining_time', @displaycolumns); @displaycolumns = grep($_ ne 'remaining_time', @displaycolumns);
@displaycolumns = grep($_ ne 'actual_time', @displaycolumns); @displaycolumns = grep($_ ne 'actual_time', @displaycolumns);
......
...@@ -77,7 +77,7 @@ if (Bugzilla::Keyword->any_exist) { ...@@ -77,7 +77,7 @@ if (Bugzilla::Keyword->any_exist) {
if (Bugzilla->has_flags) { if (Bugzilla->has_flags) {
push(@masterlist, "flagtypes.name"); 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", push(@masterlist, ("estimated_time", "remaining_time", "actual_time",
"percentage_complete", "deadline")); "percentage_complete", "deadline"));
} }
......
...@@ -93,7 +93,7 @@ $vars->{'closed_status'} = \@closed_status; ...@@ -93,7 +93,7 @@ $vars->{'closed_status'} = \@closed_status;
# Generate a list of fields that can be queried. # Generate a list of fields that can be queried.
my @fields = @{Bugzilla::Field->match({obsolete => 0})}; my @fields = @{Bugzilla::Field->match({obsolete => 0})};
# Exclude fields the user cannot query. # 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; @fields = grep { $_->name !~ /^(estimated_time|remaining_time|work_time|percentage_complete|deadline)$/ } @fields;
} }
$vars->{'field'} = \@fields; $vars->{'field'} = \@fields;
......
...@@ -1198,7 +1198,7 @@ sub process_bug { ...@@ -1198,7 +1198,7 @@ sub process_bug {
$err .= "No attachment ID specified, dropping attachment\n"; $err .= "No attachment ID specified, dropping attachment\n";
next; next;
} }
if (!$exporter->is_insider) && $att->{'isprivate'}){ if (!$exporter->is_insider && $att->{'isprivate'}) {
$err .= "Exporter not in insidergroup and attachment marked private.\n"; $err .= "Exporter not in insidergroup and attachment marked private.\n";
$err .= " Marking attachment public\n"; $err .= " Marking attachment public\n";
$att->{'isprivate'} = 0; $att->{'isprivate'} = 0;
...@@ -1251,7 +1251,7 @@ sub process_bug { ...@@ -1251,7 +1251,7 @@ sub process_bug {
# Insert longdesc and append any errors # Insert longdesc and append any errors
my $worktime = $bug_fields{'actual_time'} || 0.0; 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; $long_description .= "\n" . $comments;
if ($err) { if ($err) {
$long_description .= "\n$err\n"; $long_description .= "\n$err\n";
......
...@@ -552,7 +552,7 @@ foreach my $bug (@bug_objects) { ...@@ -552,7 +552,7 @@ foreach my $bug (@bug_objects) {
# status, so we should inform the user about that. # status, so we should inform the user about that.
if (!is_open_state($new_status) && $changes->{'remaining_time'}) { if (!is_open_state($new_status) && $changes->{'remaining_time'}) {
$vars->{'message'} = "remaining_time_zeroed" $vars->{'message'} = "remaining_time_zeroed"
if Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'}); if Bugzilla->user->is_timetracker;
} }
} }
......
...@@ -247,7 +247,7 @@ foreach my $val (editable_bug_fields()) { ...@@ -247,7 +247,7 @@ foreach my $val (editable_bug_fields()) {
push @chfields, $val; push @chfields, $val;
} }
if (Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'})) { if (Bugzilla->user->is_timetracker) {
push @chfields, "work_time"; push @chfields, "work_time";
} else { } else {
@chfields = grep($_ ne "estimated_time", @chfields); @chfields = grep($_ ne "estimated_time", @chfields);
......
...@@ -109,7 +109,7 @@ if ($cgi->param("field")) { ...@@ -109,7 +109,7 @@ if ($cgi->param("field")) {
@fieldlist = $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); @fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
} }
......
...@@ -232,6 +232,20 @@ sub get_inactive_bugs { ...@@ -232,6 +232,20 @@ sub get_inactive_bugs {
return $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 # Template code starts here
# #
...@@ -245,7 +259,7 @@ my $vars = {}; ...@@ -245,7 +259,7 @@ my $vars = {};
Bugzilla->switch_to_shadow_db(); Bugzilla->switch_to_shadow_db();
$user->in_group(Bugzilla->params->{"timetrackinggroup"}) $user->is_timetracker
|| ThrowUserError("auth_failure", {group => "time-tracking", || ThrowUserError("auth_failure", {group => "time-tracking",
action => "access", action => "access",
object => "timetracking_summaries"}); object => "timetracking_summaries"});
...@@ -301,16 +315,14 @@ if ($do_report) { ...@@ -301,16 +315,14 @@ if ($do_report) {
# Break dates apart into months if necessary; if not, we use the # Break dates apart into months if necessary; if not, we use the
# same @parts list to allow us to use a common codepath. # same @parts list to allow us to use a common codepath.
if ($monthly) { if ($monthly) {
# unfortunately it's not too easy to guess a start date, since # Calculate the earliest activity date if the user doesn't
# it depends on what bugs we're looking at. We risk bothering # specify a start date.
# the user here. XXX: perhaps run a query to see what the if (!$start_date) {
# earliest activity in longdescs for all bugs and use that as a $start_date = get_earliest_activity_date(\@bugs);
# start date. }
$start_date || ThrowUserError("illegal_date", {'date' => $start_date}); # Provide a default end date. Note that this differs in semantics
# we can, however, provide a default end date. Note that this # from the open-ended queries we use when start/end_date aren't
# differs in semantics from the open-ended queries we use when # provided -- and clock skews will make this evident!
# start/end_date aren't provided -- and clock skews will make
# this evident!
@parts = split_by_month($start_date, @parts = split_by_month($start_date,
$end_date || format_time(scalar localtime(time()), '%Y-%m-%d')); $end_date || format_time(scalar localtime(time()), '%Y-%m-%d'));
} else { } else {
......
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
</span> </span>
</div> </div>
[% IF user.in_group(Param('timetrackinggroup')) && [% IF user.is_timetracker &&
(comment.work_time > 0 || comment.work_time < 0) %] (comment.work_time > 0 || comment.work_time < 0) %]
<br> <br>
Additional hours worked: Additional hours worked:
......
...@@ -345,7 +345,7 @@ TUI_hide_default('expert_fields'); ...@@ -345,7 +345,7 @@ TUI_hide_default('expert_fields');
<td>&nbsp;</td> <td>&nbsp;</td>
[%# Calculate the number of rows we can use for flags %] [%# Calculate the number of rows we can use for flags %]
[% num_rows = 6 + (Param("useqacontact") ? 1 : 0) + [% num_rows = 6 + (Param("useqacontact") ? 1 : 0) +
(user.in_group(Param('timetrackinggroup')) ? 3 : 0) + (user.is_timetracker ? 3 : 0) +
(Param("usebugaliases") ? 1 : 0) (Param("usebugaliases") ? 1 : 0)
%] %]
...@@ -427,7 +427,7 @@ TUI_hide_default('expert_fields'); ...@@ -427,7 +427,7 @@ TUI_hide_default('expert_fields');
<td colspan="3">&nbsp;</td> <td colspan="3">&nbsp;</td>
</tr> </tr>
[% IF user.in_group(Param('timetrackinggroup')) %] [% IF user.is_timetracker %]
<tr> <tr>
<th>Estimated Hours:</th> <th>Estimated Hours:</th>
<td colspan="2"> <td colspan="2">
......
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
return text; return text;
} }
[% IF user.in_group(Param('timetrackinggroup')) %] [% IF user.is_timetracker %]
var fRemainingTime = [% bug.remaining_time %]; // holds the original value var fRemainingTime = [% bug.remaining_time %]; // holds the original value
function adjustRemainingTime() { function adjustRemainingTime() {
// subtracts time spent from remaining time // subtracts time spent from remaining time
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
[% PROCESS section_restrict_visibility %] [% PROCESS section_restrict_visibility %]
[% IF user.in_group(Param('timetrackinggroup')) %] [% IF user.is_timetracker %]
<br> <br>
[% PROCESS section_timetracking %] [% PROCESS section_timetracking %]
[% END %] [% END %]
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
[% PROCESS dependencies name = "blocked" %] [% PROCESS dependencies name = "blocked" %]
[% END %] [% END %]
[% IF user.in_group(Param("timetrackinggroup")) %] [% IF user.is_timetracker %]
<tr> <tr>
<th>Time tracking:</th> <th>Time tracking:</th>
<td colspan="3"> <td colspan="3">
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<commentid>[% c.id FILTER xml %]</commentid> <commentid>[% c.id FILTER xml %]</commentid>
<who name="[% c.author.name FILTER xml %]">[% c.author.email FILTER email FILTER xml %]</who> <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> <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> <work_time>[% PROCESS formattimeunit time_unit = c.work_time FILTER xml %]</work_time>
[% END %] [% END %]
<thetext>[% c.body_full FILTER xml %]</thetext> <thetext>[% c.body_full FILTER xml %]</thetext>
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
<th><label for="bug_status">Status:</label></th> <th><label for="bug_status">Status:</label></th>
<td colspan="3">[% PROCESS status_section %]</td> <td colspan="3">[% PROCESS status_section %]</td>
</tr> </tr>
[% IF user.in_group(Param("timetrackinggroup")) %] [% IF user.is_timetracker %]
<tr> <tr>
<th><label for="estimated_time">Estimated Hours:</label></th> <th><label for="estimated_time">Estimated Hours:</label></th>
<td> <td>
......
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
<input type="submit" value="XML" id="xml"> <input type="submit" value="XML" id="xml">
</form> </form>
[% IF user.in_group(Param('timetrackinggroup')) %] [% IF user.is_timetracker %]
<form method="post" action="summarize_time.cgi"> <form method="post" action="summarize_time.cgi">
<input type="hidden" name="id" value="[% buglist_joined FILTER html %]"> <input type="hidden" name="id" value="[% buglist_joined FILTER html %]">
<input type="submit" id="timesummary" value="Time Summary"> <input type="submit" id="timesummary" value="Time Summary">
......
...@@ -305,7 +305,7 @@ function doOnSelectProduct(selectmode) { ...@@ -305,7 +305,7 @@ function doOnSelectProduct(selectmode) {
[% END %] [% END %]
[%# Deadline %] [%# Deadline %]
[% IF user.in_group(Param("timetrackinggroup")) %] [% IF user.is_timetracker %]
<tr> <tr>
<th align="right"> <th align="right">
<label for="deadlinefrom" accesskey="l">Dead<u>l</u>ine</label>: <label for="deadlinefrom" accesskey="l">Dead<u>l</u>ine</label>:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment