LP#1772680: add global flag to control display of digital search tab
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 20 Sep 2018 20:23:10 +0000 (16:23 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 16 Mar 2020 19:09:43 +0000 (15:09 -0400)
This patch introduces a new global flag, extras.enable_digital_resource_search_tab,
that controls whether the public catalog search tab for digital
resources is displayed. If that flag is not turned on, the tab
is not displayed and unnecessary RBDigital initialization code
is bypassed.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
LP#1772680: add some guards

Avoid crashes if the RBDigital API is not available or incorrect
tokens are configured.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting.ebook-api-rbdigital.sql
Open-ILS/src/templates/opac/parts/topnav.tt2

index e80e079..061cc0a 100644 (file)
@@ -956,6 +956,7 @@ sub get_patron_id {
     
     $logger->error("EbookAPI: User Authenticated. Now, calling for patron authentication");
     my $handler = new_handler($session_id);
+    return unless defined $handler;
     return $handler->do_patron_auth($editor->requestor->usrname, $editor->requestor->email);
 }
 
index e56a673..5030652 100644 (file)
@@ -204,17 +204,13 @@ sub _get_patron_id {
     };
 
     my $res = $self->request($req, $session_id);
-    if ($res && defined($res->{content}->{patronId})) {
-        $self->{patron_id} = $res->{content}->{patronId};
-        return $res->{content}->{patronId};
-    } 
 
     if (defined ($res)) {
         if ($res->{is_success} && defined($res->{content}->{patronId}) ) {
             $self->{patron_id} = $res->{content}->{patronId};
             return $res->{content}->{patronId};
         } else {
-            $logger->error("EbookAPI: Unable to get patron Id from RBDigital portal: ".$res->{content}->{message});
+            $logger->error("EbookAPI: Unable to get patron Id from RBDigital portal: ".$res->{content});
             return 0;
         }
     } else {
index 831cc32..0b6fb61 100644 (file)
@@ -163,7 +163,7 @@ sub load {
     return $self->load_temp_warn_post if $path =~ m|opac/temp_warn/post|;
     return $self->load_temp_warn if $path =~ m|opac/temp_warn|;
 
-    # Load EbookAPI modules 
+    # Load RBDigital EbookAPI modules 
     return $self->load_rbdigital_advanced if $path =~ m|opac/ebook_api/rbdigital/advanced|;
     return $self->load_rbdigital_manage_search_fields if $path =~ m|opac/ebook_api/rbdigital/manage_search_fields|;
     return $self->load_rbdigital_results if $path =~ m|opac/ebook_api/rbdigital/results|;
@@ -434,7 +434,13 @@ sub load_common {
         return $rows;
     };
 
-    $self->load_rbdigital_common();
+
+    $ctx->{digital_resource_search_tab_enabled} = 0;
+    my $flag = $e->retrieve_config_global_flag('extras.enable_digital_resource_search_tab');
+    if ($flag && $U->is_true($flag->enabled)) {
+        $self->load_rbdigital_common();
+        $ctx->{digital_resource_search_tab_enabled} = 1;
+    }
 
     return Apache2::Const::OK;
 }
index 9123fe2..b11dab6 100644 (file)
@@ -403,8 +403,8 @@ sub _get_patron_id {
     my $ebook_api = OpenSRF::AppSession->create('open-ils.ebook_api');
     my $api_request = $ebook_api->request('open-ils.ebook_api.get_patron_id', $authtoken, $session_id,0);
 
-    if ($api_request) {
-        return $api_request->recv->content;
+    if (my $resp = $api_request->recv) {
+        return $resp->content;
     }
     
     return 0;
index 7e66b89..58301b8 100644 (file)
@@ -20418,5 +20418,16 @@ VALUES (
         'Catalog Results Page Size',
         'cwst', 'label'
     )
+
+INSERT INTO config.global_flag (name, label, enabled) VALUES (
+    'extras.enable_digital_resource_search_tab',
+    oils_i18n_gettext(
+        'extras.enable_digital_resource_search_tab',
+        'Extras: Enable public catalog search tab for digital resource searches (e.g., RBDigital)',
+        'cgf',
+        'label'
+    ),
+    FALSE
+
 );
 
index 4e525f3..8cf46e9 100644 (file)
@@ -2,6 +2,17 @@ BEGIN;
 
 -- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
+INSERT INTO config.global_flag (name, label, enabled) VALUES (
+    'extras.enable_digital_resource_search_tab',
+    oils_i18n_gettext(
+        'extras.enable_digital_resource_search_tab',
+        'Extras: Enable public catalog search tab for digital resource searches (e.g., RBDigital)',
+        'cgf',
+        'label'
+    ),
+    FALSE
+);
+
 INSERT INTO config.org_unit_setting_type
     (name, label, description, grp, datatype) 
 VALUES (
index 3a618da..6c1259a 100644 (file)
@@ -96,5 +96,7 @@
 </div>
 </div>
 [% INCLUDE "opac/parts/topnav_links.tt2" %]
-[% INCLUDE "opac/parts/vendor_tabs.tt2" %]
+[% IF ctx.digital_resource_search_tab_enabled;
+      INCLUDE "opac/parts/vendor_tabs.tt2";
+   END %]
 [% END %]