From a2dd3b00284fd4724d3408274cb1156c7a77d187 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 24 Oct 2009 05:21:06 +0000 Subject: Bug 520948: Use Bugzilla->feature and feature_enabled everywhere instead of checking if modules are installed Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Config/Common.pm | 29 +++++++++------- Bugzilla/Install/Requirements.pm | 4 +-- Bugzilla/JobQueue.pm | 4 +-- Bugzilla/Template.pm | 2 ++ Bugzilla/Update.pm | 9 +---- Bugzilla/Util.pm | 9 ++--- chart.cgi | 8 +++-- jsonrpc.cgi | 8 +++-- report.cgi | 4 +++ reports.cgi | 15 ++++----- template/en/default/global/code-error.html.tmpl | 37 +++++---------------- template/en/default/index.html.tmpl | 3 -- template/en/default/reports/menu.html.tmpl | 44 ++++++++++++++----------- xmlrpc.cgi | 5 +-- 14 files changed, 86 insertions(+), 95 deletions(-) mode change 100644 => 100755 jsonrpc.cgi 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 old mode 100644 new mode 100755 index cd41663fa..25fb4c175 --- 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 [% filename FILTER html %]. - [% 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 content method 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 + checksetup.pl 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 [% job FILTER html %] 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 checksetup.pl to see what modules - you are missing. - [% ELSIF error == "jobqueue_no_job_mapping" %] Bugzilla::JobQueue has not been configured to handle the job "[% job FILTER html %]". You need to add this job type to the JOB_MAP constant in Bugzilla::JobQueue. - [% ELSIF error == "json_rpc_not_installed" %] - [% admindocslinks = { 'installation.html#install-perlmodules' - => 'Installing Perl modules' } %] - The JSON-RPC interface will not work without the JSON::RPC - Perl module being installed. Run checksetup.pl for - installation instructions. - [% ELSIF error == "ldap_bind_failed" %] Failed to bind to the LDAP server. The error message was: [% errstr FILTER html %] @@ -426,12 +413,6 @@ The value "[% value FILTER html %]" is not in the list of legal values for the [% name FILTER html %] 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);

This message is only shown to logged in users with admin privs. You can configure this notification from the Parameters page.

- [% ELSIF release.error == "missing_package" %] -

Missing package '[% release.package FILTER html %]'. This package is required to - notify you about new releases.

[% ELSIF release.error == "cannot_download" %]

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 @@ - tables of [% terms.bug %] counts in 1, 2 or 3 dimensions, as HTML or CSV. -

  • - - Graphical reports - - - line graphs, bar and pie charts. -
  • - - -

    Change Over Time

    - - +[% IF feature_enabled('new_charts') OR feature_enabled('old_charts') %] +

    Change Over Time

    + + +[% 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); -- cgit v1.2.3-24-g4f1b