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 {
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;
}
......
......@@ -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);
......
......@@ -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"));
}
......
......@@ -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;
......
......@@ -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";
......
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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 {
......
......@@ -205,7 +205,7 @@
</span>
</div>
[% IF user.in_group(Param('timetrackinggroup')) &&
[% IF user.is_timetracker &&
(comment.work_time > 0 || comment.work_time < 0) %]
<br>
Additional hours worked:
......
......@@ -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">
......
......@@ -115,7 +115,7 @@
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
......@@ -213,7 +213,7 @@
[% PROCESS section_restrict_visibility %]
[% IF user.in_group(Param('timetrackinggroup')) %]
[% IF user.is_timetracker %]
<br>
[% PROCESS section_timetracking %]
[% END %]
......
......@@ -195,7 +195,7 @@
[% PROCESS dependencies name = "blocked" %]
[% END %]
[% IF user.in_group(Param("timetrackinggroup")) %]
[% IF user.is_timetracker %]
<tr>
<th>Time tracking:</th>
<td colspan="3">
......
......@@ -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>
......
......@@ -140,7 +140,7 @@
<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>
......
......@@ -198,7 +198,7 @@
<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">
......
......@@ -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>:
......
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