Commit c1fa559e authored by Byron Jones's avatar Byron Jones

Bug 1128853: Bugzilla shouldn't try to write API tokens into the shadow DB

r=dkl,a=glob
parent dbc7a21e
...@@ -530,6 +530,11 @@ sub switch_to_main_db { ...@@ -530,6 +530,11 @@ sub switch_to_main_db {
return $class->dbh_main; return $class->dbh_main;
} }
sub is_shadow_db {
my $class = shift;
return $class->request_cache->{dbh} != $class->dbh_main;
}
sub fields { sub fields {
my ($class, $criteria) = @_; my ($class, $criteria) = @_;
$criteria ||= {}; $criteria ||= {};
...@@ -935,6 +940,12 @@ Switch from using the main database to using the shadow database. ...@@ -935,6 +940,12 @@ Switch from using the main database to using the shadow database.
Change the database object to refer to the main 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> =item C<params>
The current Parameters of Bugzilla, as a hashref. If C<data/params.json> The current Parameters of Bugzilla, as a hashref. If C<data/params.json>
......
...@@ -432,6 +432,9 @@ sub _create_token { ...@@ -432,6 +432,9 @@ sub _create_token {
trick_taint($tokentype); trick_taint($tokentype);
trick_taint($eventdata); trick_taint($eventdata);
my $is_shadow = Bugzilla->is_shadow_db;
$dbh = Bugzilla->switch_to_main_db() if $is_shadow;
$dbh->bz_start_transaction(); $dbh->bz_start_transaction();
my $token = GenerateUniqueToken(); my $token = GenerateUniqueToken();
...@@ -444,8 +447,10 @@ sub _create_token { ...@@ -444,8 +447,10 @@ sub _create_token {
if (wantarray) { if (wantarray) {
my (undef, $token_ts, undef) = GetTokenData($token); my (undef, $token_ts, undef) = GetTokenData($token);
$token_ts = str2time($token_ts); $token_ts = str2time($token_ts);
Bugzilla->switch_to_shadow_db() if $is_shadow;
return ($token, $token_ts); return ($token, $token_ts);
} else { } else {
Bugzilla->switch_to_shadow_db() if $is_shadow;
return $token; return $token;
} }
} }
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = current_tab.label title = current_tab.label
subheader = filtered_login subheader = filtered_login
generate_api_token = 1
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
javascript_urls = ['js/util.js', 'js/field.js', 'js/TUI.js'] javascript_urls = ['js/util.js', 'js/field.js', 'js/TUI.js']
doc_section = current_tab.doc_section doc_section = current_tab.doc_section
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
[% title = BLOCK %]Add component to the [% product.name FILTER html %] product[% END %] [% title = BLOCK %]Add component to the [% product.name FILTER html %] product[% END %]
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
generate_api_token = 1
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
yui = [ 'autocomplete' ] yui = [ 'autocomplete' ]
javascript_urls = [ "js/field.js" ] javascript_urls = [ "js/field.js" ]
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
[% END %] [% END %]
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
generate_api_token = 1
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
yui = [ 'autocomplete' ] yui = [ 'autocomplete' ]
javascript_urls = [ "js/field.js" ] javascript_urls = [ "js/field.js" ]
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
generate_api_token = 1
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
javascript_urls = ['js/util.js', 'js/field.js'] javascript_urls = ['js/util.js', 'js/field.js']
yui = [ 'autocomplete' ] yui = [ 'autocomplete' ]
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = "Begin sudo session" title = "Begin sudo session"
generate_api_token = 1
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
doc_section = "administering/users.html#impersonating-users" doc_section = "administering/users.html#impersonating-users"
%] %]
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
title = title title = title
header = header header = header
subheader = subheader subheader = subheader
generate_api_token = 1
style_urls = ['skins/standard/bug.css'] style_urls = ['skins/standard/bug.css']
yui = [ 'autocomplete' ] yui = [ 'autocomplete' ]
javascript_urls = [ "js/attachment.js", 'js/field.js', "js/util.js", "js/TUI.js" ] javascript_urls = [ "js/attachment.js", 'js/field.js', "js/util.js", "js/TUI.js" ]
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
title = title title = title
header = header header = header
subheader = subheader subheader = subheader
generate_api_token = 1
doc_section = "using/editing.html#attachments" doc_section = "using/editing.html#attachments"
javascript_urls = ['js/attachment.js', 'js/field.js'] javascript_urls = ['js/attachment.js', 'js/field.js']
style_urls = ['skins/standard/bug.css'] style_urls = ['skins/standard/bug.css']
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
generate_api_token = 1
yui = [ 'autocomplete', 'calendar', 'datatable', 'button' ] yui = [ 'autocomplete', 'calendar', 'datatable', 'button' ]
style_urls = ['skins/standard/bug.css'] style_urls = ['skins/standard/bug.css']
javascript_urls = [ "js/attachment.js", "js/util.js", javascript_urls = [ "js/attachment.js", "js/util.js",
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
[% title = title _ "($filtered_alias) " %] [% title = title _ "($filtered_alias) " %]
[% END %] [% END %]
[% title = title _ filtered_desc %] [% title = title _ filtered_desc %]
[% generate_api_token = 1 %]
[% yui = ['autocomplete', 'calendar'] %] [% yui = ['autocomplete', 'calendar'] %]
[% yui.push('container') IF user.can_tag_comments %] [% yui.push('container') IF user.can_tag_comments %]
[% javascript_urls = [ "js/util.js", "js/field.js" ] %] [% javascript_urls = [ "js/util.js", "js/field.js" ] %]
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# style_urls: list. List of URLs to CSS style sheets. # style_urls: list. List of URLs to CSS style sheets.
# message: string. A message to display to the user. May contain HTML. # message: string. A message to display to the user. May contain HTML.
# atomlink: Atom link URL, 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 %] [% IF message %]
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
onload = "" onload = ""
style_urls = [] style_urls = []
yui = [] yui = []
generate_api_token = 0
%] %]
[% SET yui_css = { [% SET yui_css = {
...@@ -175,7 +177,7 @@ ...@@ -175,7 +177,7 @@
version_required: version_required:
"You must select a Version for this [% terms.bug %]." "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 %]' , api_token: '[% get_api_token FILTER js FILTER html %]'
[% END %] [% END %]
}; };
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
generate_api_token = dotweak
atomlink = "buglist.cgi?$urlquerypart&title=$title&ctype=atom" atomlink = "buglist.cgi?$urlquerypart&title=$title&ctype=atom"
yui = [ 'autocomplete', 'calendar' ] yui = [ 'autocomplete', 'calendar' ]
javascript_urls = [ "js/util.js", "js/field.js", "js/TUI.js" ] javascript_urls = [ "js/util.js", "js/field.js", "js/TUI.js" ]
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title="Request Queue" title="Request Queue"
generate_api_token = 1
onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');" onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');"
javascript_urls=["js/productform.js", "js/field.js"] javascript_urls=["js/productform.js", "js/field.js"]
style_urls = ['skins/standard/buglist.css'] style_urls = ['skins/standard/buglist.css']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment