From e18c6fd41b16c91ccb6fbca903b0716af37f27c2 Mon Sep 17 00:00:00 2001 From: "terry%mozilla.org" <> Date: Wed, 13 Oct 1999 06:00:31 +0000 Subject: Patch by Holger Schurig -- rewriting and enhancing the ability to edit components, products, and versions. Yay! --- defparams.pl | 6 + editcomponents.cgi | 792 +++++++++++++++++++++++++++++++++++++++++++++++------ editproducts.cgi | 665 ++++++++++++++++++++++++++++++++++++++++++++ editusers.cgi | 583 +++++++++++++++++++++++++++++++++++++++ editversions.cgi | 542 ++++++++++++++++++++++++++++++++++++ query.cgi | 2 +- 6 files changed, 2510 insertions(+), 80 deletions(-) create mode 100755 editproducts.cgi create mode 100755 editusers.cgi create mode 100755 editversions.cgi diff --git a/defparams.pl b/defparams.pl index 7efdc4053..56a63cf6d 100644 --- a/defparams.pl +++ b/defparams.pl @@ -353,6 +353,12 @@ Reason: %reason% %urlbase%show_bug.cgi?id=%bugid% "); +DefParam("allowbugdeletion", + q{The pages to edit products and components and versions can delete all associated bugs when you delete a product (or component or version). Since that is a pretty scary idea, you have to turn on this option before any such deletions will ever happen.}, + "b", + 0); + + 1; diff --git a/editcomponents.cgi b/editcomponents.cgi index e4b6a23de..371c27b72 100755 --- a/editcomponents.cgi +++ b/editcomponents.cgi @@ -10,114 +10,748 @@ # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. -# -# The Original Code is the Bugzilla Bug Tracking System. -# -# The Initial Developer of the Original Code is Netscape Communications -# Corporation. Portions created by Netscape are Copyright (C) 1998 -# Netscape Communications Corporation. All Rights Reserved. -# -# Contributor(s): Sam Ziegler -# Terry Weissman - -# Code derived from editparams.cgi, editowners.cgi +# +# +# Direct any questions on this source code to +# +# Holger Schurig use diagnostics; use strict; require "CGI.pl"; +require "globals.pl"; + +my $dobugcounts = (defined $::FORM{'dobugcounts'}); + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text +# TestComponent: just returns if the specified product/component combination exists +# CheckComponent: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + +sub TestComponent ($$) +{ + my ($prod,$comp) = @_; + + # does the product exist? + SendSQL("SELECT program,value + FROM components + WHERE program=" . SqlQuote($prod) . " and value=" . SqlQuote($comp)); + return FetchOneColumn(); +} + +sub CheckComponent ($$) +{ + my ($prod,$comp) = @_; + + # do we have the component? + unless ($comp) { + print "Sorry, you haven't specified a component."; + PutTrailer(); + exit; + } + + CheckProduct($prod); + + unless (TestComponent $prod,$comp) { + print "Sorry, component '$comp' for product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit component parameters +# + +sub EmitFormElements ($$$$$) +{ + my ($product, $component, $initialowner, $initialqacontact, $description) = @_; + + print " Component:\n"; + print " \n"; + print " \n"; + + print "\n"; + print " Description:\n"; + print " \n"; + + print "\n"; + print " Initial owner:\n"; + print " \n"; + + if (Param('useqacontact')) { + print "\n"; + print " Initial QA contact:\n"; + print " \n"; + } +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the query page", @_); + + my $count = $#links; + my $num = 0; + print "

\n"; + if (!$dobugcounts) { + print qq{}; + print qq{Redisplay table with bug counts (slower)

\n}; + } + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "\n\n"; +} + + + + -# Shut up misguided -w warnings about "used only once": -use vars @::legal_product; + +# +# Preliminary checks: +# confirm_login(); print "Content-type: text/html\n\n"; -if (!UserInGroup("editcomponents")) { - print "

Sorry, you aren't a member of the 'editcomponents' group.

\n"; - print "And so, you aren't allowed to edit the owners.\n"; +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete components.\n"; + PutTrailer(); exit; } -PutHeader("Edit Components"); +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $component = trim($::FORM{component} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer; +if ($product) { + $localtrailer = "edit more components"; +} else { + $localtrailer = "edit more components"; +} + + + +# +# product = '' -> Show nice list of products +# + +unless ($product) { + PutHeader("Select product"); + + if ($dobugcounts){ + SendSQL("SELECT products.product,products.description,COUNT(bug_id) + FROM products LEFT JOIN bugs + ON products.product=bugs.product + GROUP BY products.product + ORDER BY products.product"); + } else { + SendSQL("SELECT products.product,products.description + FROM products + ORDER BY products.product"); + } + print "\n"; + print " \n"; + print " \n"; + if ($dobugcounts) { + print " \n"; + } + #print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($product, $description, $bugs) = FetchSQLData(); + $description ||= "missing"; + print "\n"; + print " \n"; + print " \n"; + if ($dobugcounts) { + $bugs ||= "none"; + print " \n"; + } + #print " \n"; + } + print "
Edit components of ...DescriptionBugsEdit
$product$description$bugsEdit
\n"; -print "This lets you edit the program components of bugzilla.\n"; -print "
"; -print "Add new component.
\n"; -print "
"; + PutTrailer(); + exit; +} -print "
\n"; -my $rowbreak = "
"; -unlink "data/versioncache"; -GetVersionTable(); +# +# action='' -> Show nice list of components +# -my $prodcode = "P000"; +unless ($action) { + PutHeader("Select component"); + CheckProduct($product); -foreach my $product (@::legal_product) { - SendSQL("select description, milestoneurl, disallownew, votesperuser from products where product='$product'"); - my @row = FetchSQLData(); - if (!@row) { - next; + if ($dobugcounts) { + SendSQL("SELECT value,description,initialowner,initialqacontact,COUNT(bug_id) + FROM components LEFT JOIN bugs + ON components.program=bugs.product AND components.value=bugs.component + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + } else { + SendSQL("SELECT value,description,initialowner,initialqacontact + FROM components + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + } + print "\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n" + if Param('useqacontact'); + print " \n" + if $dobugcounts; + print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($component,$desc,$initialowner,$initialqacontact, $bugs) = FetchSQLData(); + $desc ||= "missing"; + $initialowner ||= "missing"; + $initialqacontact ||= "none"; + print "\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n" + if Param('useqacontact'); + if ($dobugcounts) { + $bugs ||= 'none'; + print " \n"; + } + print " \n"; + print ""; } - my ($description, $milestoneurl, $disallownew, $votesperuser) = (@row); - $prodcode++; - print "\n"; - print "
Edit component ...DescriptionInitial ownerInitial QA contactBugsDelete
$component$desc$initialowner$initialqacontact$bugsDelete
\n"; - print "\n"; - print "\n"; - if (Param('usetargetmilestone')) { - print "\n"; - print "\n"; - } - print qq{\n}; - my $check0 = !$disallownew ? " SELECTED" : ""; - my $check1 = $disallownew ? " SELECTED" : ""; - print "\n"; - - print "
$product
Description:
MilestoneURL:
Maximum votes per user:\n}; - print qq{}; - print qq{
Components:
\n"; - print "\n"; + print "\n"; + my $span = 3; + $span++ if Param('useqacontact'); + $span++ if $dobugcounts; + print " \n"; + print " \n"; + print "
Add a new componentAdd
\n"; + + PutTrailer(); + exit; +} + + +$dobugcounts = 1; # Stupid hack to force further PutTrailer() + # calls to not offer a "bug count" option. + + +# +# action='add' -> present form for parameters for new component +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add component"); + CheckProduct($product); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "\n"; + print "\n"; + + EmitFormElements($product, '', '', '', ''); + + print "
\n
\n"; + print "\n"; + print "\n"; + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add component entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new product"); + CheckProduct($product); + + # Cleanups and valididy checks + + unless ($component) { + print "You must enter a name for the new component. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestComponent($product,$component)) { + print "The component '$component' already exists. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $description = trim($::FORM{description} || ''); + + if ($description eq '') { + print "You must enter a description for the component '$component'. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $initialowner = trim($::FORM{initialowner} || ''); + + if ($initialowner eq '') { + print "You must enter an initial owner for the component '$component'. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + #+++ + #DBNameToIdAndCheck($initialowner, 0); + + my $initialqacontact = trim($::FORM{initialqacontact} || ''); + + if (Param('useqacontact')) { + if ($initialqacontact eq '') { + print "You must enter an initial QA contact for the component '$component'. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + #+++ + #DBNameToIdAndCheck($initialqacontact, 0); + } + + # Add the new component + SendSQL("INSERT INTO components ( " . + "program, value, description, initialowner, initialqacontact " . + " ) VALUES ( " . + SqlQuote($product) . "," . + SqlQuote($component) . "," . + SqlQuote($description) . "," . + SqlQuote($initialowner) . "," . + SqlQuote($initialqacontact) . ")"); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.

\n"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete component"); + CheckComponent($product, $component); + + # display some data about the component + SendSQL("SELECT products.product,products.description, + products.milestoneurl,products.disallownew, + components.program,components.value,components.initialowner, + components.initialqacontact,components.description + FROM products + LEFT JOIN components on product=program + WHERE product=" . SqlQuote($product) . " + AND value=" . SqlQuote($component) ); + + + my ($product,$pdesc,$milestoneurl,$disallownew, + $dummy,$component,$initialowner,$initialqacontact,$cdesc) = FetchSQLData(); + + $pdesc ||= "missing"; + $milestoneurl ||= "missing"; + $disallownew = $disallownew ? 'closed' : 'open'; + $initialowner ||= "missing"; + $initialqacontact ||= "missing"; + $cdesc ||= "missing"; - SendSQL("select value, initialowner, initialqacontact, description from components where program=" . SqlQuote($product) . " order by value"); - my $c = 0; - while (my @row = FetchSQLData()) { - my ($component, $initialowner, $initialqacontact, $description) = - (@row); - $c++; - my $compcode = $prodcode . "-" . "C$c"; - print "\n"; - print "$componentDescription:\n"; - print "\n"; - print "Initial owner:\n"; - print "\n"; - if (Param('useqacontact')) { - print "Initial QA contact:\n"; - print "\n"; + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " "; + + print "\n"; + print " \n"; + print " "; + + print "\n"; + print " \n"; + print " "; + + if (Param('useqacontact')) { + print "\n"; + print " \n"; + print " "; + } + SendSQL("SELECT count(bug_id),product,component + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + if (Param('usetargetmilestone')) { + print "\n"; + print " \n"; + print " \n"; + } + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n
PartValue
Component:$component
Component description:$cdesc
Initial owner:$initialowner
Initial QA contact:$initialqacontact
Component of product:$product
Description:$pdesc
Milestone URL:$milestoneurl
Closed for bugs:$disallownew
Bugs"; + my $bugs = FetchOneColumn(); + print $bugs || 'none'; + + + print "
"; + + print "

Confirmation

\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this component. +You must reassign those bugs to another component before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "
\n", + "There are bugs entered for this component! When you delete this ", + "component, all stored bugs will be deleted, too. ", + "You could not even see the bug history for this component anymore!\n", + "
\n"; + } + + print "

Do you really want to delete this component?

\n"; + + print "

\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "
"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the component +# + +if ($action eq 'delete') { + PutHeader("Deleting component"); + CheckComponent($product,$component); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + components WRITE, + dependencies WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.
\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + print "Bugs deleted.
\n"; + + SendSQL("DELETE FROM components + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($component)); + print "Components deleted.

\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit component form +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit component"); + CheckComponent($product,$component); + + # get data of component + SendSQL("SELECT products.product,products.description, + products.milestoneurl,products.disallownew, + components.program,components.value,components.initialowner, + components.initialqacontact,components.description + FROM products + LEFT JOIN components on product=program + WHERE product=" . SqlQuote($product) . " + AND value=" . SqlQuote($component) ); + + my ($product,$pdesc,$milestoneurl,$disallownew, + $dummy,$component,$initialowner,$initialqacontact,$cdesc) = FetchSQLData(); + + print "

\n"; + print "\n"; + + #+++ display product/product description + + EmitFormElements($product, $component, $initialowner, $initialqacontact, $cdesc); + + print "\n"; + print " \n"; + print " \n
Bugs:"; + SendSQL("SELECT count(*) + FROM bugs + WHERE product=" . SqlQuote($product) . + " and component=" . SqlQuote($component)); + my $bugs = ''; + $bugs = FetchOneColumn() if MoreSQLData(); + print $bugs || 'none'; + + print "
\n"; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='update' -> update the component +# + +if ($action eq 'update') { + PutHeader("Update component"); + + my $componentold = trim($::FORM{componentold} || ''); + my $description = trim($::FORM{description} || ''); + my $descriptionold = trim($::FORM{descriptionold} || ''); + my $initialowner = trim($::FORM{initialowner} || ''); + my $initialownerold = trim($::FORM{initialownerold} || ''); + my $initialqacontact = trim($::FORM{initialqacontact} || ''); + my $initialqacontactold = trim($::FORM{initialqacontactold} || ''); + + CheckComponent($product,$componentold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$component' or WHERE='$componentold' + + SendSQL("LOCK TABLES bugs WRITE, + components WRITE"); + + if ($description ne $descriptionold) { + unless ($description) { + print "Sorry, I can't delete the description."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE components + SET description=" . SqlQuote($description) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated description.
\n"; + } + + + if ($initialowner ne $initialownerold) { + unless ($initialowner) { + print "Sorry, I can't delete the initial owner."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + #+++ + #DBNameToIdAndCheck($initialowner, 0); + SendSQL("UPDATE components + SET initialowner=" . SqlQuote($initialowner) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated initial owner.
\n"; + } + + if (Param('useqacontact') && $initialqacontact ne $initialqacontactold) { + unless ($initialqacontact) { + print "Sorry, I can't delete the initial QA contact."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; } + #+++ + #DBNameToIdAndCheck($initialqacontact, 0); + SendSQL("UPDATE components + SET initialqacontact=" . SqlQuote($initialqacontact) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated initial QA contact.
\n"; } - print "
\n"; + if ($component ne $componentold) { + unless ($component) { + print "Sorry, I can't delete the product name."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestComponent($product,$component)) { + print "Sorry, component name '$component' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + + SendSQL("UPDATE bugs + SET component=" . SqlQuote($component) . " + WHERE component=" . SqlQuote($componentold) . " + AND product=" . SqlQuote($product)); + SendSQL("UPDATE components + SET value=" . SqlQuote($component) . " + WHERE value=" . SqlQuote($componentold) . " + AND program=" . SqlQuote($product)); + + unlink "data/versioncache"; + print "Updated product name.
\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; } -print "\n"; -print "\n"; -print "

Skip all this, and go back to the query page\n"; +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.
\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}
\n"; +} diff --git a/editproducts.cgi b/editproducts.cgi new file mode 100755 index 000000000..be492ce01 --- /dev/null +++ b/editproducts.cgi @@ -0,0 +1,665 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# +# Direct any questions on this source code to +# +# Holger Schurig + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit a products parameters +# + +sub EmitFormElements ($$$$) +{ + my ($product, $description, $milestoneurl, $disallownew) = @_; + + print " Product:\n"; + print " \n"; + print "\n"; + + print " Description:\n"; + print " \n"; + + if (Param('usetargetmilestone')) { + print "\n"; + print " Milestone URL:\n"; + print " \n"; + } + + print "\n"; + print " Closed for bug entry:\n"; + my $closed = $disallownew ? "CHECKED" : ""; + print " \n"; +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the query page", @_); + + my $count = $#links; + my $num = 0; + print "

\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "\n\n"; +} + + + + + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete products.\n"; + PutTrailer(); + exit; +} + + + +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer = "edit more products"; + + + +# +# action='' -> Show nice list of products +# + +unless ($action) { + PutHeader("Select product"); + + SendSQL("SELECT products.product,description,disallownew,COUNT(bug_id) + FROM products LEFT JOIN bugs + ON products.product=bugs.product + GROUP BY products.product + ORDER BY products.product"); + print "\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($product, $description, $disallownew, $bugs) = FetchSQLData(); + $description ||= "missing"; + $disallownew = $disallownew ? 'closed' : 'open'; + $bugs ||= 'none'; + print "\n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print ""; + } + print "\n"; + print " \n"; + print " \n"; + print "
Edit product ...DescriptionStatusBugsAction
$product$description$disallownew$bugsDelete
Add a new productAdd
\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new product +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add product"); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "

\n"; + print "\n"; + + EmitFormElements('', '', '', 0); + + print "\n"; + print " \n"; + print " \n"; + + print "
Version:
\n
\n"; + print "\n"; + print "\n"; + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add product entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new product"); + + # Cleanups and valididy checks + + unless ($product) { + print "You must enter a name for the new product. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestProduct($product)) { + print "The product '$product' already exists. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $version = trim($::FORM{version} || ''); + + if ($version eq '') { + print "You must enter a version for product '$product'. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $description = trim($::FORM{description} || ''); + my $milestoneurl = trim($::FORM{milestoneurl} || ''); + my $disallownew = 0; + $disallownew = 1 if $::FORM{disallownew}; + + # Add the new product. + SendSQL("INSERT INTO products ( " . + "product, description, milestoneurl, disallownew" . + " ) VALUES ( " . + SqlQuote($product) . "," . + SqlQuote($description) . "," . + SqlQuote($milestoneurl) . "," . + $disallownew . ")" ); + SendSQL("INSERT INTO versions ( " . + "value, program" . + " ) VALUES ( " . + SqlQuote($version) . "," . + SqlQuote($product) . ")" ); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.

\n"; + PutTrailer($localtrailer, "add components to this new product."); + exit; +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete product"); + CheckProduct($product); + + # display some data about the product + SendSQL("SELECT description, milestoneurl, disallownew + FROM products + WHERE product=" . SqlQuote($product)); + my ($description, $milestoneurl, $disallownew) = FetchSQLData(); + $description ||= "description missing"; + $disallownew = $disallownew ? 'closed' : 'open'; + + print "\n"; + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + if (Param('usetargetmilestone')) { + print "\n"; + print " \n"; + print " \n"; + } + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n\n"; + print " \n"; + print " \n\n"; + print " \n"; + print " \n
PartValue
Product:$product
Description:$description
Milestone URL:$milestoneurl
Closed for bugs:$disallownew
Components:"; + SendSQL("SELECT value,description + FROM components + WHERE program=" . SqlQuote($product)); + if (MoreSQLData()) { + print ""; + while ( MoreSQLData() ) { + my ($component, $description) = FetchSQLData(); + $description ||= "description missing"; + print ""; + print "\n"; + } + print "
$component:$description
\n"; + } else { + print "missing"; + } + + print "
Versions:"; + SendSQL("SELECT value + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + if (MoreSQLData()) { + my $br = 0; + while ( MoreSQLData() ) { + my ($version) = FetchSQLData(); + print "
" if $br; + print $version; + $br = 1; + } + } else { + print "missing"; + } + + + print "
Bugs:"; + SendSQL("SELECT count(bug_id),product + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product)); + my $bugs = FetchOneColumn(); + print $bugs || 'none'; + + + print "
"; + + print "

Confirmation

\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this product. +You must reassign those bugs to another product before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "
\n", + "There are bugs entered for this product! When you delete this ", + "product, all stored bugs will be deleted, too. ", + "You could not even see a bug history anymore!\n", + "
\n"; + } + + print "

Do you really want to delete this product?

\n"; + print "

\n"; + print "\n"; + print "\n"; + print "\n"; + print "
"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the product +# + +if ($action eq 'delete') { + PutHeader("Deleting product"); + CheckProduct($product); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + components WRITE, + dependencies WRITE, + versions WRITE, + products WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.
\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product)); + print "Bugs deleted.
\n"; + + SendSQL("DELETE FROM components + WHERE program=" . SqlQuote($product)); + print "Components deleted.
\n"; + + SendSQL("DELETE FROM versions + WHERE program=" . SqlQuote($product)); + print "Versions deleted.

\n"; + + SendSQL("DELETE FROM products + WHERE product=" . SqlQuote($product)); + print "Product '$product' deleted.
\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit products from +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit product"); + CheckProduct($product); + + # get data of product + SendSQL("SELECT description,milestoneurl,disallownew + FROM products + WHERE product=" . SqlQuote($product)); + my ($description, $milestoneurl, $disallownew) = FetchSQLData(); + + print "

\n"; + print "\n"; + + EmitFormElements($product, $description, $milestoneurl, $disallownew); + + print "\n"; + print " \n"; + print " \n\n"; + print " \n"; + print " \n\n"; + print " \n"; + print " \n
Edit components:"; + SendSQL("SELECT value,description + FROM components + WHERE program=" . SqlQuote($product)); + if (MoreSQLData()) { + print ""; + while ( MoreSQLData() ) { + my ($component, $description) = FetchSQLData(); + $description ||= "description missing"; + print ""; + print "\n"; + } + print "
$component:$description
\n"; + } else { + print "missing"; + } + + + print "
Edit versions:"; + SendSQL("SELECT value + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + if (MoreSQLData()) { + my $br = 0; + while ( MoreSQLData() ) { + my ($version) = FetchSQLData(); + print "
" if $br; + print $version; + $br = 1; + } + } else { + print "missing"; + } + + + print "
Bugs:"; + SendSQL("SELECT count(bug_id),product + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product)); + my $bugs = ''; + $bugs = FetchOneColumn() if MoreSQLData(); + print $bugs || 'none'; + + print "
\n"; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "
"; + + my $x = $localtrailer; + $x =~ s/more/other/; + PutTrailer($x); + exit; +} + + + +# +# action='update' -> update the product +# + +if ($action eq 'update') { + PutHeader("Update product"); + + my $productold = trim($::FORM{productold} || ''); + my $description = trim($::FORM{description} || ''); + my $descriptionold = trim($::FORM{descriptionold} || ''); + my $disallownew = trim($::FORM{disallownew} || ''); + my $disallownewold = trim($::FORM{disallownewold} || ''); + my $milestoneurl = trim($::FORM{milestoneurl} || ''); + my $milestoneurlold = trim($::FORM{milestoneurlold} || ''); + + CheckProduct($productold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$product' or WHERE='$productold' + + SendSQL("LOCK TABLES bugs WRITE, + components WRITE, + products WRITE, + versions WRITE"); + + if ($disallownew != $disallownewold) { + $disallownew ||= 0; + SendSQL("UPDATE products + SET disallownew=$disallownew + WHERE product=" . SqlQuote($productold)); + print "Updated bug submit status.
\n"; + } + + if ($description ne $descriptionold) { + unless ($description) { + print "Sorry, I can't delete the description."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE products + SET description=" . SqlQuote($description) . " + WHERE product=" . SqlQuote($productold)); + print "Updated description.
\n"; + } + + if (Param('usetargetmilestone') && $milestoneurl ne $milestoneurlold) { + SendSQL("UPDATE products + SET milestoneurl=" . SqlQuote($milestoneurl) . " + WHERE product=" . SqlQuote($productold)); + print "Updated mile stone URL.
\n"; + } + + + if ($product ne $productold) { + unless ($product) { + print "Sorry, I can't delete the product name."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestProduct($product)) { + print "Sorry, product name '$product' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + + SendSQL("UPDATE bugs + SET product=" . SqlQuote($product) . " + WHERE product=" . SqlQuote($productold)); + SendSQL("UPDATE components + SET program=" . SqlQuote($product) . " + WHERE program=" . SqlQuote($productold)); + SendSQL("UPDATE products + SET product=" . SqlQuote($product) . " + WHERE product=" . SqlQuote($productold)); + SendSQL("UPDATE versions + SET program='$product' + WHERE program=" . SqlQuote($productold)); + + unlink "data/versioncache"; + print "Updated product name.
\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.
\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}
\n"; +} diff --git a/editusers.cgi b/editusers.cgi new file mode 100755 index 000000000..552474339 --- /dev/null +++ b/editusers.cgi @@ -0,0 +1,583 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# +# Direct any questions on this source code to +# +# Holger Schurig + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + + +# TestUser: just returns if the specified user does exists +# CheckUser: same check, optionally emit an error text + +sub TestUser ($) +{ + my $user = shift; + + # does the product exist? + SendSQL("SELECT login_name + FROM profiles + WHERE login_name=" . SqlQuote($user)); + return FetchOneColumn(); +} + +sub CheckUser ($) +{ + my $user = shift; + + # do we have a product? + unless ($user) { + print "Sorry, you haven't specified a user."; + PutTrailer(); + exit; + } + + unless (TestUser $user) { + print "Sorry, user '$user' does not exist."; + PutTrailer(); + exit; + } +} + + + +# +# Displays the form to edit a user parameters +# + +sub EmitFormElements ($$$$) +{ + my ($user, $password, $realname, $groupset) = @_; + + print " Login name:\n"; + print " \n"; + + print "\n"; + print " Real name:\n"; + print " \n"; + + print "\n"; + print " Password:\n"; + print " \n"; + + + SendSQL("SELECT bit,name,description + FROM groups + ORDER BY name"); + while (MoreSQLData()) { + my($bit,$name,$description) = FetchSQLData(); + print "\n"; + $bit = $bit+0; # this strange construct coverts a string to a number + print " ", ucfirst($name), ":\n"; + my $checked = ($groupset & $bit) ? "CHECKED" : ""; + print " $description\n"; + } + +} + + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the index", @_); + + my $count = $#links; + my $num = 0; + print "

\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "\n"; +} + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("tweakparams")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'tweakparams' group.\n"; + print "And so, you aren't allowed to add, modify or delete users.\n"; + PutTrailer(); + exit; +} + + + +# +# often used variables +# +my $user = trim($::FORM{user} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer = "edit more users"; + + + +# +# action='' -> Show nice list of users +# + +unless ($action) { + PutHeader("Select user"); + + SendSQL("SELECT login_name,realname + FROM profiles + ORDER BY login_name"); + my $count = 0; + my $header = " + + +\n +"; + print $header; + while ( MoreSQLData() ) { + $count++; + if ($count % 100 == 0) { + print "
Edit user ...Real nameAction
$header"; + } + my ($user, $realname) = FetchSQLData(); + $realname ||= "missing"; + print "\n"; + print " $user\n"; + print " $realname\n"; + print " Delete\n"; + print ""; + } + print "\n"; + print " Add a new user\n"; + print " Add\n"; + print "\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new user +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add user"); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "

\n"; + print "\n"; + + EmitFormElements('', '', '', 0); + + print "
\n
\n"; + print "\n"; + print "\n"; + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add user entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new user"); + + # Cleanups and valididy checks + my $realname = trim($::FORM{realname} || ''); + my $password = trim($::FORM{password} || ''); + + unless ($user) { + print "You must enter a name for the new user. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + unless ($user =~ /^[^\@]+\@[^\@]+$/) { + print "The user name entered must be a valid e-mail address. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestUser($user)) { + print "The user '$user' does already exist. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if ($password !~ /^[a-zA-Z0-9-_]*$/ || length($password) < 3 || length($password) > 16) { + print "The new user must have a password. The password must be between ", + "3 and 16 characters long and must contain only numbers, letters, ", + "hyphens and underlines. Press Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $bits = 0; + foreach (keys %::FORM) { + next unless /^bit_/; + #print "$_=$::FORM{$_}
\n"; + $bits |= $::FORM{$_}; + } + + + sub x { + my $sc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"; + return substr($sc, int (rand () * 100000) % (length ($sc) + 1), 1); + } + + my $salt = x() . x(); + my $cryptpassword = crypt($password, $salt); + + # Add the new user + SendSQL("INSERT INTO profiles ( " . + "login_name, password, cryptpassword, realname, groupset" . + " ) VALUES ( " . + SqlQuote($user) . "," . + SqlQuote($password) . "," . + SqlQuote($cryptpassword) . "," . + SqlQuote($realname) . "," . + $bits . ")" ); + + #+++ send e-mail away + + print "OK, done.

\n"; + PutTrailer($localtrailer, + "add another user."); + exit; + +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete user"); + CheckUser($user); + + # display some data about the product + SendSQL("SELECT realname, groupset, emailnotification, login_name + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my ($realname, $groupset, $emailnotification) = FetchSQLData(); + $realname ||= "missing"; + + print "\n"; + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + + + # Check if the user is an initialowner + my $nodelete = ''; + + SendSQL("SELECT program, value + FROM components + WHERE initialowner=" . SqlQuote($user)); + $found = 0; + while (MoreSQLData()) { + if ($found) { + print "
\n"; + } else { + print "\n"; + print " \n"; + print " \n" if $found; + + + # Check if the user is an initialqacontact + + SendSQL("SELECT program, value + FROM components + WHERE initialqacontact=" . SqlQuote($user)); + $found = 0; + while (MoreSQLData()) { + if ($found) { + print "
\n"; + } else { + print "\n"; + print " \n"; + print " \n" if $found; + + print "
PartValue
Login name:$user
Real name:$realname
E-Mail notification:$emailnotification
Group set:"; + SendSQL("SELECT bit, name + FROM groups + ORDER BY name"); + my $found = 0; + while ( MoreSQLData() ) { + my ($bit,$name) = FetchSQLData(); + if ($bit & $groupset) { + print "
\n" if $found; + print ucfirst $name; + $found = 1; + } + } + print "none" unless $found; + print "
Initial owner:"; + } + my ($product, $component) = FetchSQLData(); + print "$product: $component"; + $found = 1; + $nodelete = 'initial bug owner'; + } + print "
Initial QA contact:"; + } + my ($product, $component) = FetchSQLData(); + print "$product: $component"; + $found = 1; + $nodelete = 'initial QA contact'; + } + print "
\n"; + + + if ($nodelete) { + print "

You can't delete this user because '$user' is an $nodelete ", + "for at least one product."; + PutTrailer($localtrailer); + exit; + } + + + print "

Confirmation

\n"; + print "

Do you really want to delete this user?

\n"; + + print "

\n"; + print "\n"; + print "\n"; + print "\n"; + print "
"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the user +# + +if ($action eq 'delete') { + PutHeader("Deleting user"); + CheckUser($user); + + SendSQL("SELECT userid + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my $userid = FetchOneColumn(); + + SendSQL("DELETE FROM profiles + WHERE login_name=" . SqlQuote($user)); + SendSQL("DELETE FROM logincookies + WHERE userid=" . $userid); + print "User deleted.
\n"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the user edit from +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit user"); + CheckUser($user); + + # get data of user + SendSQL("SELECT password, realname, groupset, emailnotification + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my ($password, $realname, $groupset, $emailnotification) = FetchSQLData(); + + print "
\n"; + print "\n"; + + EmitFormElements($user, $password, $realname, $groupset); + + print "
\n"; + + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + print "
"; + + my $x = $localtrailer; + $x =~ s/more/other/; + PutTrailer($x); + exit; +} + +# +# action='update' -> update the user +# + +if ($action eq 'update') { + PutHeader("Update User"); + + my $userold = trim($::FORM{userold} || ''); + my $realname = trim($::FORM{realname} || ''); + my $realnameold = trim($::FORM{realnameold} || ''); + my $password = trim($::FORM{password} || ''); + my $passwordold = trim($::FORM{passwordold} || ''); + my $emailnotification = trim($::FORM{emailnotification} || ''); + my $emailnotificationold = trim($::FORM{emailnotificationold} || ''); + my $groupsetold = trim($::FORM{groupsetold} || ''); + + my $groupset = 0; + foreach (keys %::FORM) { + next unless /^bit_/; + #print "$_=$::FORM{$_}
\n"; + $groupset |= $::FORM{$_}; + } + + CheckUser($userold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$product' or WHERE='$productold' + + if ($groupset != $groupsetold) { + SendSQL("UPDATE profiles + SET groupset=" . $groupset . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated permissions.\n"; + } + +=for me + + if ($emailnotification ne $emailnotificationold) { + SendSQL("UPDATE profiles + SET emailnotification=" . $emailnotification . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated email notification.
\n"; + } + +=cut + + if ($password ne $passwordold) { + SendSQL("UPDATE profiles + SET password=" . SqlQuote($password) . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated password.
\n"; + } + if ($realname ne $realnameold) { + SendSQL("UPDATE profiles + SET realname=" . SqlQuote($realname) . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated real name.
\n"; + } + if ($user ne $userold) { + unless ($user) { + print "Sorry, I can't delete the user's name."; + PutTrailer($localtrailer); + exit; + } + if (TestUser($user)) { + print "Sorry, user name '$user' is already in use."; + PutTrailer($localtrailer); + exit; + } + + SendSQL("UPDATE profiles + SET login_name=" . SqlQuote($user) . " + WHERE login_name=" . SqlQuote($userold)); + + print "Updated user's name.
\n"; + } + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.
\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}
\n"; +} diff --git a/editversions.cgi b/editversions.cgi new file mode 100755 index 000000000..7ac8032b2 --- /dev/null +++ b/editversions.cgi @@ -0,0 +1,542 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# +# Direct any questions on this source code to +# +# Holger Schurig + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text +# TestVersion: just returns if the specified product/version combination exists +# CheckVersion: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + +sub TestVersion ($$) +{ + my ($prod,$ver) = @_; + + # does the product exist? + SendSQL("SELECT program,value + FROM versions + WHERE program=" . SqlQuote($prod) . " and value=" . SqlQuote($ver)); + return FetchOneColumn(); +} + +sub CheckVersion ($$) +{ + my ($prod,$ver) = @_; + + # do we have the version? + unless ($ver) { + print "Sorry, you haven't specified a version."; + PutTrailer(); + exit; + } + + CheckProduct($prod); + + unless (TestVersion $prod,$ver) { + print "Sorry, version '$ver' for product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit a version +# + +sub EmitFormElements ($$) +{ + my ($product, $version) = @_; + + print " Version:\n"; + print " \n"; + print " \n"; +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the query page", @_); + + my $count = $#links; + my $num = 0; + print "

\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "\n\n"; +} + + + + + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete versions.\n"; + PutTrailer(); + exit; +} + + +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $version = trim($::FORM{version} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer; +if ($version) { + $localtrailer = "edit more versions"; +} else { + $localtrailer = "edit more versions"; +} + + + +# +# product = '' -> Show nice list of versions +# + +unless ($product) { + PutHeader("Select product"); + + SendSQL("SELECT products.product,products.description,'xyzzy' + FROM products + GROUP BY products.product + ORDER BY products.product"); + print "\n"; + print " \n"; + print " \n"; + print " \n"; + #print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($product, $description, $bugs) = FetchSQLData(); + $description ||= "missing"; + $bugs ||= "none"; + print "\n"; + print " \n"; + print " \n"; + print " \n"; + #print " \n"; + } + print "
Edit versions of ...DescriptionBugsEdit
$product$description$bugsEdit
\n"; + + PutTrailer(); + exit; +} + + + +# +# action='' -> Show nice list of versions +# + +unless ($action) { + PutHeader("Select version"); + CheckProduct($product); + +=for me + + # Das geht nicht wie vermutet. Ich bekomme nicht alle Versionen + # angezeigt! Schade. Ich würde gerne sehen, wieviel Bugs pro + # Version angegeben sind ... + + SendSQL("SELECT value,program,COUNT(bug_id) + FROM versions LEFT JOIN bugs + ON program=product AND value=version + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + +=cut + + SendSQL("SELECT value,program + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + + print "\n"; + print " \n"; + #print " \n"; + print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($version,$dummy,$bugs) = FetchSQLData(); + $bugs ||= 'none'; + print "\n"; + print " \n"; + #print " \n"; + print " \n"; + print ""; + } + print "\n"; + print " \n"; + print " \n"; + print "
Edit version ...BugsAction
$version$bugsDelete
Add a new versionAdd
\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new version +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add version"); + CheckProduct($product); + + #print "This page lets you add a new version to a bugzilla-tracked product.\n"; + + print "

\n"; + print "\n"; + + EmitFormElements($product, $version); + + print "
\n
\n"; + print "\n"; + print "\n"; + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add version entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new version"); + CheckProduct($product); + + # Cleanups and valididy checks + + unless ($version) { + print "You must enter a text for the new version. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestVersion($product,$version)) { + print "The version '$version' already exists. Please press\n"; + print "Back and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + # Add the new version + SendSQL("INSERT INTO versions ( " . + "value, program" . + " ) VALUES ( " . + SqlQuote($version) . "," . + SqlQuote($product) . ")"); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.

\n"; + PutTrailer($localtrailer); + exit; +} + + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete version"); + CheckVersion($product, $version); + + SendSQL("SELECT count(bug_id),product,version + FROM bugs + GROUP BY product,version + HAVING product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + my $bugs = FetchOneColumn(); + + print "\n"; + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + print "\n"; + print " \n"; + print " \n"; + print "\n"; + print " \n"; + print " \n"; + print "
PartValue
Product:$product
Version:$version
Bugs:", $bugs || 'none' , "
\n"; + + print "

Confirmation

\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this version. +You must reassign those bugs to another version before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "
\n", + "There are bugs entered for this version! When you delete this ", + "version, all stored bugs will be deleted, too. ", + "You could not even see the bug history for this version anymore!\n", + "
\n"; + } + + print "

Do you really want to delete this version?

\n"; + print "

\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "
"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the version +# + +if ($action eq 'delete') { + PutHeader("Deleting version"); + CheckVersion($product,$version); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + versions WRITE, + dependencies WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.
\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + print "Bugs deleted.
\n"; + + SendSQL("DELETE FROM versions + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($version)); + print "Version deleted.

\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit version form +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit version"); + CheckVersion($product,$version); + + print "

\n"; + print "\n"; + + EmitFormElements($product, $version); + + print "
\n"; + + print "\n"; + print "\n"; + print "\n"; + + print "
"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='update' -> update the version +# + +if ($action eq 'update') { + PutHeader("Update version"); + + my $versionold = trim($::FORM{versionold} || ''); + + CheckVersion($product,$versionold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$version' or WHERE='$versionold' + + SendSQL("LOCK TABLES bugs WRITE, + versions WRITE"); + + if ($version ne $versionold) { + unless ($version) { + print "Sorry, I can't delete the version text."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestVersion($product,$version)) { + print "Sorry, version '$version' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE bugs + SET version=" . SqlQuote($version) . " + WHERE version=" . SqlQuote($versionold) . " + AND product=" . SqlQuote($product)); + SendSQL("UPDATE versions + SET value=" . SqlQuote($version) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($versionold)); + unlink "data/versioncache"; + print "Updated version.
\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.
\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}
\n"; +} diff --git a/query.cgi b/query.cgi index b35cdf433..f092b280c 100755 --- a/query.cgi +++ b/query.cgi @@ -583,7 +583,7 @@ if (UserInGroup("tweakparams")) { print "Edit Bugzilla operating parameters
\n"; } if (UserInGroup("editcomponents")) { - print "Edit Bugzilla components
\n"; + print "Edit Bugzilla products and components
\n"; } if (defined $::COOKIE{"Bugzilla_login"}) { print "Log in as someone besides $::COOKIE{'Bugzilla_login'}
\n"; -- cgit v1.2.3-24-g4f1b