]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 313020: Implement the ability to add individual bugs to saved searches - Patch...
authorlpsolit%gmail.com <>
Wed, 26 Oct 2005 00:55:02 +0000 (00:55 +0000)
committerlpsolit%gmail.com <>
Wed, 26 Oct 2005 00:55:02 +0000 (00:55 +0000)
Bugzilla/Constants.pm
Bugzilla/DB/Schema.pm
Bugzilla/User.pm
buglist.cgi
checksetup.pl
skins/standard/global.css
template/en/default/global/per-bug-queries.html.tmpl [new file with mode: 0644]
template/en/default/global/setting-descs.none.tmpl
template/en/default/global/useful-links.html.tmpl
template/en/default/global/user-error.html.tmpl

index 078c988b6fe9d1a249d6c0b0d0f5a88f200d82e9..795f0096b2049cbb9426b8703ef9bc614290e0cc 100644 (file)
@@ -65,6 +65,9 @@ use base qw(Exporter);
     DEFAULT_COLUMN_LIST
     DEFAULT_QUERY_NAME
 
+    QUERY_LIST
+    LIST_OF_BUGS
+
     COMMENT_COLS
 
     UNLOCK_ABORT
@@ -173,6 +176,10 @@ use constant DEFAULT_COLUMN_LIST => (
 # for the default settings.
 use constant DEFAULT_QUERY_NAME => '(Default query)';
 
+# The possible types for saved searches.
+use constant QUERY_LIST => 0;
+use constant LIST_OF_BUGS => 1;
+
 # The column length for displayed (and wrapped) bug comments.
 use constant COMMENT_COLS => 80;
 
index 8379f0b122649b97a1e3482005e339eab042a31c..5ffb41216efae7ee89475bd09d9e707f9fc61ce3 100644 (file)
@@ -665,6 +665,7 @@ use constant ABSTRACT_SCHEMA => {
             name         => {TYPE => 'varchar(64)', NOTNULL => 1},
             linkinfooter => {TYPE => 'BOOLEAN', NOTNULL => 1},
             query        => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
+            query_type   => {TYPE => 'BOOLEAN', NOTNULL => 1},
         ],
         INDEXES => [
             namedqueries_userid_idx => {FIELDS => [qw(userid name)],
index 7f3736c28d65e33bc9b0d2ab9e96ac89b88042ea..6beb16a8b2e82d618e8278359ac0f7431158e400 100644 (file)
@@ -198,7 +198,7 @@ sub queries {
 
     my $dbh = Bugzilla->dbh;
     my $sth = $dbh->prepare(q{ SELECT
-                             DISTINCT name, query, linkinfooter,
+                             DISTINCT name, query, linkinfooter, query_type,
                                       CASE WHEN whine_queries.id IS NOT NULL
                                       THEN 1 ELSE 0 END,
                                       UPPER(name) AS uppername 
@@ -221,7 +221,8 @@ sub queries {
                           name         => $row->[0],
                           query        => $row->[1],
                           linkinfooter => $row->[2],
-                          usedinwhine  => $row->[3],
+                          query_type   => $row->[3],
+                          usedinwhine  => $row->[4],
                         });
     }
     $self->{queries} = \@queries;
index 53f810c3cc0a79324319271e8458ce3cdb4fc690..cb49d2a312e04f01d1599f96aa337cdd1945157f 100755 (executable)
@@ -39,6 +39,7 @@ use Bugzilla::Search;
 use Bugzilla::Search::Quicksearch;
 use Bugzilla::Constants;
 use Bugzilla::User;
+use Bugzilla::Bug;
 
 # Include the Bugzilla CGI and general utility library.
 require "globals.pl";
@@ -207,6 +208,7 @@ sub LookupNamedQuery {
     my $dbh = Bugzilla->dbh;
     # $name is safe -- we only use it below in a SELECT placeholder and then 
     # in error messages (which are always HTML-filtered).
+    $name || ThrowUserError("query_name_missing");
     trick_taint($name);
     my $result = $dbh->selectrow_array("SELECT query FROM namedqueries" 
                           . " WHERE userid = ? AND name = ?"
@@ -232,14 +234,17 @@ sub LookupNamedQuery {
 #         empty, or we will throw a UserError.
 # link_in_footer (optional) - 1 if the Named Query should be 
 # displayed in the user's footer, 0 otherwise.
+# query_type (optional) - 1 if the Named Query contains a list of
+# bug IDs only, 0 otherwise (default).
 #
 # All parameters are validated before passing them into the database.
 #
 # Returns: A boolean true value if the query existed in the database 
 # before, and we updated it. A boolean false value otherwise.
 sub InsertNamedQuery {
-    my ($userid, $query_name, $query, $link_in_footer) = @_;
+    my ($userid, $query_name, $query, $link_in_footer, $query_type) = @_;
     $link_in_footer ||= 0;
+    $query_type ||= QUERY_LIST;
     $query_name = trim($query_name);
     Bugzilla->login(LOGIN_REQUIRED);
     my $dbh = Bugzilla->dbh;
@@ -268,15 +273,15 @@ sub InsertNamedQuery {
     if ($result) {
         $query_existed_before = 1;
         $dbh->do("UPDATE namedqueries"
-            . " SET query = ?, linkinfooter = ?"
+            . " SET query = ?, linkinfooter = ?, query_type = ?"
             . " WHERE userid = ? AND name = ?"
-            , undef, ($query, $link_in_footer, $userid, $query_name));
+            , undef, ($query, $link_in_footer, $query_type, $userid, $query_name));
     } else {
         $query_existed_before = 0;
         $dbh->do("INSERT INTO namedqueries"
-            . " (userid, name, query, linkinfooter)"
-            . " VALUES (?, ?, ?, ?)"
-            , undef, ($userid, $query_name, $query, $link_in_footer));
+            . " (userid, name, query, linkinfooter, query_type)"
+            . " VALUES (?, ?, ?, ?, ?)"
+            , undef, ($userid, $query_name, $query, $link_in_footer, $query_type));
     }
 
     $dbh->bz_unlock_tables();
@@ -436,11 +441,35 @@ elsif (($cgi->param('cmdtype') eq "doit") && defined $cgi->param('remtype')) {
         Bugzilla->login(LOGIN_REQUIRED);
         my $userid = Bugzilla->user->id;
         my $query_name = $cgi->param('newqueryname');
-
+        my $new_query = $cgi->param('newquery');
+        my $query_type = QUERY_LIST;
+        # If add_bugids is true, we are adding individual bugs to a saved
+        # search. We get the existing list of bug IDs (if any) and append
+        # the new ones.
+        if ($cgi->param('add_bugids')) {
+            my %bug_ids;
+            foreach my $bug_id (split(/[\s,]+/, $cgi->param('bug_ids'))) {
+                next unless $bug_id;
+                ValidateBugID($bug_id);
+                $bug_ids{$bug_id} = 1;
+            }
+            ThrowUserError("no_bug_ids") unless scalar(keys %bug_ids);
+
+            if (!trim($query_name)) {
+                # No new query name has been given. We append new bug IDs
+                # to the existing list.
+                $query_name = $cgi->param('oldqueryname');
+                my $old_query = LookupNamedQuery($query_name);
+                foreach my $bug_id (split(/[\s,=]+/, $old_query)) {
+                    $bug_ids{$bug_id} = 1 if detaint_natural($bug_id);
+                }
+            }
+            $new_query = "bug_id=" . join(',', sort {$a <=> $b} keys %bug_ids);
+            $query_type = LIST_OF_BUGS;
+        }
         my $tofooter = 1;
-        my $existed_before = InsertNamedQuery($userid, $query_name, 
-                                              scalar $cgi->param('newquery'),
-                                              $tofooter);
+        my $existed_before = InsertNamedQuery($userid, $query_name, $new_query,
+                                              $tofooter, $query_type);
         if ($existed_before) {
             $vars->{'message'} = "buglist_updated_named_query";
         }
index e3c5a4af5e9f7b07d8190be16c379ac9548adab0..d04a07b7c758ffa1787372963e857e0adf18005c 100755 (executable)
@@ -4038,6 +4038,10 @@ if ($dbh->bz_column_info("series", "public")) {
 $dbh->bz_add_column('attachments', 'isurl',
                     {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0});
 
+# 2005-10-21 LpSolit@gmail.com - Bug 313020
+$dbh->bz_add_column('namedqueries', 'query_type',
+                    {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0});
+
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
 #
@@ -4180,6 +4184,9 @@ add_setting ("post_bug_submit_action", {"next_bug" => 1,
 # 2005-06-29 wurblzap@gmail.com -- Bug 257767
 add_setting ('csv_colsepchar', {',' => 1, ';' => 2 }, ',' );
 
+# 2005-10-21 LpSolit@gmail.com -- Bug 313020
+add_setting('per_bug_queries', {'on' => 1, 'off' => 2}, 'on');
+
 ###########################################################################
 # Create Administrator  --ADMIN--
 ###########################################################################
index ea95e74602f34dea87272dd68f79ca6182e2e41c..7d6e0abbaa1a47d9b41eb490c03ca3b7c4213496 100644 (file)
@@ -210,7 +210,8 @@ body
 
     #footer #links-actions,
     #footer #links-edit,
-    #footer #links-saved
+    #footer #links-saved,
+    #footer #links-special
     {
         display: table-row;
     }
diff --git a/template/en/default/global/per-bug-queries.html.tmpl b/template/en/default/global/per-bug-queries.html.tmpl
new file mode 100644 (file)
index 0000000..537ed01
--- /dev/null
@@ -0,0 +1,40 @@
+[%# 1.0@bugzilla.org %]
+[%# The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (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.
+  #
+  # The Original Code is the Bugzilla Bug Tracking System.
+  #
+  # Contributor(s): Frédéric Buclin <LpSolit@gmail.com>
+  #%]
+
+[% IF user.id && user.settings.per_bug_queries.value == "on" %]
+  <div id="links-special">
+    <div class="label">&nbsp;</div>
+    <div class="links">
+      <form action="buglist.cgi" method="get">
+        <input type="hidden" name="cmdtype" value="doit">
+        <input type="hidden" name="remtype" value="asnamed">
+        <input type="hidden" name="add_bugids" value="1">
+        <input type="submit" value="Add"> [% terms.bugs %]
+        <input type="text" name="bug_ids" size="8" maxlength="80"> to
+        <select name="oldqueryname">
+          [% FOREACH q = user.queries %]
+            [% IF q.query_type == constants.LIST_OF_BUGS %]
+              <option value="[% q.name FILTER html %]">
+                [% q.name FILTER html %]</option>
+            [% END %]
+          [% END %]
+        </select>
+        or to the new saved search:
+        <input type="text" name="newqueryname" size="20" maxlength="64">
+      </form>
+    </div>
+  </div>
+[% END %]
index 9957cf6a48f3b812061505f43ec26769d87676c3..3ca7fe3f38650d13aad06285ddab98ef435bcb30 100644 (file)
@@ -27,7 +27,8 @@
    "newest_to_oldest_desc_first"      => "Newest to Oldest, but keep Description at the top",
    "off"                              => "Off",
    "oldest_to_newest"                 => "Oldest to Newest",
-   "on"                               => "On"
+   "on"                               => "On",
+   "per_bug_queries"                  => "Add individual $terms.bugs to saved searches",
    "post_bug_submit_action"           => "After changing $terms.abug",
    "next_bug"                         => "Show next $terms.bug in my list",
    "same_bug"                         => "Show the updated $terms.bug",
index ef7f3d19f360682b9094cfcbd472e77b447daf82..b2e598163f604192166172c904a3f7044e700d0a 100644 (file)
     </div>
   </div>
 
+  [%# Individual bugs addition %]
+
+  [% PROCESS "global/per-bug-queries.html.tmpl" %]
+
   [%# Sections of links to more things users can do on this installation. %]
   [% Hook.process("end") %]
 </div>
index b1c8e7c91683cfb290ccc20393212201369ba3c8..299cf2d2bf2b2b50a4a286b1a802f12a7e15cced 100644 (file)
     [% title = BLOCK %]No [% terms.Bugs %] Chosen[% END %]
     You apparently didn't choose any [% terms.bugs %] to modify.
 
+  [% ELSIF error == "no_bug_ids" %]
+    [% title = BLOCK %]No [% terms.Bugs %] Chosen[% END %]
+    You didn't choose any [% terms.bugs %] to add to the saved search.
+
   [% ELSIF error == "no_component_change_for_multiple_products" %]
     [% title = "Action Not Permitted" %]
     You cannot change the component for a list of [% terms.bugs %] covering more than