]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1128853: Bugzilla shouldn't try to write API tokens into the shadow DB
authorByron Jones <glob@mozilla.com>
Thu, 5 Mar 2015 04:57:51 +0000 (12:57 +0800)
committerByron Jones <glob@mozilla.com>
Thu, 5 Mar 2015 04:57:51 +0000 (12:57 +0800)
r=dkl,a=glob

14 files changed:
Bugzilla.pm
Bugzilla/Token.pm
template/en/default/account/prefs/prefs.html.tmpl
template/en/default/admin/components/create.html.tmpl
template/en/default/admin/components/edit.html.tmpl
template/en/default/admin/products/create.html.tmpl
template/en/default/admin/sudo.html.tmpl
template/en/default/attachment/create.html.tmpl
template/en/default/attachment/edit.html.tmpl
template/en/default/bug/create/create.html.tmpl
template/en/default/bug/show-header.html.tmpl
template/en/default/global/header.html.tmpl
template/en/default/list/list.html.tmpl
template/en/default/request/queue.html.tmpl

index 46d6182cd469b0feee8f0317385eebfaaee63340..6ca46f430f1a5e33ea912c46442e1e3daf54dff7 100644 (file)
@@ -537,6 +537,11 @@ sub switch_to_main_db {
     return $class->dbh_main;
 }
 
+sub is_shadow_db {
+    my $class = shift;
+    return $class->request_cache->{dbh} != $class->dbh_main;
+}
+
 sub fields {
     my ($class, $criteria) = @_;
     $criteria ||= {};
@@ -942,6 +947,12 @@ Switch from using the main database to using the shadow database.
 
 Change the database object to refer to the main database.
 
+=item C<is_shadow_db>
+
+Returns true if the currently active database is the shadow database.
+Returns false if a the currently active database is the man database, or if a
+shadow database is not configured or enabled.
+
 =item C<params>
 
 The current Parameters of Bugzilla, as a hashref. If C<data/params.json>
index 24ffad3c34a88bde966781379914f4b4aaec174c..84d86b8c6d6bf4752a79a5a8bfe7ad5d45b73213 100644 (file)
@@ -432,6 +432,9 @@ sub _create_token {
     trick_taint($tokentype);
     trick_taint($eventdata);
 
+    my $is_shadow = Bugzilla->is_shadow_db;
+    $dbh = Bugzilla->switch_to_main_db() if $is_shadow;
+
     $dbh->bz_start_transaction();
 
     my $token = GenerateUniqueToken();
@@ -444,8 +447,10 @@ sub _create_token {
     if (wantarray) {
         my (undef, $token_ts, undef) = GetTokenData($token);
         $token_ts = str2time($token_ts);
+        Bugzilla->switch_to_shadow_db() if $is_shadow;
         return ($token, $token_ts);
     } else {
+        Bugzilla->switch_to_shadow_db() if $is_shadow;
         return $token;
     }
 }
index 96e02812f73088fd6fb9a0758feae9855ff6d37e..21a823fb647239a2bc67e0362f04f07fb1f6bd4e 100644 (file)
@@ -55,6 +55,7 @@
 [% PROCESS global/header.html.tmpl
    title = current_tab.label
    subheader = filtered_login
+   generate_api_token = 1
    style_urls = ['skins/standard/admin.css']
    javascript_urls = ['js/util.js', 'js/field.js', 'js/TUI.js']
    doc_section = current_tab.doc_section
index 4db4a489c56ab30f3df6f9bb885e7d596c5e5619..96c9ce384c2163783a8227afce1fe253bb017455 100644 (file)
@@ -14,6 +14,7 @@
 [% title = BLOCK %]Add component to the [% product.name FILTER html %] product[% END %]
 [% PROCESS global/header.html.tmpl
   title = title
+  generate_api_token = 1
   style_urls = ['skins/standard/admin.css']
   yui = [ 'autocomplete' ]
   javascript_urls = [ "js/field.js" ]
index 9998845e215eb9f5d924732dac281db072317819..c4da1181b42aaa4129b2661c4ded1db1a70d3e56 100644 (file)
@@ -18,6 +18,7 @@
 [% END %]
 [% PROCESS global/header.html.tmpl
   title = title
+  generate_api_token = 1
   style_urls = ['skins/standard/admin.css']
   yui = [ 'autocomplete' ]
   javascript_urls = [ "js/field.js" ]
index b34f67b629a2441dcd2af54b8447a56b7aad5655..0dcfd7283d481fcaf41a4e41596e2d38e5865a35 100644 (file)
@@ -17,6 +17,7 @@
 
 [% PROCESS global/header.html.tmpl
   title = title
+  generate_api_token = 1
   style_urls = ['skins/standard/admin.css']
   javascript_urls = ['js/util.js', 'js/field.js']
   yui = [ 'autocomplete' ]
index b3f748697d467ebea903b117f8842802facfa986..8cdfb520442faba11c66ca39960cdfa2cb26fcc1 100644 (file)
@@ -8,6 +8,7 @@
 
 [% PROCESS global/header.html.tmpl
    title = "Begin sudo session"
+   generate_api_token = 1
    style_urls = ['skins/standard/admin.css']
    doc_section = "administering/users.html#impersonating-users"
  %]
index 13c13cdb9a82274bcb5200c33993c696835a0dc5..e566b428eed1b8af2356c21ebafb3320b315b4cf 100644 (file)
@@ -16,6 +16,7 @@
   title = title
   header = header
   subheader = subheader
+  generate_api_token = 1
   style_urls = ['skins/standard/bug.css']
   yui = [ 'autocomplete' ]
   javascript_urls = [ "js/attachment.js", 'js/field.js', "js/util.js", "js/TUI.js" ]
index 497f89a8d2706238429d22472cc1fb7ca667ffc6..184cdde054283f970c7e265d7ea0a530946409e8 100644 (file)
@@ -21,6 +21,7 @@
   title = title
   header = header
   subheader = subheader
+  generate_api_token = 1
   doc_section = "using/editing.html#attachments"
   javascript_urls = ['js/attachment.js', 'js/field.js']
   style_urls = ['skins/standard/bug.css']
index 5547ddb5550dd37ae775f1e00b0c1e68cc6891b0..29b17d41017fd7d91284dee78d6c5af24426fc30 100644 (file)
@@ -11,6 +11,7 @@
 
 [% PROCESS global/header.html.tmpl
   title = title
+  generate_api_token = 1
   yui = [ 'autocomplete', 'calendar', 'datatable', 'button' ]
   style_urls = ['skins/standard/bug.css']
   javascript_urls = [ "js/attachment.js", "js/util.js",
index 4cd7aaa38b7ffb0db668434aadbe6c55ff501300..f18afed961578ac134b44372f94dc17dbfdb0c91 100644 (file)
@@ -23,6 +23,7 @@
   [% title = title _ "($filtered_alias) " %]
 [% END %]
 [% title = title _ filtered_desc %]
+[% generate_api_token = 1 %]
 [% yui = ['autocomplete', 'calendar'] %]
 [% yui.push('container') IF user.can_tag_comments %]
 [% javascript_urls = [ "js/util.js", "js/field.js", "js/comments.js" ] %]
index 5c731c008a001037349fdb2b91358b0c1f10cf68..5b3cd03f360bf3187e34658102e0db3116d70c13 100644 (file)
@@ -20,6 +20,7 @@
   # style_urls: list. List of URLs to CSS style sheets.
   # message: string. A message to display to the user. May contain HTML.
   # atomlink: Atom link URL, May contain HTML
+  # generate_api_token: generate a token which can be used to make authenticated webservice calls
   #%]
 
 [% IF message %]
@@ -37,6 +38,7 @@
   no_yui = 0
   jquery = []
   jquery_css = []
+  generate_api_token = 0
 %]
 
 [% IF NOT no_yui %]
                 version_required:
                     "You must select a Version for this [% terms.bug %]."
             }
-            [% IF javascript_urls.containsany(['js/bug.js', 'js/field.js', 'js/comment-tagging.js']) %]
+            [% IF generate_api_token %]
               , api_token: '[% get_api_token FILTER js FILTER html %]'
             [% END %]
         };
index 259b26cf911d32034a9eaa697faf1c0772e80407..d5022778ed9ffb9d0a3a47cc7a17cb3f1a30476a 100644 (file)
@@ -59,6 +59,7 @@
 
 [% PROCESS global/header.html.tmpl
   title = title
+  generate_api_token = dotweak
   atomlink = "buglist.cgi?$urlquerypart&title=$title&ctype=atom" 
   yui = [ 'autocomplete', 'calendar' ]
   javascript_urls = [ "js/util.js", "js/field.js", "js/TUI.js" ]
index f64583acdf90a7242947ab9ace9387f0445b5b60..828bdba9f9ab62c87916f62794220f12ff5aed43 100644 (file)
@@ -11,6 +11,7 @@
 
 [% PROCESS global/header.html.tmpl
   title="Request Queue"
+  generate_api_token = 1
   onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');"
   javascript_urls=["js/productform.js", "js/field.js"]
   style_urls = ['skins/standard/buglist.css']