From 2f804027b44c5790d4547f3161bff28266150bef Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Tue, 10 Nov 2009 16:31:47 +0000 Subject: Bug 505039: Use $user->is_timetracker instead of $user->in_group(Bugzilla->params->{'timetrackinggroup'}) - Patch by XqueZme r/a=LpSolit --- Bugzilla/Bug.pm | 15 ++++------- buglist.cgi | 2 +- colchange.cgi | 2 +- config.cgi | 2 +- importxml.pl | 4 +-- process_bug.cgi | 2 +- query.cgi | 2 +- show_bug.cgi | 2 +- summarize_time.cgi | 34 ++++++++++++++++-------- template/en/default/bug/comments.html.tmpl | 2 +- template/en/default/bug/create/create.html.tmpl | 4 +-- template/en/default/bug/edit.html.tmpl | 4 +-- template/en/default/bug/show-multiple.html.tmpl | 2 +- template/en/default/bug/show.xml.tmpl | 2 +- template/en/default/list/edit-multiple.html.tmpl | 2 +- template/en/default/list/list.html.tmpl | 2 +- template/en/default/search/form.html.tmpl | 2 +- 17 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 726316808..1c8b8b965 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -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; } diff --git a/buglist.cgi b/buglist.cgi index a8103a1e0..6b03b123d 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -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); diff --git a/colchange.cgi b/colchange.cgi index e28bccf04..6c2fa8090 100755 --- a/colchange.cgi +++ b/colchange.cgi @@ -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")); } diff --git a/config.cgi b/config.cgi index 2d8c2d92c..22e1dc78a 100755 --- a/config.cgi +++ b/config.cgi @@ -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; diff --git a/importxml.pl b/importxml.pl index f5385d178..c08f5c8b2 100755 --- a/importxml.pl +++ b/importxml.pl @@ -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"; diff --git a/process_bug.cgi b/process_bug.cgi index 504fcacc3..a4547ad6b 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -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; } } diff --git a/query.cgi b/query.cgi index fd18bab67..ba8979adc 100755 --- 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); diff --git a/show_bug.cgi b/show_bug.cgi index ddb41ffec..64d2e875f 100755 --- a/show_bug.cgi +++ b/show_bug.cgi @@ -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); } 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 { diff --git a/template/en/default/bug/comments.html.tmpl b/template/en/default/bug/comments.html.tmpl index 41436f9b2..9a04b7147 100644 --- a/template/en/default/bug/comments.html.tmpl +++ b/template/en/default/bug/comments.html.tmpl @@ -205,7 +205,7 @@ - [% IF user.in_group(Param('timetrackinggroup')) && + [% IF user.is_timetracker && (comment.work_time > 0 || comment.work_time < 0) %]
Additional hours worked: diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 1d3160563..3572ec372 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -345,7 +345,7 @@ TUI_hide_default('expert_fields');   [%# 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');   -[% IF user.in_group(Param('timetrackinggroup')) %] +[% IF user.is_timetracker %] Estimated Hours: diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 853ad7287..813e80cb2 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -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 %]
[% PROCESS section_timetracking %] [% END %] diff --git a/template/en/default/bug/show-multiple.html.tmpl b/template/en/default/bug/show-multiple.html.tmpl index 903d9d622..b6507b964 100644 --- a/template/en/default/bug/show-multiple.html.tmpl +++ b/template/en/default/bug/show-multiple.html.tmpl @@ -195,7 +195,7 @@ [% PROCESS dependencies name = "blocked" %] [% END %] - [% IF user.in_group(Param("timetrackinggroup")) %] + [% IF user.is_timetracker %] Time tracking: diff --git a/template/en/default/bug/show.xml.tmpl b/template/en/default/bug/show.xml.tmpl index f4ad0ceda..31e56d299 100644 --- a/template/en/default/bug/show.xml.tmpl +++ b/template/en/default/bug/show.xml.tmpl @@ -71,7 +71,7 @@ [% c.id FILTER xml %] [% c.author.email FILTER email FILTER xml %] [% c.creation_ts FILTER time("%Y-%m-%d %T %z") FILTER xml %] - [% IF user.in_group(Param('timetrackinggroup')) && (c.work_time - 0 != 0) %] + [% IF user.is_timetracker && (c.work_time - 0 != 0) %] [% PROCESS formattimeunit time_unit = c.work_time FILTER xml %] [% END %] [% c.body_full FILTER xml %] diff --git a/template/en/default/list/edit-multiple.html.tmpl b/template/en/default/list/edit-multiple.html.tmpl index 05d534976..528d1bd68 100644 --- a/template/en/default/list/edit-multiple.html.tmpl +++ b/template/en/default/list/edit-multiple.html.tmpl @@ -140,7 +140,7 @@ [% PROCESS status_section %] - [% IF user.in_group(Param("timetrackinggroup")) %] + [% IF user.is_timetracker %] diff --git a/template/en/default/list/list.html.tmpl b/template/en/default/list/list.html.tmpl index a3e3a767a..6d7f80585 100644 --- a/template/en/default/list/list.html.tmpl +++ b/template/en/default/list/list.html.tmpl @@ -198,7 +198,7 @@ - [% IF user.in_group(Param('timetrackinggroup')) %] + [% IF user.is_timetracker %]
diff --git a/template/en/default/search/form.html.tmpl b/template/en/default/search/form.html.tmpl index a237fd347..c52f5dcc5 100644 --- a/template/en/default/search/form.html.tmpl +++ b/template/en/default/search/form.html.tmpl @@ -305,7 +305,7 @@ function doOnSelectProduct(selectmode) { [% END %] [%# Deadline %] - [% IF user.in_group(Param("timetrackinggroup")) %] + [% IF user.is_timetracker %] : -- cgit v1.2.3-24-g4f1b