From fc6aa3c91fdcb1d9f11d05d9f13d1da8fce15b45 Mon Sep 17 00:00:00 2001 From: "gerv%gerv.net" <> Date: Sun, 24 Mar 2002 01:58:36 +0000 Subject: Bug 110012 - show_bug templatisation. r=bbaetz, afranke. --- bug_form.pl | 825 +++++++++++++++++++----------------------------------------- 1 file changed, 257 insertions(+), 568 deletions(-) (limited to 'bug_form.pl') diff --git a/bug_form.pl b/bug_form.pl index 6d52011c7..e51107bfb 100644 --- a/bug_form.pl +++ b/bug_form.pl @@ -28,604 +28,293 @@ use RelationSet; # Use the Attachment module to display attachments for the bug. use Attachment; -# Shut up misguided -w warnings about "used only once". For some reason, -# "use vars" chokes on me when I try it here. - -sub bug_form_pl_sillyness { - my $zz; - $zz = %::FORM; - $zz = %::components; - $zz = %::proddesc; - $zz = %::prodmaxvotes; - $zz = %::versions; - $zz = @::enterable_products; - $zz = @::legal_keywords; - $zz = @::legal_opsys; - $zz = @::legal_platform; - $zz = @::legal_priority; - $zz = @::settable_resolution; - $zz = @::legal_severity; - $zz = %::target_milestone; -} - -my $loginok = quietly_check_login(); - -my $id = $::FORM{'id'}; - -my $query = " -select - bugs.bug_id, - product, - version, - rep_platform, - op_sys, - bug_status, - resolution, - priority, - bug_severity, - component, - assigned_to, - reporter, - bug_file_loc, - short_desc, - target_milestone, - qa_contact, - status_whiteboard, - date_format(creation_ts,'%Y-%m-%d %H:%i'), - groupset, - delta_ts, - sum(votes.count) -from bugs left join votes using(bug_id) -where bugs.bug_id = $id -group by bugs.bug_id"; - -SendSQL($query); -my %bug; -my @row; -@row = FetchSQLData(); -my $count = 0; -foreach my $field ("bug_id", "product", "version", "rep_platform", - "op_sys", "bug_status", "resolution", "priority", - "bug_severity", "component", "assigned_to", "reporter", - "bug_file_loc", "short_desc", "target_milestone", - "qa_contact", "status_whiteboard", "creation_ts", - "groupset", "delta_ts", "votes") { - $bug{$field} = shift @row; - if (!defined $bug{$field}) { - $bug{$field} = ""; +sub show_bug { + # Shut up misguided -w warnings about "used only once". For some reason, + # "use vars" chokes on me when I try it here. + sub bug_form_pl_sillyness { + my $zz; + $zz = %::FORM; + $zz = %::proddesc; + $zz = %::prodmaxvotes; + $zz = @::enterable_products; + $zz = @::settable_resolution; + $zz = $::unconfirmedstate; + $zz = $::milestoneurl; + $zz = $::template; + $zz = $::vars; + $zz = @::legal_priority; + $zz = @::legal_platform; + $zz = @::legal_severity; + $zz = @::legal_bug_status; + $zz = @::target_milestone; + $zz = @::components; + $zz = @::legal_keywords; + $zz = @::versions; + $zz = @::legal_opsys; } - $count++; -} - -my $assignedtoid = $bug{'assigned_to'}; -my $reporterid = $bug{'reporter'}; -my $qacontactid = $bug{'qa_contact'}; - -$bug{'assigned_to_email'} = DBID_to_name($assignedtoid); -$bug{'assigned_to'} = DBID_to_real_or_loginname($bug{'assigned_to'}); -$bug{'reporter'} = DBID_to_real_or_loginname($bug{'reporter'}); - -print qq{
\n}; - -# foreach my $i (sort(keys(%bug))) { -# my $q = value_quote($bug{$i}); -# print qq{\n}; -# } - -$bug{'long_desc'} = GetLongDescriptionAsHTML($id); -my $longdesclength = length($bug{'long_desc'}); - -GetVersionTable(); - - -# -# These should be read from the database ... -# - -my $platform_popup = make_options(\@::legal_platform, $bug{'rep_platform'}); -my $priority_popup = make_options(\@::legal_priority, $bug{'priority'}); -my $sev_popup = make_options(\@::legal_severity, $bug{'bug_severity'}); - - -my $component_popup = make_options($::components{$bug{'product'}}, - $bug{'component'}); - -my $ccSet = new RelationSet; -$ccSet->mergeFromDB("select who from cc where bug_id=$id"); -my @ccList = $ccSet->toArrayOfStrings(); -my $cc_element = ""; -if (scalar(@ccList) > 0) { - $cc_element = "
\n" . - "Remove selected CCs
\n"; -} - -my $URL = value_quote($bug{'bug_file_loc'}); - -if (defined $URL && $URL ne "none" && $URL ne "NULL" && $URL ne "") { - $URL = "URL:"; -} else { - $URL = "URL:"; -} - -# -# Make a list of products the user has access to -# - -my (@prodlist, $product_popup); -my $seen_currProd = 0; - -foreach my $p (@::enterable_products) { - if ($p eq $bug{'product'}) { - # if it's the product the bug is already in, it's ALWAYS in - # the popup, period, whether the user can see it or not, and - # regardless of the disallownew setting. - $seen_currProd = 1; - push(@prodlist, $p); - next; + # Use templates + my $template = $::template; + my $vars = $::vars; + + $vars->{'GetBugLink'} = \&GetBugLink; + $vars->{'quoteUrls'} = \"eUrls, + $vars->{'lsearch'} = \&lsearch, + $vars->{'header_done'} = (@_), + + quietly_check_login(); + + my $id = $::FORM{'id'}; + + if (!defined($id)) { + $template->process("show/choose_bug.html.tmpl", $vars) + || DisplayError("Template process failed: " . $template->error()); + exit; } - if(Param("usebuggroupsentry") - && GroupExists($p) - && !UserInGroup($p)) + + my %user; + my %bug; + + # Populate the bug hash with the info we get directly from the DB. + my $query = " + SELECT bugs.bug_id, product, version, rep_platform, + op_sys, bug_status, resolution, priority, + bug_severity, component, assigned_to, reporter, + bug_file_loc, short_desc, target_milestone, + qa_contact, status_whiteboard, + date_format(creation_ts,'%Y-%m-%d %H:%i'), + groupset, delta_ts, sum(votes.count) + FROM bugs LEFT JOIN votes USING(bug_id) + WHERE bugs.bug_id = $id + GROUP BY bugs.bug_id"; + + SendSQL($query); + + my $value; + my @row = FetchSQLData(); + foreach my $field ("bug_id", "product", "version", "rep_platform", + "op_sys", "bug_status", "resolution", "priority", + "bug_severity", "component", "assigned_to", "reporter", + "bug_file_loc", "short_desc", "target_milestone", + "qa_contact", "status_whiteboard", "creation_ts", + "groupset", "delta_ts", "votes") { - # If we're using bug groups to restrict entry on products, and - # this product has a bug group, and the user is not in that - # group, we don't want to include that product in this list. - next; + $value = shift(@row); + $bug{$field} = defined($value) ? $value : ""; } - push(@prodlist, $p); -} - -# The current product is part of the popup, even if new bugs are no longer -# allowed for that product -if (!$seen_currProd) { - push (@prodlist, $bug{'product'}); - @prodlist = sort @prodlist; -} -# If the user has access to multiple products, display a popup, otherwise -# display the current product. + # General arrays of info about the database state + GetVersionTable(); + + # Fiddle the product list. + my $seen_curr_prod; + my @prodlist; + + foreach my $product (@::enterable_products) { + if ($product eq $bug{'product'}) { + # if it's the product the bug is already in, it's ALWAYS in + # the popup, period, whether the user can see it or not, and + # regardless of the disallownew setting. + $seen_curr_prod = 1; + push(@prodlist, $product); + next; + } -if (1 < @prodlist) { - $product_popup = ""; -} -else { - $product_popup = $bug{'product'} . - ""; -} + if (Param("usebuggroupsentry") + && GroupExists($product) + && !UserInGroup($product)) + { + # If we're using bug groups to restrict entry on products, and + # this product has a bug group, and the user is not in that + # group, we don't want to include that product in this list. + next; + } -print " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "; - -if (Param("usetargetmilestone")) { - my $url = ""; - if (defined $::milestoneurl{$bug{'product'}}) { - $url = $::milestoneurl{$bug{'product'}}; + push(@prodlist, $product); } - if ($url eq "") { - $url = "notargetmilestone.html"; - } - if ($bug{'target_milestone'} eq "") { - $bug{'target_milestone'} = " "; - } - print " - - - "; -} else { print ""; } - -print " -"; - -if (Param("useqacontact")) { - my $name = $bug{'qa_contact'} > 0 ? DBID_to_name($bug{'qa_contact'}) : ""; - print " - - - "; -} - - -print " - - - - - "; - -if (Param("usestatuswhiteboard")) { - print " - - - "; -} -if (@::legal_keywords) { - SendSQL("SELECT keyworddefs.name - FROM keyworddefs, keywords - WHERE keywords.bug_id = $id AND keyworddefs.id = keywords.keywordid - ORDER BY keyworddefs.name"); - my @list; - while (MoreSQLData()) { - push(@list, FetchOneColumn()); + # The current product is part of the popup, even if new bugs are no longer + # allowed for that product + if (!$seen_curr_prod) { + push (@prodlist, $bug{'product'}); + @prodlist = sort @prodlist; } - my $value = value_quote(join(', ', @list)); - print qq{ - - - -}; -} -print "
Bug#:$bug{'bug_id'} Platform: Reporter:$bug{'reporter'}
Product:$product_popup OS: Add CC:
Component: Version: CC: $cc_element
Status:$bug{'bug_status'} Priority: 
Resolution:$bug{'resolution'} Severity: 
Assigned To: - $bug{'assigned_to'} Target Milestone:  
QA Contact: - -
$URL - -
Summary: - -
Status Whiteboard: - -
Keywords: -
\n"; + $vars->{'product'} = \@prodlist; + $vars->{'rep_platform'} = \@::legal_platform; + $vars->{'priority'} = \@::legal_priority; + $vars->{'bug_severity'} = \@::legal_severity; + $vars->{'op_sys'} = \@::legal_opsys; + $vars->{'bug_status'} = \@::legal_bug_status; + + # Hack - this array contains "" for some reason. See bug 106589. + shift @::settable_resolution; + $vars->{'resolution'} = \@::settable_resolution; + + $vars->{'component_'} = $::components{$bug{'product'}}; + $vars->{'version'} = $::versions{$bug{'product'}}; + $vars->{'target_milestone'} = $::target_milestone{$bug{'product'}}; + $bug{'milestoneurl'} = $::milestoneurl{$bug{'product'}} || + "notargetmilestone.html"; + + $vars->{'use_votes'} = $::prodmaxvotes{$bug{'product'}}; + + # Add additional, calculated fields to the bug hash + if (@::legal_keywords) { + $vars->{'use_keywords'} = 1; + + SendSQL("SELECT keyworddefs.name + FROM keyworddefs, keywords + WHERE keywords.bug_id = $id + AND keyworddefs.id = keywords.keywordid + ORDER BY keyworddefs.name"); + my @keywords; + while (MoreSQLData()) { + push(@keywords, FetchOneColumn()); + } + + $bug{'keywords'} = \@keywords; + } -# Display attachments for this bug (if any). -&Attachment::list($id); + # Attachments + $bug{'attachments'} = Attachment::query($id); -sub EmitDependList { - my ($desc, $myfield, $targetfield) = (@_); - print "$desc:"; + # Dependencies my @list; - SendSQL("select $targetfield from dependencies where - $myfield = $id order by $targetfield"); + SendSQL("SELECT dependson FROM dependencies WHERE + blocked = $id ORDER BY dependson"); while (MoreSQLData()) { - my ($i) = (FetchSQLData()); + my ($i) = FetchSQLData(); push(@list, $i); - print GetBugLink($i, $i); - print " "; - } - print "\n"; -} - -if (Param("usedependencies")) { - print "\n"; - EmitDependList("Bug $id depends on", "blocked", "dependson"); - print qq{ -"; - EmitDependList("Bug $id blocks", "dependson", "blocked"); - print "
Show dependency tree -}; - if (Param("webdotbase") ne "") { - print qq{ -
Show dependency graph -}; } - print "
\n"; -} -if ($::prodmaxvotes{$bug{'product'}}) { - print qq{ - - - -
Votes: -$bug{'votes'}    -Show votes for this bug    -Vote for this bug -
-}; -} + $bug{'dependson'} = \@list; -print " -
-Additional Comments: -
-
"; - - -if ($::usergroupset ne '0' || $bug{'groupset'} ne '0') { - SendSQL("select bit, name, description, (bit & $bug{'groupset'} != 0), " . - "(bit & $::usergroupset != 0) from groups where isbuggroup != 0 " . - # Include active groups as well as inactive groups to which - # the bug already belongs. This way the bug can be removed - # from an inactive group but can only be added to active ones. - "and ((isactive = 1 and (bit & $::usergroupset != 0)) or " . - "(bit & $bug{'groupset'} != 0)) " . - "order by description"); - # We only print out a header bit for this section if there are any - # results. - my $groupFound = 0; - my $inAllGroups = 1; + my @list2; + SendSQL("SELECT blocked FROM dependencies WHERE + dependson = $id ORDER BY blocked"); while (MoreSQLData()) { - my ($bit, $name, $description, $ison, $ingroup) = (FetchSQLData()); - # For product groups, we only want to display the checkbox if either - # (1) The bit is already set, or - # (2) The user is in the group, but either: - # (a) The group is a product group for the current product, or - # (b) The group name isn't a product name - # This measns that all product groups will be skipped, but non-product - # bug groups will still be displayed. - if($ison || ($ingroup && (($name eq $bug{'product'}) || - (!defined $::proddesc{$name})))) { - if(!$groupFound) { - print "
Only users in the selected groups can view this bug:
\n"; - print "(Unchecking all boxes makes this a public bug.)

\n"; - $groupFound = 1; - } - if(!$ingroup) { - $inAllGroups = 0; - } - # Modifying this to use checkboxes instead - my $checked = $ison ? " CHECKED" : ""; - my $disabled = $ingroup ? "" : " DISABLED=\"disabled\""; - # indent these a bit - print "    "; - print "\n"; - print "$description
\n"; - } - } - if (!$inAllGroups) { - print "Only members of a group can change the visibility of a bug for that group
"; + my ($i) = FetchSQLData(); + push(@list2, $i); } - # If the bug is restricted to a group, display checkboxes that allow - # the user to set whether or not the reporter - # and cc list can see the bug even if they are not members of all - # groups to which the bug is restricted. - if ( $bug{'groupset'} != 0 ) { - # Determine whether or not the bug is always accessible by the reporter, - # QA contact, and/or users on the cc: list. - SendSQL("SELECT reporter_accessible, cclist_accessible - FROM bugs - WHERE bug_id = $id - "); - my ($reporter_accessible, $cclist_accessible) = FetchSQLData(); - - # Convert boolean data about which roles always have access to the bug - # into "checked" attributes for the HTML checkboxes by which users - # set and change these values. - my $reporter_checked = $reporter_accessible ? " checked" : ""; - my $cclist_checked = $cclist_accessible ? " checked" : ""; - - # Display interface for changing the values. - print qq| -

- But users in the roles selected below can always view this bug:
- (The assignee - |; - if (Param('useqacontact')) { - print " and qa contact"; - } - print qq| can always see a bug, and this does not take effect unless the bug is restricted to at least one group.) -

- -

- Reporter - CC List -

- |; - } -} - - - - - -print "
- - Leave as $bug{'bug_status'} $bug{'resolution'}
"; - - -# knum is which knob number we're generating, in javascript terms. - -my $knum = 1; - -my $status = $bug{'bug_status'}; - -# In the below, if the person hasn't logged in ($::userid == 0), then -# we treat them as if they can do anything. That's because we don't -# know why they haven't logged in; it may just be because they don't -# use cookies. Display everything as if they have all the permissions -# in the world; their permissions will get checked when they log in -# and actually try to make the change. - -my $canedit = UserInGroup("editbugs") || ($::userid == 0); -my $canconfirm; - -if ($status eq $::unconfirmedstate) { - $canconfirm = UserInGroup("canconfirm") || ($::userid == 0); - if ($canedit || $canconfirm) { - print ""; - print "Confirm bug (change status to NEW)
"; - $knum++; - } -} - -my $movers = Param("movers"); -$movers =~ s/\s?,\s?/|/g; -$movers =~ s/@/\@/g; - -if ($canedit || $::userid == $assignedtoid || - $::userid == $reporterid || $::userid == $qacontactid) { - if (IsOpenedState($status)) { - if ($status ne "ASSIGNED") { - print ""; - my $extra = ""; - if ($status eq $::unconfirmedstate && ($canconfirm || $canedit)) { - $extra = "confirm bug, "; + $bug{'blocked'} = \@list2; + + # Groups + if ($::usergroupset ne '0' || $bug{'groupset'} ne '0') { + my $bug_groupset = $bug{'groupset'}; + + SendSQL("SELECT bit, name, description, (bit & $bug_groupset != 0), + (bit & $::usergroupset != 0) FROM groups + WHERE isbuggroup != 0 " . + # Include active groups as well as inactive groups to which + # the bug already belongs. This way the bug can be removed + # from an inactive group but can only be added to active ones. + "AND ((isactive = 1 AND (bit & $::usergroupset != 0)) OR + (bit & $bug_groupset != 0))"); + + my @groups; + $user{'inallgroups'} = 1; + + while (MoreSQLData()) { + my ($bit, $name, $description, $ison, $ingroup) = FetchSQLData(); + # For product groups, we only want to display the checkbox if either + # (1) The bit is already set, or + # (2) The user is in the group, but either: + # (a) The group is a product group for the current product, or + # (b) The group name isn't a product name + # This means that all product groups will be skipped, but + # non-product bug groups will still be displayed. + if($ison || + ($ingroup && (($name eq $bug{'product'}) || + (!defined $::proddesc{$name})))) + { + $user{'inallgroups'} &= $ingroup; + + push (@groups, { "bit" => $bit, + "ison" => $ison, + "ingroup" => $ingroup, + "description" => $description }); } - print "Accept bug (${extra}change status to ASSIGNED)
"; - $knum++; - } - if ($bug{'resolution'} ne "") { - print "\n"; - print "Clear the resolution (remove the current resolution of\n"; - print "$bug{'resolution'})
\n"; - $knum++; - } - my $resolution_popup = make_options(\@::settable_resolution, - $bug{'resolution'}); - print " - Resolve bug, changing resolution to -
\n"; - $knum++; - print " - Resolve bug, mark it as duplicate of bug # -
\n"; - $knum++; - my $assign_element = ""; - - print " - Reassign bug to - $assign_element -
\n"; - if ($status eq $::unconfirmedstate && ($canconfirm || $canedit)) { - print "     and confirm bug (change status to NEW)
"; - } - $knum++; - print " - Reassign bug to owner "; - if (Param("useqacontact")) { print "and QA contact "; } - print "of selected component
\n"; - if ($status eq $::unconfirmedstate && ($canconfirm || $canedit)) { - print "     and confirm bug (change status to NEW)
"; - } - $knum++; - } elsif ( Param("move-enabled") && ($bug{'resolution'} eq "MOVED") ) { - if ( (defined $::COOKIE{"Bugzilla_login"}) - && ($::COOKIE{"Bugzilla_login"} =~ /($movers)/) ){ - print " Reopen bug
\n"; - $knum++; - if ($status eq "RESOLVED") { - print " - Mark bug as VERIFIED
\n"; - $knum++; - } - if ($status ne "CLOSED") { - print " - Mark bug as CLOSED
\n"; - $knum++; - } } - } else { - print " Reopen bug
\n"; - $knum++; - if ($status eq "RESOLVED") { - print " - Mark bug as VERIFIED
\n"; - $knum++; - } - if ($status ne "CLOSED") { - print " - Mark bug as CLOSED
\n"; - $knum++; + + # If the bug is restricted to a group, display checkboxes that allow + # the user to set whether or not the reporter + # and cc list can see the bug even if they are not members of all + # groups to which the bug is restricted. + if ($bug{'groupset'} != 0) { + $bug{'inagroup'} = 1; + + # Determine whether or not the bug is always accessible by the + # reporter, QA contact, and/or users on the cc: list. + SendSQL("SELECT reporter_accessible, cclist_accessible + FROM bugs + WHERE bug_id = $id + "); + ($bug{'reporter_accessible'}, + $bug{'cclist_accessible'}) = FetchSQLData(); } + + $vars->{'groups'} = \@groups; } -} - -print " - - - -

- - View Bug Activity -   |   - Format For Printing - -"; - -if ( Param("move-enabled") && (defined $::COOKIE{"Bugzilla_login"}) && ($::COOKIE{"Bugzilla_login"} =~ /($movers)/) ){ - print "  |  " - ."\n"; -} -print "

"; - -print qq| - -
Description:Opened: $bug{'creation_ts'}
-
-|; -print $bug{'long_desc'}; -print " -
\n"; + my $movers = Param("movers"); + $user{'canmove'} = Param("move-enabled") + && (defined $::COOKIE{"Bugzilla_login"}) + && ($::COOKIE{"Bugzilla_login"} =~ /\Q$movers\E/); + + # User permissions + + # In the below, if the person hasn't logged in ($::userid == 0), then + # we treat them as if they can do anything. That's because we don't + # know why they haven't logged in; it may just be because they don't + # use cookies. Display everything as if they have all the permissions + # in the world; their permissions will get checked when they log in + # and actually try to make the change. + $user{'canedit'} = $::userid == 0 + || $::userid == $bug{'reporter'} + || $::userid == $bug{'qa_contact'} + || $::userid == $bug{'assigned_to'} + || UserInGroup("editbugs"); + $user{'canconfirm'} = ($::userid == 0) || UserInGroup("canconfirm"); + + # Bug states + $bug{'isunconfirmed'} = ($bug{'bug_status'} eq $::unconfirmedstate); + $bug{'isopened'} = IsOpenedState($bug{'bug_status'}); + + # People involved with the bug + $bug{'assigned_to_email'} = DBID_to_name($bug{'assigned_to'}); + $bug{'assigned_to'} = DBID_to_real_or_loginname($bug{'assigned_to'}); + $bug{'reporter'} = DBID_to_real_or_loginname($bug{'reporter'}); + $bug{'qa_contact'} = $bug{'qa_contact'} > 0 ? + DBID_to_name($bug{'qa_contact'}) : ""; + + my $ccset = new RelationSet; + $ccset->mergeFromDB("SELECT who FROM cc WHERE bug_id=$id"); + + my @cc = $ccset->toArrayOfStrings(); + $bug{'cc'} = \@cc if $cc[0]; + + # Next bug in list (if there is one) + if ($::COOKIE{"BUGLIST"} && $id) + { + my @bug_list = split(/:/, $::COOKIE{"BUGLIST"}); + $vars->{'bug_list'} = \@bug_list; + } -# To add back option of editing the long description, insert after the above -# long_list.cgi line: -# Edit Long Description + $bug{'comments'} = GetComments($bug{'bug_id'}); -navigation_header(); + # This is length in number of comments + $bug{'longdesclength'} = scalar(@{$bug{'comments'}}); -PutFooter(); + # Add the bug and user hashes to the variables + $vars->{'bug'} = \%bug; + $vars->{'user'} = \%user; + # Generate and return the UI (HTML page) from the appropriate template. + $template->process("show/show_bug.html.tmpl", $vars) + || DisplayError("Template process failed: " . $template->error()) + && exit; +} + 1; -- cgit v1.2.3-24-g4f1b