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 {
# 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 "";
}
......
......@@ -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',
......
......@@ -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;
......
......@@ -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 =>
......
......@@ -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();
......
......@@ -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));
......
......@@ -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",
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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.
......
......@@ -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
......
......@@ -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 %]
......@@ -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);
......
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