summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-10-24 07:21:06 +0200
committermkanat%bugzilla.org <>2009-10-24 07:21:06 +0200
commita2dd3b00284fd4724d3408274cb1156c7a77d187 (patch)
tree4aa41a1c8cea9d31aaccddc4685f8f1c5991c1b4
parent401fb65f2e6f9031cedf47fb6d951236b5c624d3 (diff)
downloadbugzilla-a2dd3b00284fd4724d3408274cb1156c7a77d187.tar.gz
bugzilla-a2dd3b00284fd4724d3408274cb1156c7a77d187.tar.xz
Bug 520948: Use Bugzilla->feature and feature_enabled everywhere instead of checking if modules are installed
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit
-rw-r--r--Bugzilla/Config/Common.pm29
-rw-r--r--Bugzilla/Install/Requirements.pm4
-rw-r--r--Bugzilla/JobQueue.pm4
-rw-r--r--Bugzilla/Template.pm2
-rw-r--r--Bugzilla/Update.pm9
-rw-r--r--Bugzilla/Util.pm9
-rwxr-xr-xchart.cgi8
-rwxr-xr-x[-rw-r--r--]jsonrpc.cgi8
-rwxr-xr-xreport.cgi4
-rwxr-xr-xreports.cgi15
-rw-r--r--template/en/default/global/code-error.html.tmpl37
-rw-r--r--template/en/default/index.html.tmpl3
-rw-r--r--template/en/default/reports/menu.html.tmpl44
-rwxr-xr-xxmlrpc.cgi5
14 files changed, 86 insertions, 95 deletions
diff --git a/Bugzilla/Config/Common.pm b/Bugzilla/Config/Common.pm
index b722795d4..95866b032 100644
--- a/Bugzilla/Config/Common.pm
+++ b/Bugzilla/Config/Common.pm
@@ -257,22 +257,29 @@ sub check_user_verify_class {
# the login method as LDAP, we won't notice, but all logins will fail.
# So don't do that.
+ my $params = Bugzilla->params;
my ($list, $entry) = @_;
$list || return 'You need to specify at least one authentication mechanism';
for my $class (split /,\s*/, $list) {
my $res = check_multi($class, $entry);
return $res if $res;
if ($class eq 'RADIUS') {
- eval "require Authen::Radius";
- return "Error requiring Authen::Radius: '$@'" if $@;
- return "RADIUS servername (RADIUS_server) is missing" unless Bugzilla->params->{"RADIUS_server"};
- return "RADIUS_secret is empty" unless Bugzilla->params->{"RADIUS_secret"};
+ if (!Bugzilla->feature('auth_radius')) {
+ return "RADIUS support is not available. Run checksetup.pl"
+ . " for more details";
+ }
+ return "RADIUS servername (RADIUS_server) is missing"
+ if !$params->{"RADIUS_server"};
+ return "RADIUS_secret is empty" if !$params->{"RADIUS_secret"};
}
elsif ($class eq 'LDAP') {
- eval "require Net::LDAP";
- return "Error requiring Net::LDAP: '$@'" if $@;
- return "LDAP servername (LDAPserver) is missing" unless Bugzilla->params->{"LDAPserver"};
- return "LDAPBaseDN is empty" unless Bugzilla->params->{"LDAPBaseDN"};
+ if (!Bugzilla->feature('auth_ldap')) {
+ return "LDAP support is not available. Run checksetup.pl"
+ . " for more details";
+ }
+ return "LDAP servername (LDAPserver) is missing"
+ if !$params->{"LDAPserver"};
+ return "LDAPBaseDN is empty" if !$params->{"LDAPBaseDN"};
}
}
return "";
@@ -323,9 +330,9 @@ sub check_notification {
sub check_smtp_auth {
my $username = shift;
- if ($username) {
- eval "require Authen::SASL";
- return "Error requiring Authen::SASL: '$@'" if $@;
+ if ($username and !Bugzilla->feature('smtp_auth')) {
+ return "SMTP Authentication is not available. Run checksetup.pl for"
+ . " more details";
}
return "";
}
diff --git a/Bugzilla/Install/Requirements.pm b/Bugzilla/Install/Requirements.pm
index 70974a373..86b4813d1 100644
--- a/Bugzilla/Install/Requirements.pm
+++ b/Bugzilla/Install/Requirements.pm
@@ -151,7 +151,7 @@ sub OPTIONAL_MODULES {
},
{
package => 'Chart',
- module => 'Chart::Base',
+ module => 'Chart::Lines',
version => '1.0',
feature => [qw(new_charts old_charts)],
},
@@ -179,7 +179,7 @@ sub OPTIONAL_MODULES {
package => 'XML-Twig',
module => 'XML::Twig',
version => 0,
- feature => ['moving'],
+ feature => ['moving', 'updates'],
},
{
package => 'MIME-tools',
diff --git a/Bugzilla/JobQueue.pm b/Bugzilla/JobQueue.pm
index 102f58bc6..d10df9804 100644
--- a/Bugzilla/JobQueue.pm
+++ b/Bugzilla/JobQueue.pm
@@ -38,8 +38,8 @@ use constant JOB_MAP => {
sub new {
my $class = shift;
- if (!eval { require TheSchwartz; }) {
- ThrowCodeError('jobqueue_not_configured');
+ if (!Bugzilla->feature('jobqueue')) {
+ ThrowCodeError('feature_disabled', { feature => 'jobqueue' });
}
my $lc = Bugzilla->localconfig;
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 2e2ac4b08..d5e371f64 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -777,6 +777,8 @@ sub create {
'feature_enabled' => sub { return Bugzilla->feature(@_); },
+ 'install_string' => \&Bugzilla::Install::Util::install_string,
+
# These don't work as normal constants.
DB_MODULE => \&Bugzilla::Constants::DB_MODULE,
REQUIRED_MODULES =>
diff --git a/Bugzilla/Update.pm b/Bugzilla/Update.pm
index d3f780570..292ab626e 100644
--- a/Bugzilla/Update.pm
+++ b/Bugzilla/Update.pm
@@ -27,13 +27,9 @@ use constant TIMEOUT => 5; # Number of seconds before timeout.
# Look for new releases and notify logged in administrators about them.
sub get_notifications {
+ return if !Bugzilla->feature('updates');
return if (Bugzilla->params->{'upgrade_notification'} eq 'disabled');
- # If the XML::Twig module is missing, we won't be able to parse
- # the XML file. So there is no need to go further.
- eval("require XML::Twig");
- return if $@;
-
my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE;
# Update the local XML file if this one doesn't exist or if
# the last modification time (stat[9]) is older than TIME_INTERVAL.
@@ -128,9 +124,6 @@ sub get_notifications {
}
sub _synchronize_data {
- eval("require LWP::UserAgent");
- return {'error' => 'missing_package', 'package' => 'LWP::UserAgent'} if $@;
-
my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE;
my $ua = LWP::UserAgent->new();
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index a36b22c37..513e02857 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -124,12 +124,7 @@ sub html_light_quote {
dfn samp kbd big small sub sup tt dd dt dl ul li ol
fieldset legend);
- # Are HTML::Scrubber and HTML::Parser installed?
- eval { require HTML::Scrubber;
- require HTML::Parser;
- };
-
- if ($@) { # Package(s) not installed.
+ if (!Bugzilla->feature('html_desc')) {
my $safe = join('|', @allow);
my $chr = chr(1);
@@ -144,7 +139,7 @@ sub html_light_quote {
$text =~ s#$chr($safe)$chr#<$1>#go;
return $text;
}
- else { # Packages installed.
+ else {
# We can be less restrictive. We can accept elements with attributes.
push(@allow, qw(a blockquote q span));
diff --git a/chart.cgi b/chart.cgi
index 1aef2a251..0b46347b5 100755
--- a/chart.cgi
+++ b/chart.cgi
@@ -65,6 +65,12 @@ local our $template = Bugzilla->template;
local our $vars = {};
my $dbh = Bugzilla->dbh;
+my $user = Bugzilla->login(LOGIN_REQUIRED);
+
+if (!Bugzilla->feature('new_charts')) {
+ ThrowCodeError('feature_disabled', { feature => 'new_charts' });
+}
+
# Go back to query.cgi if we are adding a boolean chart parameter.
if (grep(/^cmd-/, $cgi->param())) {
my $params = $cgi->canonicalise_query("format", "ctype", "action");
@@ -96,8 +102,6 @@ if ($action eq "search") {
exit;
}
-my $user = Bugzilla->login(LOGIN_REQUIRED);
-
$user->in_group(Bugzilla->params->{"chartgroup"})
|| ThrowUserError("auth_failure", {group => Bugzilla->params->{"chartgroup"},
action => "use",
diff --git a/jsonrpc.cgi b/jsonrpc.cgi
index cd41663fa..25fb4c175 100644..100755
--- a/jsonrpc.cgi
+++ b/jsonrpc.cgi
@@ -27,10 +27,12 @@ use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::WebService::Constants;
-# This eval allows runtests to pass even if JSON::RPC isn't
-# installed.
+if (!Bugzilla->feature('jsonrpc')) {
+ ThrowCodeError('feature_disabled', { feature => 'jsonrpc' });
+}
+
+# This eval allows runtests.pl to pass.
eval { require Bugzilla::WebService::Server::JSONRPC; };
-$@ && ThrowCodeError('json_rpc_not_installed');
Bugzilla->usage_mode(USAGE_MODE_JSON);
diff --git a/report.cgi b/report.cgi
index 2f950948a..ca92fafc6 100755
--- a/report.cgi
+++ b/report.cgi
@@ -95,6 +95,10 @@ if (defined $cgi->param('format') && $cgi->param('format') eq "table") {
}
}
else {
+ if (!Bugzilla->feature('graphical_reports')) {
+ ThrowCodeError('feature_disabled', { feature => 'graphical_reports' });
+ }
+
if ($row_field && !$col_field) {
# 1D *charts* should be displayed horizontally (with an col_field only)
$col_field = $row_field;
diff --git a/reports.cgi b/reports.cgi
index 6eb4496cc..b53d9521e 100755
--- a/reports.cgi
+++ b/reports.cgi
@@ -45,19 +45,18 @@ use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Status;
-eval "use GD";
-$@ && ThrowCodeError("gd_not_installed");
-eval "use Chart::Lines";
-$@ && ThrowCodeError("chart_lines_not_installed");
+# If we're using bug groups for products, we should apply those restrictions
+# to viewing reports, as well. Time to check the login in that case.
+my $user = Bugzilla->login();
+
+if (!Bugzilla->feature('old_charts')) {
+ ThrowCodeError('feature_disabled', { feature => 'old_charts' });
+}
my $dir = bz_locations()->{'datadir'} . "/mining";
my $graph_url = 'graphs';
my $graph_dir = bz_locations()->{'libpath'} . '/' .$graph_url;
-# If we're using bug groups for products, we should apply those restrictions
-# to viewing reports, as well. Time to check the login in that case.
-my $user = Bugzilla->login();
-
Bugzilla->switch_to_shadow_db();
my $cgi = Bugzilla->cgi;
diff --git a/template/en/default/global/code-error.html.tmpl b/template/en/default/global/code-error.html.tmpl
index 8ad0c4ae9..3c9f73f4c 100644
--- a/template/en/default/global/code-error.html.tmpl
+++ b/template/en/default/global/code-error.html.tmpl
@@ -110,11 +110,6 @@
[% ELSIF error == "chart_file_open_fail" %]
Unable to open the chart datafile <tt>[% filename FILTER html %]</tt>.
- [% ELSIF error == "chart_lines_not_installed" %]
- [% admindocslinks = {'installation.html#install-perlmodules' => 'Installing Perl modules necessary for Charting'} %]
- Charts will not work without the Chart::Lines Perl module being installed.
- Run checksetup.pl for installation instructions.
-
[% ELSIF error == "column_not_null_without_default" %]
Failed adding the column [% name FILTER html %]:
You cannot add a NOT NULL column with no default to an existing table
@@ -167,11 +162,6 @@
'[% field.description FILTER html %]' ([% field.name FILTER html %])
is not a custom field.
- [% ELSIF error == "gd_not_installed" %]
- [% admindocslinks = {'installation.html#install-perlmodules' => 'Installing Perl modules necessary for Charting'} %]
- Charts will not work without the GD Perl module being installed.
- Run checksetup.pl for installation instructions.
-
[% ELSIF error == "illegal_content_type_method" %]
Your form submission got corrupted somehow. The <em>content
method</em> field, which specifies how the content type gets determined,
@@ -228,6 +218,15 @@
but you tried to flag it as obsolete while creating a new attachment to
[% terms.bug %] [%+ my_bug_id FILTER html %].
+ [% ELSIF error == "feature_disabled" %]
+ The [% install_string("feature_$feature") FILTER html %] feature is not
+ available in this [% terms.Bugzilla %].
+ [% IF user.in_group('admin') %]
+ If you would like to enable this feature, please run
+ <kbd>checksetup.pl</kbd> to see how to install the necessary
+ requirements for this feature.
+ [% END %]
+
[% ELSIF error == "flag_unexpected_object" %]
[% title = "Object Not Recognized" %]
Flags cannot be set for objects of type [% caller FILTER html %].
@@ -280,23 +279,11 @@
Inserting a <code>[% job FILTER html %]</code> job into the Job
Queue failed with the following error: [% errmsg FILTER html %]
- [% ELSIF error == "jobqueue_not_configured" %]
- Using the job queue system requires that certain Perl modules
- be installed. Run <code>checksetup.pl</code> to see what modules
- you are missing.
-
[% ELSIF error == "jobqueue_no_job_mapping" %]
<code>Bugzilla::JobQueue</code> has not been configured to handle
the job "[% job FILTER html %]". You need to add this job type
to the <code>JOB_MAP</code> constant in <code>Bugzilla::JobQueue</code>.
- [% ELSIF error == "json_rpc_not_installed" %]
- [% admindocslinks = { 'installation.html#install-perlmodules'
- => 'Installing Perl modules' } %]
- The JSON-RPC interface will not work without the <code>JSON::RPC</code>
- Perl module being installed. Run <code>checksetup.pl</code> for
- installation instructions.
-
[% ELSIF error == "ldap_bind_failed" %]
Failed to bind to the LDAP server. The error message was:
<code>[% errstr FILTER html %]</code>
@@ -426,12 +413,6 @@
The value "<code>[% value FILTER html %]</code>" is not in the list of
legal values for the <em>[% name FILTER html %]</em> setting.
- [% ELSIF error == "soap_not_installed" %]
- [% admindocslinks = {'installation.html#install-perlmodules' => 'Installing Perl modules'} %]
- The XMLRPC interface will not work without the SOAP::Lite Perl module being
- installed.
- Run checksetup.pl for installation instructions.
-
[% ELSIF error == "token_generation_error" %]
Something is seriously wrong with the token generation system.
diff --git a/template/en/default/index.html.tmpl b/template/en/default/index.html.tmpl
index 6231baa43..dd00d3550 100644
--- a/template/en/default/index.html.tmpl
+++ b/template/en/default/index.html.tmpl
@@ -97,9 +97,6 @@ YAHOO.util.Event.onDOMReady(onLoadActions);
<p class="notice">This message is only shown to logged in users with admin privs.
You can configure this notification from the
<a href="editparams.cgi?section=core#upgrade_notification">Parameters</a> page.</p>
- [% ELSIF release.error == "missing_package" %]
- <p>Missing package '[% release.package FILTER html %]'. This package is required to
- <a href="editparams.cgi?section=core#upgrade_notification">notify you about new releases</a>.</p>
[% ELSIF release.error == "cannot_download" %]
<p>The local XML file '[% release.xml_file FILTER html %]' cannot be created.
Please make sure the web server can write in this directory and that you can access
diff --git a/template/en/default/reports/menu.html.tmpl b/template/en/default/reports/menu.html.tmpl
index db5b19293..f7613ec01 100644
--- a/template/en/default/reports/menu.html.tmpl
+++ b/template/en/default/reports/menu.html.tmpl
@@ -48,28 +48,34 @@
</strong> -
tables of [% terms.bug %] counts in 1, 2 or 3 dimensions, as HTML or CSV.
</li>
- <li>
- <strong>
- <a href="query.cgi?format=report-graph">Graphical reports</a>
- </strong> -
- line graphs, bar and pie charts.
- </li>
-</ul>
-
-<h2>Change Over Time</h2>
-
-<ul>
- <li>
- <strong><a href="reports.cgi">Old Charts</a></strong> -
- plot the status and/or resolution of [% terms.bugs %] against
- time, for each product in your database.
- </li>
- [% IF user.in_group(Param("chartgroup")) %]
+ [% IF feature_enabled('graphical_reports') %]
<li>
- <strong><a href="chart.cgi">New Charts</a></strong> -
- plot any arbitrary search against time. Far more powerful.
+ <strong>
+ <a href="query.cgi?format=report-graph">Graphical reports</a>
+ </strong> -
+ line graphs, bar and pie charts.
</li>
[% END %]
</ul>
+[% IF feature_enabled('new_charts') OR feature_enabled('old_charts') %]
+ <h2>Change Over Time</h2>
+
+ <ul>
+ [% IF feature_enabled('old_charts') %]
+ <li>
+ <strong><a href="reports.cgi">Old Charts</a></strong> -
+ plot the status and/or resolution of [% terms.bugs %] against
+ time, for each product in your database.
+ </li>
+ [% END %]
+ [% IF feature_enabled('new_charts') AND user.in_group(Param("chartgroup")) %]
+ <li>
+ <strong><a href="chart.cgi">New Charts</a></strong> -
+ plot any arbitrary search against time. Far more powerful.
+ </li>
+ [% END %]
+ </ul>
+[% END %]
+
[% PROCESS global/footer.html.tmpl %]
diff --git a/xmlrpc.cgi b/xmlrpc.cgi
index c98dd1b73..994e3a485 100755
--- a/xmlrpc.cgi
+++ b/xmlrpc.cgi
@@ -22,11 +22,12 @@ use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::WebService::Constants;
-
+if (!Bugzilla->feature('xmlrpc')) {
+ ThrowCodeError('feature_disabled', { feature => 'xmlrpc' });
+}
# Use an eval here so that runtests.pl accepts this script even if SOAP-Lite
# is not installed.
eval { require Bugzilla::WebService::Server::XMLRPC; };
-$@ && ThrowCodeError('soap_not_installed');
Bugzilla->usage_mode(USAGE_MODE_XMLRPC);