From 7f67360617c7978b1c7cc14f2ea8b4f7bb8f7159 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 20 Sep 2018 16:23:10 -0400 Subject: [PATCH] LP#1772680: add global flag to control display of digital search tab 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 LP#1772680: add some guards Avoid crashes if the RBDigital API is not available or incorrect tokens are configured. Signed-off-by: Galen Charlton --- .../perlmods/lib/OpenILS/Application/EbookAPI.pm | 1 + .../lib/OpenILS/Application/EbookAPI/RBDigital.pm | 6 +----- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 10 ++++++++-- .../lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm | 4 ++-- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 21 +++++++++++++++++++++ .../XXXX.data.org-setting.ebook-api-rbdigital.sql | 11 +++++++++++ Open-ILS/src/templates/opac/parts/topnav.tt2 | 4 +++- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm index e80e07959a..061cc0aa04 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm @@ -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); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm index e56a6739d6..50306529ce 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm @@ -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 { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b588e5ec88..e48a8d848b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -164,7 +164,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|; @@ -439,7 +439,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; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm index 9123fe22d5..b11dab6e9a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm @@ -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; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 9ee2cad0b2..1b67fad474 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -20423,3 +20423,24 @@ VALUES ( ) ); +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.catalog.results.count', 'gui', 'integer', + oils_i18n_gettext( + 'eg.catalog.results.count', + '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 + +); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting.ebook-api-rbdigital.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting.ebook-api-rbdigital.sql index 4e525f38ca..8cf46e90b6 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting.ebook-api-rbdigital.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting.ebook-api-rbdigital.sql @@ -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 ( diff --git a/Open-ILS/src/templates/opac/parts/topnav.tt2 b/Open-ILS/src/templates/opac/parts/topnav.tt2 index 5fc4a6fa7f..7dbe73430a 100644 --- a/Open-ILS/src/templates/opac/parts/topnav.tt2 +++ b/Open-ILS/src/templates/opac/parts/topnav.tt2 @@ -104,5 +104,7 @@ [% 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 %] -- 2.11.0