Commit a2dd3b00 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 520948: Use Bugzilla->feature and feature_enabled everywhere instead of…

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
parent 401fb65f
...@@ -257,22 +257,29 @@ sub check_user_verify_class { ...@@ -257,22 +257,29 @@ sub check_user_verify_class {
# the login method as LDAP, we won't notice, but all logins will fail. # the login method as LDAP, we won't notice, but all logins will fail.
# So don't do that. # So don't do that.
my $params = Bugzilla->params;
my ($list, $entry) = @_; my ($list, $entry) = @_;
$list || return 'You need to specify at least one authentication mechanism'; $list || return 'You need to specify at least one authentication mechanism';
for my $class (split /,\s*/, $list) { for my $class (split /,\s*/, $list) {
my $res = check_multi($class, $entry); my $res = check_multi($class, $entry);
return $res if $res; return $res if $res;
if ($class eq 'RADIUS') { if ($class eq 'RADIUS') {
eval "require Authen::Radius"; if (!Bugzilla->feature('auth_radius')) {
return "Error requiring Authen::Radius: '$@'" if $@; return "RADIUS support is not available. Run checksetup.pl"
return "RADIUS servername (RADIUS_server) is missing" unless Bugzilla->params->{"RADIUS_server"}; . " for more details";
return "RADIUS_secret is empty" unless Bugzilla->params->{"RADIUS_secret"}; }
return "RADIUS servername (RADIUS_server) is missing"
if !$params->{"RADIUS_server"};
return "RADIUS_secret is empty" if !$params->{"RADIUS_secret"};
} }
elsif ($class eq 'LDAP') { elsif ($class eq 'LDAP') {
eval "require Net::LDAP"; if (!Bugzilla->feature('auth_ldap')) {
return "Error requiring Net::LDAP: '$@'" if $@; return "LDAP support is not available. Run checksetup.pl"
return "LDAP servername (LDAPserver) is missing" unless Bugzilla->params->{"LDAPserver"}; . " for more details";
return "LDAPBaseDN is empty" unless Bugzilla->params->{"LDAPBaseDN"}; }
return "LDAP servername (LDAPserver) is missing"
if !$params->{"LDAPserver"};
return "LDAPBaseDN is empty" if !$params->{"LDAPBaseDN"};
} }
} }
return ""; return "";
...@@ -323,9 +330,9 @@ sub check_notification { ...@@ -323,9 +330,9 @@ sub check_notification {
sub check_smtp_auth { sub check_smtp_auth {
my $username = shift; my $username = shift;
if ($username) { if ($username and !Bugzilla->feature('smtp_auth')) {
eval "require Authen::SASL"; return "SMTP Authentication is not available. Run checksetup.pl for"
return "Error requiring Authen::SASL: '$@'" if $@; . " more details";
} }
return ""; return "";
} }
......
...@@ -151,7 +151,7 @@ sub OPTIONAL_MODULES { ...@@ -151,7 +151,7 @@ sub OPTIONAL_MODULES {
}, },
{ {
package => 'Chart', package => 'Chart',
module => 'Chart::Base', module => 'Chart::Lines',
version => '1.0', version => '1.0',
feature => [qw(new_charts old_charts)], feature => [qw(new_charts old_charts)],
}, },
...@@ -179,7 +179,7 @@ sub OPTIONAL_MODULES { ...@@ -179,7 +179,7 @@ sub OPTIONAL_MODULES {
package => 'XML-Twig', package => 'XML-Twig',
module => 'XML::Twig', module => 'XML::Twig',
version => 0, version => 0,
feature => ['moving'], feature => ['moving', 'updates'],
}, },
{ {
package => 'MIME-tools', package => 'MIME-tools',
......
...@@ -38,8 +38,8 @@ use constant JOB_MAP => { ...@@ -38,8 +38,8 @@ use constant JOB_MAP => {
sub new { sub new {
my $class = shift; my $class = shift;
if (!eval { require TheSchwartz; }) { if (!Bugzilla->feature('jobqueue')) {
ThrowCodeError('jobqueue_not_configured'); ThrowCodeError('feature_disabled', { feature => 'jobqueue' });
} }
my $lc = Bugzilla->localconfig; my $lc = Bugzilla->localconfig;
......
...@@ -777,6 +777,8 @@ sub create { ...@@ -777,6 +777,8 @@ sub create {
'feature_enabled' => sub { return Bugzilla->feature(@_); }, 'feature_enabled' => sub { return Bugzilla->feature(@_); },
'install_string' => \&Bugzilla::Install::Util::install_string,
# These don't work as normal constants. # These don't work as normal constants.
DB_MODULE => \&Bugzilla::Constants::DB_MODULE, DB_MODULE => \&Bugzilla::Constants::DB_MODULE,
REQUIRED_MODULES => REQUIRED_MODULES =>
......
...@@ -27,13 +27,9 @@ use constant TIMEOUT => 5; # Number of seconds before timeout. ...@@ -27,13 +27,9 @@ use constant TIMEOUT => 5; # Number of seconds before timeout.
# Look for new releases and notify logged in administrators about them. # Look for new releases and notify logged in administrators about them.
sub get_notifications { sub get_notifications {
return if !Bugzilla->feature('updates');
return if (Bugzilla->params->{'upgrade_notification'} eq 'disabled'); 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; my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE;
# Update the local XML file if this one doesn't exist or if # Update the local XML file if this one doesn't exist or if
# the last modification time (stat[9]) is older than TIME_INTERVAL. # the last modification time (stat[9]) is older than TIME_INTERVAL.
...@@ -128,9 +124,6 @@ sub get_notifications { ...@@ -128,9 +124,6 @@ sub get_notifications {
} }
sub _synchronize_data { sub _synchronize_data {
eval("require LWP::UserAgent");
return {'error' => 'missing_package', 'package' => 'LWP::UserAgent'} if $@;
my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE;
my $ua = LWP::UserAgent->new(); my $ua = LWP::UserAgent->new();
......
...@@ -124,12 +124,7 @@ sub html_light_quote { ...@@ -124,12 +124,7 @@ sub html_light_quote {
dfn samp kbd big small sub sup tt dd dt dl ul li ol dfn samp kbd big small sub sup tt dd dt dl ul li ol
fieldset legend); fieldset legend);
# Are HTML::Scrubber and HTML::Parser installed? if (!Bugzilla->feature('html_desc')) {
eval { require HTML::Scrubber;
require HTML::Parser;
};
if ($@) { # Package(s) not installed.
my $safe = join('|', @allow); my $safe = join('|', @allow);
my $chr = chr(1); my $chr = chr(1);
...@@ -144,7 +139,7 @@ sub html_light_quote { ...@@ -144,7 +139,7 @@ sub html_light_quote {
$text =~ s#$chr($safe)$chr#<$1>#go; $text =~ s#$chr($safe)$chr#<$1>#go;
return $text; return $text;
} }
else { # Packages installed. else {
# We can be less restrictive. We can accept elements with attributes. # We can be less restrictive. We can accept elements with attributes.
push(@allow, qw(a blockquote q span)); push(@allow, qw(a blockquote q span));
......
...@@ -65,6 +65,12 @@ local our $template = Bugzilla->template; ...@@ -65,6 +65,12 @@ local our $template = Bugzilla->template;
local our $vars = {}; local our $vars = {};
my $dbh = Bugzilla->dbh; 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. # Go back to query.cgi if we are adding a boolean chart parameter.
if (grep(/^cmd-/, $cgi->param())) { if (grep(/^cmd-/, $cgi->param())) {
my $params = $cgi->canonicalise_query("format", "ctype", "action"); my $params = $cgi->canonicalise_query("format", "ctype", "action");
...@@ -96,8 +102,6 @@ if ($action eq "search") { ...@@ -96,8 +102,6 @@ if ($action eq "search") {
exit; exit;
} }
my $user = Bugzilla->login(LOGIN_REQUIRED);
$user->in_group(Bugzilla->params->{"chartgroup"}) $user->in_group(Bugzilla->params->{"chartgroup"})
|| ThrowUserError("auth_failure", {group => Bugzilla->params->{"chartgroup"}, || ThrowUserError("auth_failure", {group => Bugzilla->params->{"chartgroup"},
action => "use", action => "use",
......
...@@ -27,10 +27,12 @@ use Bugzilla; ...@@ -27,10 +27,12 @@ use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
# This eval allows runtests to pass even if JSON::RPC isn't if (!Bugzilla->feature('jsonrpc')) {
# installed. ThrowCodeError('feature_disabled', { feature => 'jsonrpc' });
}
# This eval allows runtests.pl to pass.
eval { require Bugzilla::WebService::Server::JSONRPC; }; eval { require Bugzilla::WebService::Server::JSONRPC; };
$@ && ThrowCodeError('json_rpc_not_installed');
Bugzilla->usage_mode(USAGE_MODE_JSON); Bugzilla->usage_mode(USAGE_MODE_JSON);
......
...@@ -95,6 +95,10 @@ if (defined $cgi->param('format') && $cgi->param('format') eq "table") { ...@@ -95,6 +95,10 @@ if (defined $cgi->param('format') && $cgi->param('format') eq "table") {
} }
} }
else { else {
if (!Bugzilla->feature('graphical_reports')) {
ThrowCodeError('feature_disabled', { feature => 'graphical_reports' });
}
if ($row_field && !$col_field) { if ($row_field && !$col_field) {
# 1D *charts* should be displayed horizontally (with an col_field only) # 1D *charts* should be displayed horizontally (with an col_field only)
$col_field = $row_field; $col_field = $row_field;
......
...@@ -45,19 +45,18 @@ use Bugzilla::Util; ...@@ -45,19 +45,18 @@ use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Status; use Bugzilla::Status;
eval "use GD"; # If we're using bug groups for products, we should apply those restrictions
$@ && ThrowCodeError("gd_not_installed"); # to viewing reports, as well. Time to check the login in that case.
eval "use Chart::Lines"; my $user = Bugzilla->login();
$@ && ThrowCodeError("chart_lines_not_installed");
if (!Bugzilla->feature('old_charts')) {
ThrowCodeError('feature_disabled', { feature => 'old_charts' });
}
my $dir = bz_locations()->{'datadir'} . "/mining"; my $dir = bz_locations()->{'datadir'} . "/mining";
my $graph_url = 'graphs'; my $graph_url = 'graphs';
my $graph_dir = bz_locations()->{'libpath'} . '/' .$graph_url; 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(); Bugzilla->switch_to_shadow_db();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
......
...@@ -110,11 +110,6 @@ ...@@ -110,11 +110,6 @@
[% ELSIF error == "chart_file_open_fail" %] [% ELSIF error == "chart_file_open_fail" %]
Unable to open the chart datafile <tt>[% filename FILTER html %]</tt>. 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" %] [% ELSIF error == "column_not_null_without_default" %]
Failed adding the column [% name FILTER html %]: Failed adding the column [% name FILTER html %]:
You cannot add a NOT NULL column with no default to an existing table You cannot add a NOT NULL column with no default to an existing table
...@@ -167,11 +162,6 @@ ...@@ -167,11 +162,6 @@
'[% field.description FILTER html %]' ([% field.name FILTER html %]) '[% field.description FILTER html %]' ([% field.name FILTER html %])
is not a custom field. 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" %] [% ELSIF error == "illegal_content_type_method" %]
Your form submission got corrupted somehow. The <em>content Your form submission got corrupted somehow. The <em>content
method</em> field, which specifies how the content type gets determined, method</em> field, which specifies how the content type gets determined,
...@@ -228,6 +218,15 @@ ...@@ -228,6 +218,15 @@
but you tried to flag it as obsolete while creating a new attachment to but you tried to flag it as obsolete while creating a new attachment to
[% terms.bug %] [%+ my_bug_id FILTER html %]. [% 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" %] [% ELSIF error == "flag_unexpected_object" %]
[% title = "Object Not Recognized" %] [% title = "Object Not Recognized" %]
Flags cannot be set for objects of type [% caller FILTER html %]. Flags cannot be set for objects of type [% caller FILTER html %].
...@@ -280,23 +279,11 @@ ...@@ -280,23 +279,11 @@
Inserting a <code>[% job FILTER html %]</code> job into the Job Inserting a <code>[% job FILTER html %]</code> job into the Job
Queue failed with the following error: [% errmsg FILTER html %] 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" %] [% ELSIF error == "jobqueue_no_job_mapping" %]
<code>Bugzilla::JobQueue</code> has not been configured to handle <code>Bugzilla::JobQueue</code> has not been configured to handle
the job "[% job FILTER html %]". You need to add this job type the job "[% job FILTER html %]". You need to add this job type
to the <code>JOB_MAP</code> constant in <code>Bugzilla::JobQueue</code>. 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" %] [% ELSIF error == "ldap_bind_failed" %]
Failed to bind to the LDAP server. The error message was: Failed to bind to the LDAP server. The error message was:
<code>[% errstr FILTER html %]</code> <code>[% errstr FILTER html %]</code>
...@@ -426,12 +413,6 @@ ...@@ -426,12 +413,6 @@
The value "<code>[% value FILTER html %]</code>" is not in the list of The value "<code>[% value FILTER html %]</code>" is not in the list of
legal values for the <em>[% name FILTER html %]</em> setting. 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" %] [% ELSIF error == "token_generation_error" %]
Something is seriously wrong with the token generation system. Something is seriously wrong with the token generation system.
......
...@@ -97,9 +97,6 @@ YAHOO.util.Event.onDOMReady(onLoadActions); ...@@ -97,9 +97,6 @@ YAHOO.util.Event.onDOMReady(onLoadActions);
<p class="notice">This message is only shown to logged in users with admin privs. <p class="notice">This message is only shown to logged in users with admin privs.
You can configure this notification from the You can configure this notification from the
<a href="editparams.cgi?section=core#upgrade_notification">Parameters</a> page.</p> <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" %] [% ELSIF release.error == "cannot_download" %]
<p>The local XML file '[% release.xml_file FILTER html %]' cannot be created. <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 Please make sure the web server can write in this directory and that you can access
......
...@@ -48,28 +48,34 @@ ...@@ -48,28 +48,34 @@
</strong> - </strong> -
tables of [% terms.bug %] counts in 1, 2 or 3 dimensions, as HTML or CSV. tables of [% terms.bug %] counts in 1, 2 or 3 dimensions, as HTML or CSV.
</li> </li>
<li> [% IF feature_enabled('graphical_reports') %]
<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")) %]
<li> <li>
<strong><a href="chart.cgi">New Charts</a></strong> - <strong>
plot any arbitrary search against time. Far more powerful. <a href="query.cgi?format=report-graph">Graphical reports</a>
</strong> -
line graphs, bar and pie charts.
</li> </li>
[% END %] [% END %]
</ul> </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 %] [% PROCESS global/footer.html.tmpl %]
...@@ -22,11 +22,12 @@ use Bugzilla; ...@@ -22,11 +22,12 @@ use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Constants; 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 # Use an eval here so that runtests.pl accepts this script even if SOAP-Lite
# is not installed. # is not installed.
eval { require Bugzilla::WebService::Server::XMLRPC; }; eval { require Bugzilla::WebService::Server::XMLRPC; };
$@ && ThrowCodeError('soap_not_installed');
Bugzilla->usage_mode(USAGE_MODE_XMLRPC); Bugzilla->usage_mode(USAGE_MODE_XMLRPC);
......
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