]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 520948: Use Bugzilla->feature and feature_enabled everywhere instead of checking...
authormkanat%bugzilla.org <>
Sat, 24 Oct 2009 05:21:06 +0000 (05:21 +0000)
committermkanat%bugzilla.org <>
Sat, 24 Oct 2009 05:21:06 +0000 (05:21 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit

14 files changed:
Bugzilla/Config/Common.pm
Bugzilla/Install/Requirements.pm
Bugzilla/JobQueue.pm
Bugzilla/Template.pm
Bugzilla/Update.pm
Bugzilla/Util.pm
chart.cgi
jsonrpc.cgi [changed mode: 0644->0755]
report.cgi
reports.cgi
template/en/default/global/code-error.html.tmpl
template/en/default/index.html.tmpl
template/en/default/reports/menu.html.tmpl
xmlrpc.cgi

index b722795d4627fe1d7b55897e43d09181a3f54931..95866b032f048fce3d9d8286cea7dfb113f5b90e 100644 (file)
@@ -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 "";
 }
index 70974a3739516a03f9b8afedbcb9688477c8005c..86b4813d1b51076c3e19fa29eb6b2663cc9982b4 100644 (file)
@@ -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',
index 102f58bc68d247f3e4c664b74584ed703ad3af84..d10df98045cfa47688540e13f020da7ed95adac0 100644 (file)
@@ -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;
index 2e2ac4b08dfcababeb5029d681709a5baf5a9d0d..d5e371f6433aa3e1624f1ba1d983a2455b65208f 100644 (file)
@@ -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 => 
index d3f780570e1ead3390ece8070924094955fdffc4..292ab626e16e0d5aa73c3ad98032080064c10c7b 100644 (file)
@@ -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();
index a36b22c37a75037d8860b2ec8f0b95883313df17..513e0285734e4c72fff353ec09818edeee459a19 100644 (file)
@@ -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));
 
index 1aef2a251453299655a4b61d542688adf3ad6f18..0b46347b5ea5cc576690ac675b23b4806518b995 100755 (executable)
--- 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",
old mode 100644 (file)
new mode 100755 (executable)
index cd41663..25fb4c1
@@ -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);
 
index 2f950948a11993a72501e234aa91c617b048a816..ca92fafc6ea76d8fcc7cd5196685653d66bce5bf 100755 (executable)
@@ -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;
index 6eb4496ccacaba39115ded9b712ca65dffbd1650..b53d9521e004f8f01b9f0f052a1e29c3af541c51 100755 (executable)
@@ -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;
index 8ad0c4ae934c6441389f9e33e18b76d2d92c2ee0..3c9f73f4c47d81475b2b092a056ed0b44f2332b1 100644 (file)
   [% 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
     '[% 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,
     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 %].
     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>
     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.
 
index 6231baa431fa892dbcb776aa56d53891fdf5ce12..dd00d3550a879dc298f322c048302adb22be06c4 100644 (file)
@@ -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
index db5b192939f8fd7de4d631043234ec0fef982fa5..f7613ec01568059377e19f474383af26910284f5 100644 (file)
     </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 %]
index c98dd1b735e45d052be20597e6fd08726e0c0bbf..994e3a48591e6d2e8bf530f940b8097b11eb53f0 100755 (executable)
@@ -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);